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
This commit is contained in:
Ian Wienand 2017-01-17 10:44:43 +11:00
parent 0ceb138d87
commit fb942b752d

View File

@ -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)