feat: add manager, entry and command

This commit is contained in:
2023-03-13 00:06:21 +03:00
parent a8788fbaf9
commit ccdbb00eff
11 changed files with 244 additions and 1 deletions
+39
View File
@@ -0,0 +1,39 @@
__all__ = ("Command",)
import logging
import subprocess
from pathlib import Path
logger = logging.getLogger("command")
class Command:
_logger = logger
def __init__(self, executor: str, *args: str) -> None:
self._executor = executor
self._args = args
def run(self, basepath: Path):
args = [self._executor, *self._args]
self._logger.info(" ".join(args))
result = subprocess.run(
args,
cwd=basepath,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
self._logstd(result.stdout, logging.DEBUG)
if result.returncode != 0:
self._logstd(result.stderr, logging.ERROR)
raise RuntimeError(result.stderr)
else:
self._logstd(result.stderr, logging.WARNING)
@classmethod
def _logstd(cls, data: bytes, level: int):
if data:
for line in data.decode("utf-8").strip().splitlines():
if line:
cls._logger.log(level, line)