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:
parent
0ceb138d87
commit
fb942b752d
@ -14,6 +14,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -23,18 +25,19 @@ import sys
|
|||||||
# run a command, return output
|
# run a command, return output
|
||||||
# if follow is set, output will be echoed to stdout
|
# if follow is set, output will be echoed to stdout
|
||||||
def process_output(cmdline, follow=False):
|
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:
|
if follow:
|
||||||
print("Running command: %s" % cmdline)
|
print("Running command: %s" % cmdline)
|
||||||
out = ""
|
out = ""
|
||||||
with proc.stdout:
|
with proc.stdout:
|
||||||
for line in iter(proc.stdout.readline, b''):
|
for line in iter(proc.stdout.readline, ''):
|
||||||
out += line.decode('utf-8')
|
out += line
|
||||||
print("> %s" % line.strip())
|
print("> %s" % line, end="")
|
||||||
proc.wait()
|
proc.wait()
|
||||||
print("> -- done")
|
print("returncode: %d" % proc.returncode)
|
||||||
else:
|
else:
|
||||||
out = proc.communicate()[0].decode('utf-8')
|
out = proc.communicate()[0]
|
||||||
|
|
||||||
if proc.returncode:
|
if proc.returncode:
|
||||||
e = subprocess.CalledProcessError(proc.returncode, cmdline)
|
e = subprocess.CalledProcessError(proc.returncode, cmdline)
|
||||||
|
Loading…
Reference in New Issue
Block a user