Use UTF-8 to decode subprocess output on py3

Otherwise, you get output like

    Branch: master
    Source: src/opendev.org/openstack/swift
    Requirements: /home/zuul/src/opendev.org/openstack/requirements
    git log -n 1 --format=%H
    Patch under test: b'f683ca84318da31492f214f978a55bdc1be70c2c'
    git --git-dir /home/zuul/src/opendev.org/openstack/requirements/.git rev-parse HEAD
    requirements git sha: b'9ebc858033d7998a167941f1b7b060de60d17244'
    virtualenv /tmp/tmp9l32_z5b/venv
    /tmp/tmp9l32_z5b/venv/bin/pip install /home/zuul/src/opendev.org/openstack/requirements
    Checking b'f683ca84318da31492f214f978a55bdc1be70c2c'

(Note the bytes getting interpolated in the "Patch under test",
"requirements git sha", and "Checking" lines.)

Change-Id: I836a6218ff5fccf4aab74b37a5a682601a388106
This commit is contained in:
Tim Burke 2019-06-18 20:34:38 -07:00
parent 9ebc858033
commit f094c78968
1 changed files with 7 additions and 1 deletions

View File

@ -33,8 +33,14 @@ check = None
def run_command(cmd):
print(cmd)
cmd_list = shlex.split(str(cmd))
kwargs = {}
if sys.version_info >= (3, ):
kwargs = {
'encoding': 'utf-8',
'errors': 'surrogateescape',
}
p = subprocess.Popen(cmd_list, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stderr=subprocess.PIPE, **kwargs)
(out, err) = p.communicate()
if p.returncode != 0:
raise SystemError(err)