initial import

This commit is contained in:
2021-03-02 12:17:01 +03:00
commit 53d21d6496
29 changed files with 888 additions and 0 deletions

20
src/ahriman/core/util.py Normal file
View File

@ -0,0 +1,20 @@
import subprocess
from logging import Logger
from typing import Optional
def check_output(*args: str, exception: Optional[Exception],
cwd = None, stderr: int = subprocess.STDOUT,
logger: Optional[Logger] = None) -> str:
try:
result = subprocess.check_output(args, cwd=cwd, stderr=stderr).decode('utf8').strip()
if logger is not None:
for line in result.splitlines():
logger.debug(line)
except subprocess.CalledProcessError as e:
if e.output is not None and logger is not None:
for line in e.output.decode('utf8').splitlines():
logger.debug(line)
raise exception or e
return result