libretime/analyzer/libretime_analyzer/pipeline/_utils.py

25 lines
649 B
Python
Raw Permalink Normal View History

2023-02-26 01:27:00 +01:00
import logging
2022-09-09 20:21:59 +02:00
from subprocess import CalledProcessError, CompletedProcess, run
2023-02-26 01:27:00 +01:00
logger = logging.getLogger(__name__)
def run_(*args, **kwargs) -> CompletedProcess:
try:
return run(
args,
check=True,
2022-09-09 20:21:59 +02:00
capture_output=True,
text=True,
**kwargs,
)
except OSError as exception: # executable was not found
cmd = args[0]
logger.warning("Failed to run: %s - %s. Is %s installed?", cmd, exception, cmd)
raise exception
except CalledProcessError as exception: # returned an error code
logger.error(exception)
raise exception