From 7039d16046c485d94e1c71705a58368d341f0b3e Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Mon, 14 Mar 2016 11:05:06 +0100 Subject: [PATCH] always parse versions as strings, not bytes Fixes a couple errors like: File "./makebuildserver", line 30, in vagrant out += line TypeError: Can't convert 'bytes' object to str implicitly If universal_newlines=False, the default, then Popen will return bytes if the newlines in the data do not match the system's newlines. Setting it to true enables auto-conversion, and then guarantees that the data is always str. "If universal_newlines is True, the file objects stdin, stdout and stderr are opened as text streams in universal newlines mode, as described above in Frequently Used Arguments, otherwise they are opened as binary streams." https://docs.python.org/3/library/subprocess.html#subprocess.Popen --- fdroid | 6 ++++-- fdroidserver/build.py | 1 + makebuildserver | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/fdroid b/fdroid index 045f2aac..53cc00c5 100755 --- a/fdroid +++ b/fdroid @@ -76,9 +76,11 @@ def main(): import subprocess try: output = subprocess.check_output(['git', 'describe'], - stderr=subprocess.STDOUT) + stderr=subprocess.STDOUT, + universal_newlines=True) except subprocess.CalledProcessError: - output = 'git commit ' + subprocess.check_output(['git', 'rev-parse', 'HEAD']) + output = 'git commit ' + subprocess.check_output(['git', 'rev-parse', 'HEAD'], + universal_newlines=True) elif os.path.exists('setup.py'): import re m = re.search(r'''.*[\s,\(]+version\s*=\s*["']([0-9a-z.]+)["'].*''', diff --git a/fdroidserver/build.py b/fdroidserver/build.py index 10f40dc4..3837694b 100644 --- a/fdroidserver/build.py +++ b/fdroidserver/build.py @@ -176,6 +176,7 @@ def get_clean_vm(reset=False): os.mkdir('builder') p = subprocess.Popen(['vagrant', '--version'], + universal_newlines=True, stdout=subprocess.PIPE) vver = p.communicate()[0].strip().split(' ')[1] if vver.split('.')[0] != '1' or int(vver.split('.')[1]) < 4: diff --git a/makebuildserver b/makebuildserver index dc9d1f44..48e0f197 100755 --- a/makebuildserver +++ b/makebuildserver @@ -19,7 +19,8 @@ def vagrant(params, cwd=None, printout=False): is the stdout (and stderr) from vagrant """ p = subprocess.Popen(['vagrant'] + params, cwd=cwd, - stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + universal_newlines=True) out = '' if printout: while True: -- 2.30.2