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 <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2018-04-18 08:29:43 -04:00
parent df4a93c9e6
commit 6829f9175d

View File

@ -45,6 +45,16 @@ def _parse_freeze(text):
return result 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): def _freeze(requirements, python):
"""Generate a frozen install from requirements. """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 :param python: A Python binary to use. E.g. /usr/bin/python3
:return: A tuple (python_version, list of (package, version)'s) :return: A tuple (python_version, list of (package, version)'s)
""" """
version_out = subprocess.check_output( version_out = _do_cmd([python, "--version"], return_output=True,
[python, "--version"], stderr=subprocess.STDOUT).decode('utf-8') stderr=subprocess.STDOUT)
version_all = version_out.split()[1] version_all = version_out.split()[1]
version = '.'.join(version_all.split('.')[:2]) version = '.'.join(version_all.split('.')[:2])
with fixtures.TempDir() as temp: with fixtures.TempDir() as temp:
subprocess.check_call( _do_cmd(['virtualenv', '-p', python, temp.path])
['virtualenv', '-p', python, temp.path])
pip_bin = os.path.join(temp.path, 'bin', 'pip') pip_bin = os.path.join(temp.path, 'bin', 'pip')
subprocess.check_call( _do_cmd([pip_bin, 'install', '-U', 'pip', 'setuptools', 'wheel'])
[pip_bin, 'install', '-U', 'pip', 'setuptools', 'wheel']) _do_cmd([pip_bin, 'install', '-r', requirements])
subprocess.check_call( freeze = _do_cmd([pip_bin, 'freeze'], return_output=True)
[pip_bin, 'install', '-r', requirements])
freeze = subprocess.check_output(
[pip_bin, 'freeze']).decode('utf-8')
return (version, _parse_freeze(freeze)) return (version, _parse_freeze(freeze))