36 lines
772 B
Python
36 lines
772 B
Python
"""System related functions."""
|
|
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
|
|
from autonomic import logger
|
|
|
|
log = logger.get_logger(__name__)
|
|
|
|
|
|
def ensure_installed(package):
|
|
"""Ensure a system dependency is installed"""
|
|
if shutil.which(package) is None:
|
|
msg = "{} is not installed?".format(package)
|
|
exit_with_msg(msg)
|
|
|
|
|
|
def run_command(command):
|
|
"""Run a command."""
|
|
try:
|
|
log.info("Running '{}'".format(" ".join(command)))
|
|
subprocess.check_output(command)
|
|
except subprocess.CalledProcessError as exception:
|
|
msg = "{} failed! Saw {}".format(" ".join(command), str(exception))
|
|
exit_with_msg(msg)
|
|
|
|
|
|
def exit(code=1):
|
|
sys.exit(code)
|
|
|
|
|
|
def exit_with_msg(msg, code=1):
|
|
log.critical(msg)
|
|
exit(code)
|