From 6829f9175d1837d539fa7dd5bc0f60d431544c4f Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Wed, 18 Apr 2018 08:29:43 -0400 Subject: [PATCH] show commands and output together Print the command being run before running it so we can see the command and output together in the logs. Change-Id: I513521694c6efa20c284a13e6a1a7e7cf85c1892 Signed-off-by: Doug Hellmann --- openstack_requirements/cmds/generate.py | 26 +++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/openstack_requirements/cmds/generate.py b/openstack_requirements/cmds/generate.py index 183a8061ca..6609bb14c5 100644 --- a/openstack_requirements/cmds/generate.py +++ b/openstack_requirements/cmds/generate.py @@ -45,6 +45,16 @@ def _parse_freeze(text): return result +def _do_cmd(cmd, return_output=False, **kwds): + print(' '.join(cmd)) + if return_output: + out = subprocess.check_output(cmd, **kwds).decode('utf-8') + print(out) + return out + else: + subprocess.check_call(cmd) + + def _freeze(requirements, python): """Generate a frozen install from requirements. @@ -67,20 +77,16 @@ def _freeze(requirements, python): :param python: A Python binary to use. E.g. /usr/bin/python3 :return: A tuple (python_version, list of (package, version)'s) """ - version_out = subprocess.check_output( - [python, "--version"], stderr=subprocess.STDOUT).decode('utf-8') + version_out = _do_cmd([python, "--version"], return_output=True, + stderr=subprocess.STDOUT) version_all = version_out.split()[1] version = '.'.join(version_all.split('.')[:2]) with fixtures.TempDir() as temp: - subprocess.check_call( - ['virtualenv', '-p', python, temp.path]) + _do_cmd(['virtualenv', '-p', python, temp.path]) pip_bin = os.path.join(temp.path, 'bin', 'pip') - subprocess.check_call( - [pip_bin, 'install', '-U', 'pip', 'setuptools', 'wheel']) - subprocess.check_call( - [pip_bin, 'install', '-r', requirements]) - freeze = subprocess.check_output( - [pip_bin, 'freeze']).decode('utf-8') + _do_cmd([pip_bin, 'install', '-U', 'pip', 'setuptools', 'wheel']) + _do_cmd([pip_bin, 'install', '-r', requirements]) + freeze = _do_cmd([pip_bin, 'freeze'], return_output=True) return (version, _parse_freeze(freeze))