[Piuparts-commits] [piuparts] 01/02: use io.open instead of file command, make sure to utf-8 decode
Holger Levsen
holger at moszumanska.debian.org
Mon May 4 16:29:31 UTC 2015
This is an automated email from the git hooks/post-receive script.
holger pushed a commit to branch python3
in repository piuparts.
commit b1e92e1658f273f82d55ce9bc99449308357f7d6
Author: Börni <boerni at gmail.com>
Date: Mon May 4 18:03:03 2015 +0200
use io.open instead of file command, make sure to utf-8 decode
---
piuparts.py | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/piuparts.py b/piuparts.py
index 9143851..8575e41 100644
--- a/piuparts.py
+++ b/piuparts.py
@@ -32,6 +32,7 @@ Lars Wirzenius <liw at iki.fi>
"""
from __future__ import print_function
+from __future__ import unicode_literals
VERSION = "__PIUPARTS_VERSION__"
@@ -52,6 +53,7 @@ import re
import pickle
import subprocess
import uuid
+import io
from signal import alarm, signal, SIGALRM, SIGTERM, SIGKILL
try:
@@ -127,7 +129,7 @@ class DefaultsFactory:
p = subprocess.Popen(["lsb_release", "-i", "-s"],
stdout=subprocess.PIPE)
stdout, stderr = p.communicate()
- return stdout.strip().lower()
+ return stdout.strip().lower().decode('utf-8')
def new_defaults(self):
if not settings.defaults:
@@ -509,17 +511,17 @@ def run(command, ignore_errors=False, timeout=0):
"""Read 64 KB chunks, but depending on the output buffering behavior
of the command we may get less even if more output is coming later.
Abort after reading max_command_output_size bytes."""
- output += p.stdout.read(1 << 16)
+ output += p.stdout.read(1 << 16).decode('utf-8')
if (len(output) > settings.max_command_output_size):
excessive_output = True
ignore_errors = False
alarm(0)
kill_subprocess(p, "excessive output")
output += "\n\n***** Command was terminated after exceeding output limit (%.2f MB) *****\n" \
- % (settings.max_command_output_size / 1024. / 1024.)
+ % (settings.max_command_output_size / 1024. / 1024.).decode('utf-8')
break
if not excessive_output:
- output += p.stdout.read(settings.max_command_output_size)
+ output += p.stdout.read(settings.max_command_output_size).decode('utf-8')
alarm(0)
except Alarm:
ignore_errors = False
@@ -552,7 +554,7 @@ def create_temp_file():
def create_file(name, contents):
"""Create a new file with the desired name and contents."""
try:
- f = file(name, "w")
+ f = io.open(name, "w", encoding='utf-8')
f.write(contents)
f.close()
except IOError as detail:
@@ -929,6 +931,7 @@ class Chroot:
stdout=subprocess.PIPE)
stdout, _ = p.communicate()
if stdout:
+ stdout = stdout.decode('utf-8')
for line in stdout.split("\n"):
m = re.match(pat, line)
if proxy is None and m:
@@ -1427,7 +1430,7 @@ class Chroot:
for basename in os.listdir(vdir):
if basename.endswith(".list"):
pkg = basename[:-len(".list")]
- f = file(os.path.join(vdir, basename), "r")
+ f = io.open(os.path.join(vdir, basename), "r", encoding='utf-8')
for line in f:
pathname = line.strip()
if pathname in vdict:
@@ -1563,7 +1566,7 @@ class Chroot:
if not os.path.exists(os.path.join(vdir, basename)):
continue
- f = file(os.path.join(vdir, basename), "r")
+ f = io.open(os.path.join(vdir, basename), "r", encoding='utf-8')
for line in f:
pathname = line.strip()
if pathname.startswith("/etc/cron."):
@@ -1610,7 +1613,7 @@ class Chroot:
if not os.path.exists(os.path.join(vdir, basename)):
continue
- f = file(os.path.join(vdir, basename), "r")
+ f = io.open(os.path.join(vdir, basename), "r", encoding='utf-8')
for line in f:
pathname = line.strip()
if pathname.startswith("/etc/logrotate.d/"):
@@ -1706,7 +1709,7 @@ class VirtServ(Chroot):
try:
(_, tf) = create_temp_file()
self._command(['copyup', (filename,), (tf,)])
- f = file(tf)
+ f = io.open(tf, encoding='utf-8')
d = f.read()
f.close()
finally:
@@ -1839,7 +1842,7 @@ class VirtServ(Chroot):
path = self._tbpath(path)
try:
(_, tf) = create_temp_file()
- f = file(tf, 'w')
+ f = io.open(tf, 'w', encoding='utf-8')
f.write(tf)
f.close()
self._command(['copydown', (tf,), (path,)])
@@ -1865,7 +1868,7 @@ class VirtServ(Chroot):
tf = self._execute_getoutput(['find', '/', '-xdev', '-printf',
"%y %m %U %G %s %p %l \\n".replace(' ', '\\0')])
try:
- f = file(tf)
+ f = io.open(tf, encoding='utf-8')
while True:
line = ''
@@ -1907,7 +1910,7 @@ class VirtServ(Chroot):
'''])
vdict = {}
try:
- f = file(tf)
+ f = io.open(tf, encoding='utf-8')
for l in f:
(lf, pathname) = l.rstrip('\n').split(':', 1)
assert lf.endswith('.list')
@@ -1932,7 +1935,7 @@ class VirtServ(Chroot):
test "${PIPESTATUS[*]}" = "0 0"
'''])
try:
- f = file(tf)
+ f = io.open(tf, encoding='utf-8')
broken = False
for l in f:
logging.error("FAIL: Broken symlink: " + l)
@@ -2436,7 +2439,7 @@ def install_upgrade_test(chroot, chroot_state, package_files, packages, old_pack
def save_meta_data(filename, chroot_state):
"""Save directory tree meta data into a file for fast access later."""
logging.debug("Saving chroot meta data to %s" % filename)
- f = file(filename, "w")
+ f = io.open(filename, "w", encoding='utf-8')
pickle.dump(chroot_state, f)
f.close()
@@ -2444,7 +2447,7 @@ def save_meta_data(filename, chroot_state):
def load_meta_data(filename):
"""Load meta data saved by 'save_meta_data'."""
logging.debug("Loading chroot meta data from %s" % filename)
- f = file(filename, "r")
+ f = io.open(filename, "r", encoding='utf-8')
chroot_state = pickle.load(f)
f.close()
return chroot_state
@@ -2583,7 +2586,7 @@ def find_default_debian_mirrors():
"""Find the default Debian mirrors."""
mirrors = []
try:
- f = file("/etc/apt/sources.list", "r")
+ f = io.open("/etc/apt/sources.list", "r", encoding='utf-8')
for line in f:
line = re.sub('\[arch=.*\]', '', line)
parts = line.split()
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/piuparts/piuparts.git
More information about the Piuparts-commits
mailing list