Trace package install in package-installs-v2

When running the package install, trace the output so we can see what
packages were installed.

Change-Id: I5442f544ff0ef3ddffdbe6b898d178548d699a41
This commit is contained in:
Ian Wienand 2016-11-23 14:09:44 +11:00
parent f15550f9fe
commit bc6be85424

View File

@ -20,19 +20,27 @@ import subprocess
import sys import sys
def process_output(cmdline): # run a command, return output
# Try to execute subprocess.check_output(), which is available # if follow is set, output will be echoed to stdout
# in Python 2.7+, gracefully falling back to subprocess.Popen def process_output(cmdline, follow=False):
# in older Python versions.
try:
return subprocess.check_output(cmdline).decode(encoding='utf-8')
except AttributeError:
proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE) proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
out = proc.communicate()[0] if follow:
print("Running command: %s" % cmdline)
out = ""
with proc.stdout:
for line in iter(proc.stdout.readline, b''):
out += line.decode('utf-8')
print("> %s" % line.strip())
proc.wait()
print("> -- done")
else:
out = proc.communicate()[0].decode('utf-8')
if proc.returncode: if proc.returncode:
e = subprocess.CalledProcessError(proc.returncode, cmdline) e = subprocess.CalledProcessError(proc.returncode, cmdline)
e.output = out e.output = out
raise e raise e
return out return out
@ -69,8 +77,7 @@ def main():
pkg_map_args = ['pkg-map', '--missing-ok', '--element', element, pkg] pkg_map_args = ['pkg-map', '--missing-ok', '--element', element, pkg]
try: try:
map_output = process_output( map_output = process_output(pkg_map_args)
pkg_map_args)
pkgs.extend(map_output.strip().split('\n')) pkgs.extend(map_output.strip().split('\n'))
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
if e.returncode == 1: if e.returncode == 1:
@ -93,7 +100,7 @@ def main():
print(" ".join(install_args)) print(" ".join(install_args))
else: else:
try: try:
process_output(install_args) process_output(install_args, follow=True)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
print("install failed with error %s" % e.output) print("install failed with error %s" % e.output)
sys.exit(1) sys.exit(1)