From 58b09694df2be603b5bba8ebd466807d15365fce Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Sat, 11 Apr 2020 23:07:20 +0200 Subject: [PATCH] Allow interactive calls --- autonomic/infra.py | 3 ++- autonomic/utils.py | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/autonomic/infra.py b/autonomic/infra.py index 1fb7629..1aa7474 100644 --- a/autonomic/infra.py +++ b/autonomic/infra.py @@ -30,8 +30,9 @@ def run_play(play, env=None): """Run an Ansible playbook.""" if env is None: env = environ.copy() + cmd = [".venv/bin/ansible-playbook", play] - run(cmd, cwd=INFRA_DIR, env=env) + run(cmd, cwd=INFRA_DIR, interactive=True, env=env) def get_passwd(path): diff --git a/autonomic/utils.py b/autonomic/utils.py index 0588980..c69285d 100644 --- a/autonomic/utils.py +++ b/autonomic/utils.py @@ -8,7 +8,7 @@ things here. """ from os import chdir -from subprocess import check_output +from subprocess import check_output, call from psutil import process_iter @@ -16,7 +16,7 @@ from autonomic.logger import log from autonomic.yaml import yaml -def run(cmd, cwd=None, **kwargs): +def run(cmd, cwd=None, interactive=False, **kwargs): """Run a system command. Please note, all **kwargs will be passed into the check_output command so @@ -27,7 +27,11 @@ def run(cmd, cwd=None, **kwargs): if cwd: chdir(cwd) log.info("Changed directory to {}".format(cwd)) + log.info("Running {}".format(" ".join(cmd))) + + if interactive: + return call(cmd, **kwargs) return check_output(cmd, **kwargs) except Exception as exception: msg = "{} failed! Saw {}".format(" ".join(cmd), str(exception)) @@ -90,6 +94,7 @@ def git_status(fpath): """Check if Git reports changes to be committed.""" cmd = ["git", "status", "--porcelain"] output = run(cmd, cwd=fpath) + if output is not None: msg = "warning: git reports uncommitted changes in {}".format(fpath) log.warning(msg)