Merge "Trace package install in package-installs-v2"

This commit is contained in:
Jenkins 2016-12-01 01:52:03 +00:00 committed by Gerrit Code Review
commit c867c8cdb5

View File

@ -20,20 +20,28 @@ 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. proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
try: if follow:
return subprocess.check_output(cmdline).decode(encoding='utf-8') print("Running command: %s" % cmdline)
except AttributeError: out = ""
proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE) with proc.stdout:
out = proc.communicate()[0] for line in iter(proc.stdout.readline, b''):
if proc.returncode: out += line.decode('utf-8')
e = subprocess.CalledProcessError(proc.returncode, cmdline) print("> %s" % line.strip())
e.output = out proc.wait()
raise e print("> -- done")
return out else:
out = proc.communicate()[0].decode('utf-8')
if proc.returncode:
e = subprocess.CalledProcessError(proc.returncode, cmdline)
e.output = out
raise e
return out
def main(): def main():
@ -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)