[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 5/6] docker: Make _get_so_libs() work on Python 3
From: |
Eduardo Habkost |
Subject: |
[Qemu-devel] [PATCH 5/6] docker: Make _get_so_libs() work on Python 3 |
Date: |
Tue, 26 Jun 2018 23:14:22 -0300 |
The "ldd" output is a byte sequence, not a string. Use bytes
literals while handling the output, and use os.fsdecode() on the
resulting file paths before returning.
Signed-off-by: Eduardo Habkost <address@hidden>
---
tests/docker/docker.py | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/tests/docker/docker.py b/tests/docker/docker.py
index bc34bd872b..f58af8e894 100755
--- a/tests/docker/docker.py
+++ b/tests/docker/docker.py
@@ -41,6 +41,15 @@ FILTERED_ENV_NAMES = ['ftp_proxy', 'http_proxy',
'https_proxy']
DEVNULL = open(os.devnull, 'wb')
+def _fsdecode(name):
+ # type: (bytes) -> str
+ """Decode filename to str, try to use os.fsdecode() if available"""
+ if hasattr(os, 'fsdecode'):
+ # Python 3
+ return os.fsdecode(name) # type: ignore
+ else:
+ # Python 2.7
+ return name # type: ignore
def _text_checksum(text):
# type: (bytes) -> str
@@ -90,15 +99,15 @@ def _get_so_libs(executable):
ensure theright data is copied."""
libs = []
- ldd_re = re.compile(r"(/.*/)(\S*)")
+ ldd_re = re.compile(b"(/.*/)(\S*)")
try:
ldd_output = subprocess.check_output(["ldd", executable])
- for line in ldd_output.split("\n"):
+ for line in ldd_output.split(b"\n"):
search = ldd_re.search(line)
if search and len(search.groups()) == 2:
so_path = search.groups()[0]
so_lib = search.groups()[1]
- libs.append("%s/%s" % (so_path, so_lib))
+ libs.append(_fsdecode(b"%s/%s" % (so_path, so_lib)))
except subprocess.CalledProcessError:
print("%s had no associated libraries (static build?)" % (executable))
--
2.18.0.rc1.1.g3f1ff2140
- [Qemu-devel] [PATCH 0/6] docker: Port to Python 3, Eduardo Habkost, 2018/06/26
- [Qemu-devel] [PATCH 1/6] docker: Use BytesIO instead of StringIO, Eduardo Habkost, 2018/06/26
- [Qemu-devel] [PATCH 2/6] docker: Always return int on run(), Eduardo Habkost, 2018/06/26
- [Qemu-devel] [PATCH 3/6] docker: Add type annotations, Eduardo Habkost, 2018/06/26
- [Qemu-devel] [PATCH 4/6] docker: Use os.environ.items() instead of .iteritems(), Eduardo Habkost, 2018/06/26
- [Qemu-devel] [PATCH 5/6] docker: Make _get_so_libs() work on Python 3,
Eduardo Habkost <=
- [Qemu-devel] [PATCH 6/6] docker: Open dockerfiles in text mode, Eduardo Habkost, 2018/06/26