API: Added /api/flake/create. Fixed vscode search settings. Moved clan create to clan flake create

This commit is contained in:
Qubasa
2023-10-09 14:01:34 +02:00
parent 9c74c4d661
commit b49433958b
14 changed files with 157 additions and 52 deletions

View File

@@ -1,18 +1,29 @@
import asyncio
import logging
import shlex
from pathlib import Path
from typing import Optional, Tuple
from .errors import ClanError
log = logging.getLogger(__name__)
async def run(cmd: list[str]) -> bytes:
async def run(cmd: list[str], cwd: Optional[Path] = None) -> Tuple[bytes, bytes]:
log.debug(f"$: {shlex.join(cmd)}")
cwd_res = None
if cwd is not None:
if not cwd.exists():
raise ClanError(f"Working directory {cwd} does not exist")
if not cwd.is_dir():
raise ClanError(f"Working directory {cwd} is not a directory")
cwd_res = cwd.resolve()
log.debug(f"Working directory: {cwd_res}")
proc = await asyncio.create_subprocess_exec(
*cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
cwd=cwd_res,
)
stdout, stderr = await proc.communicate()
@@ -25,4 +36,4 @@ command output:
{stderr.decode("utf-8")}
"""
)
return stdout
return stdout, stderr