From fb942b752dd0db9be71d39595b3e25c9cd1bc84c Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Tue, 17 Jan 2017 10:44:43 +1100 Subject: [PATCH] Use strings in package-installs follow output I noticed in debugging that with python3 all the pkg-installs output is preceeded by a b'foo', which suggests coding issues lurking. The universal_newlines argument makes subprocess readline() returns a decoded str (via locale) instead of a byte-string. This clears up a couple of points where we explicitly decode and cleans up the print output. Minor formatting cleanup of command and exit display. Don't strip the leading spaces so indents retain in the output Change-Id: I2894f10a0c2fc618563641b9d106b716f4a544aa --- elements/package-installs/bin/package-installs-v2 | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/elements/package-installs/bin/package-installs-v2 b/elements/package-installs/bin/package-installs-v2 index 305e2a66..e475bc24 100755 --- a/elements/package-installs/bin/package-installs-v2 +++ b/elements/package-installs/bin/package-installs-v2 @@ -14,6 +14,8 @@ # License for the specific language governing permissions and limitations # under the License. +from __future__ import print_function + import argparse import json import subprocess @@ -23,18 +25,19 @@ import sys # run a command, return output # if follow is set, output will be echoed to stdout def process_output(cmdline, follow=False): - proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE) + proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE, + universal_newlines=True) 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()) + for line in iter(proc.stdout.readline, ''): + out += line + print("> %s" % line, end="") proc.wait() - print("> -- done") + print("returncode: %d" % proc.returncode) else: - out = proc.communicate()[0].decode('utf-8') + out = proc.communicate()[0] if proc.returncode: e = subprocess.CalledProcessError(proc.returncode, cmdline)