From: "André Erdmann" <dywi@mailerd.de>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 03/13] autobuild-run, python3: bytes<>str, decode()
Date: Wed, 25 Feb 2015 22:17:20 +0100 [thread overview]
Message-ID: <1424899050-24932-4-git-send-email-dywi@mailerd.de> (raw)
In-Reply-To: <1424899050-24932-1-git-send-email-dywi@mailerd.de>
urlopen.read[lines]() returns bytes in py3 and text in py2.
Decode the bytes if necessary.
Py2k compatibility: no-op decode_bytes(), decode_byte_list() functions
Note: The Py2k variant of the decode_byte_list() function returns the
input list, whereas the python3 variant creates a new list.
Note2: This commit does not add encode() functions, which could be necessary
when writing non-ascii chars to files -- in Python3 only.
Signed-off-by: Andr? Erdmann <dywi@mailerd.de>
---
scripts/autobuild-run | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/scripts/autobuild-run b/scripts/autobuild-run
index be2f482..3a3b8de 100755
--- a/scripts/autobuild-run
+++ b/scripts/autobuild-run
@@ -79,6 +79,19 @@ else:
urlopen = _urllib.urlopen
+if sys.hexversion >= 0x3000000:
+ def decode_bytes(b):
+ return b.decode()
+
+ def decode_byte_list(bl):
+ return [b.decode() for b in bl]
+else:
+ def _identity(e):
+ return e
+
+ decode_bytes = _identity
+ decode_byte_list = _identity
+
MAX_DURATION = 60 * 60 * 4
VERSION = 1
@@ -88,7 +101,7 @@ def log_write(logf, msg):
def check_version():
r = urlopen('http://autobuild.buildroot.org/version')
- version = int(r.readline().strip())
+ version = int(decode_bytes(r.readline()).strip())
if version > VERSION:
print("ERROR: script version too old, please upgrade.")
sys.exit(1)
@@ -143,7 +156,7 @@ def get_toolchain_configs():
"""
r = urlopen('http://autobuild.buildroot.org/toolchains/configs/toolchain-configs.csv')
- l = r.readlines()
+ l = decode_byte_list(r.readlines())
configs = []
for row in csv.reader(l):
config = {}
@@ -158,7 +171,7 @@ def get_toolchain_configs():
continue
config["libc"] = row[2]
r = urlopen(config["url"])
- config["contents"] = r.readlines()
+ config["contents"] = decode_byte_list(r.readlines())
configs.append(config)
return configs
--
2.3.0
next prev parent reply other threads:[~2015-02-25 21:17 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-25 21:17 [Buildroot] [PATCH 00/13] autobuild-run: python3 compat and misc improvements André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 01/13] autobuild-run, python3: print is a function André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 02/13] autobuild-run, python3: urllib.request<>urllib2 André Erdmann
2015-02-25 21:17 ` André Erdmann [this message]
2015-02-25 21:17 ` [Buildroot] [PATCH 04/13] autobuild-run, python3: configparser<>ConfigParser André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 05/13] autobuild-run: remove unneeded vars André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 06/13] autobuild-run: explicitly close web file handles André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 07/13] autobuild-run: get host arch once André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 08/13] autobuild-run: sort imports alphabetically André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 09/13] autobuild-run: unify "which <prog>" code André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 10/13] autobuild-run: use a built-in has_prog() implementation André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 11/13] autobuild-run: move check_requirements() to SystemInfo André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 12/13] autobuild-run: encapsulate subprocess calls André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 13/13] autobuild-run: set locale to en_US or C André Erdmann
2015-02-26 10:08 ` [Buildroot] [PATCH 00/13] autobuild-run: python3 compat and misc improvements Thomas Petazzoni
2015-02-26 19:25 ` Thomas De Schampheleire
2015-03-01 0:09 ` André Erdmann
2015-03-01 21:17 ` Thomas De Schampheleire
2015-03-01 21:37 ` André Erdmann
2015-03-01 21:52 ` Thomas De Schampheleire
2015-03-02 8:36 ` Thomas Petazzoni
2015-03-02 20:00 ` André Erdmann
2015-03-15 13:36 ` Thomas Petazzoni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1424899050-24932-4-git-send-email-dywi@mailerd.de \
--to=dywi@mailerd.de \
--cc=buildroot@busybox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox