From c6ef183975045609e361b854edd5dcf8e1c8da37 Mon Sep 17 00:00:00 2001 From: Matthew Thode Date: Thu, 28 Jan 2016 16:07:01 -0600 Subject: [PATCH] Fix package-installs for python3 subprocess.check_call() returns a byte-string which needs to be turned into a unicode string for python3 compatability. Also some minor refactoring while we're here. Closes-Bug: 1536462 Change-Id: Icd957bc4d93ccad94b1246ad62e6e02ee14d9ca5 --- elements/package-installs/bin/package-installs-v2 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/elements/package-installs/bin/package-installs-v2 b/elements/package-installs/bin/package-installs-v2 index 855d3aedd..f1814dd74 100755 --- a/elements/package-installs/bin/package-installs-v2 +++ b/elements/package-installs/bin/package-installs-v2 @@ -25,7 +25,7 @@ def process_output(cmdline): # in Python 2.7+, gracefully falling back to subprocess.Popen # in older Python versions. try: - return subprocess.check_output(cmdline) + return subprocess.check_output(cmdline).decode(encoding='utf-8') except AttributeError: proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE) out = proc.communicate()[0] @@ -66,12 +66,12 @@ def main(): for (pkg, element) in install_packages: print("%sing %s from %s" % (install, pkg, element)) - pkg_map_args = ["pkg-map", "--missing-ok", "--element", element] - pkg_map_args.append(pkg) + pkg_map_args = ['pkg-map', '--missing-ok', '--element', element, pkg] try: map_output = process_output( pkg_map_args) + pkgs.extend(map_output.strip().split('\n')) except subprocess.CalledProcessError as e: if e.returncode == 1: if args.noop: @@ -83,7 +83,6 @@ def main(): elif e.returncode == 2: pkgs.append(pkg) continue - pkgs.extend(map_output.strip().split('\n')) install_args = ["install-packages"] if args.uninstall: