summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-04-12 16:00:15 +0300
committerLars Wirzenius <liw@liw.fi>2020-04-12 17:15:26 +0300
commit5e9f6341eaeae7a58ca96e8e4055be8aaa718622 (patch)
tree42cfbfcceeb2da1a047d6687f52865c7af2c73be
parent5ec8a0e5cadd31473c8f44dd703ccf25d73845f9 (diff)
downloadvmdb2-5e9f6341eaeae7a58ca96e8e4055be8aaa718622.tar.gz
Change: use subprocess directly, not via cliapp.runcmd
We didn't use the cliapp.runcmd funcationality at all, except for the stdout/stderr callbacks, and those only to log the output as it happens. The logs don't seem all that useful, especially in real time. We add back the logging of command output if it turns out there's a need for that.
-rw-r--r--vmdb/runcmd.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/vmdb/runcmd.py b/vmdb/runcmd.py
index fb0d8b3..ae4a6d0 100644
--- a/vmdb/runcmd.py
+++ b/vmdb/runcmd.py
@@ -43,14 +43,20 @@ def progress(msg):
sys.stdout.write('{}\n'.format(msg))
-def runcmd(argv, *argvs, **kwargs):
+def runcmd(argv, **kwargs):
progress('Exec: %r' % (argv,))
- kwargs['stdout_callback'] = _log_stdout
- kwargs['stderr_callback'] = _log_stderr
env = kwargs.get('env', os.environ.copy())
env['LC_ALL'] = 'C'
kwargs['env'] = env
- return cliapp.runcmd(argv, *argvs, **kwargs)
+ kwargs['stdout'] = kwargs.get('stdout', subprocess.PIPE)
+ kwargs['stderr'] = kwargs.get('stderr', subprocess.PIPE)
+ p = subprocess.Popen(argv, **kwargs)
+ out, err = p.communicate()
+ logging.debug('STDOUT: %s', out.decode('UTF8'))
+ logging.debug('STDERR: %s', err.decode('UTF8'))
+ if p.returncode != 0:
+ raise cliapp.AppException('Command failed: {}'.format(p.returncode))
+ return out
def runcmd_chroot(chroot, argv, *argvs, **kwargs):