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