chiark / gitweb /
always parse versions as strings, not bytes
authorHans-Christoph Steiner <hans@eds.org>
Mon, 14 Mar 2016 10:05:06 +0000 (11:05 +0100)
committerHans-Christoph Steiner <hans@eds.org>
Mon, 14 Mar 2016 11:49:38 +0000 (12:49 +0100)
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
fdroidserver/build.py
makebuildserver

diff --git a/fdroid b/fdroid
index 045f2aacf8e5f133c61fff43c126d7bcb1add75b..53cc00c5dcc5eff9a1bf1e65fdf261300a28141b 100755 (executable)
--- 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.]+)["'].*''',
index 10f40dc478da8dc214373adc271ac01ab4b67b9a..3837694bd8450a8acaa3f3bd6215d4c2d9515db7 100644 (file)
@@ -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:
index dc9d1f44ae022af28dd317772a75f26f1a667f5a..48e0f197ec100d8adc2cd81cc74e2ae90b0443b0 100755 (executable)
@@ -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: