diff --git a/ubuntutools/archive.py b/ubuntutools/archive.py index 9237bca..b3a6eb8 100644 --- a/ubuntutools/archive.py +++ b/ubuntutools/archive.py @@ -620,8 +620,8 @@ def rmadison(url, package, suite=None, arch=None): if arch: cmd += ['-a', arch] cmd.append(package) - process = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, close_fds=True) + process = subprocess.Popen( + cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8') output, error_output = process.communicate() if process.wait() != 0: if error_output: @@ -636,7 +636,7 @@ def rmadison(url, package, suite=None, arch=None): # pylint bug: http://www.logilab.org/ticket/46273 # pylint: disable=E1103 - for line in output.decode().strip().splitlines(): + for line in output.strip().splitlines(): # pylint: enable=E1103 pkg, ver, dist, archs = [x.strip() for x in line.split('|')] comp = 'main' diff --git a/ubuntutools/builder.py b/ubuntutools/builder.py index a9f8e58..fe6c686 100644 --- a/ubuntutools/builder.py +++ b/ubuntutools/builder.py @@ -34,7 +34,7 @@ class Builder(object): def __init__(self, name): self.name = name cmd = ["dpkg-architecture", "-qDEB_BUILD_ARCH_CPU"] - process = subprocess.Popen(cmd, stdout=subprocess.PIPE) + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, encoding='utf-8') self.architecture = process.communicate()[0].strip() def _build_failure(self, returncode, dsc_file): @@ -124,7 +124,8 @@ class Sbuild(Builder): def update(self, dist): cmd = ["schroot", "--list"] Logger.command(cmd) - process = subprocess.Popen(cmd, stdout=subprocess.PIPE) + process = subprocess.Popen( + cmd, stdout=subprocess.PIPE, encoding='utf-8') chroots, _ = process.communicate()[0].strip().split() if process.returncode != 0: return process.returncode diff --git a/ubuntutools/requestsync/mail.py b/ubuntutools/requestsync/mail.py index 9170195..b94792d 100644 --- a/ubuntutools/requestsync/mail.py +++ b/ubuntutools/requestsync/mail.py @@ -161,9 +161,10 @@ def mail_bug(srcpkg, subscribe, status, bugtitle, bugtext, bug_mail_domain, gpg_command.extend(('-u', keyid)) # sign the mail body - gpg = subprocess.Popen(gpg_command, stdin=subprocess.PIPE, - stdout=subprocess.PIPE) - signed_report = gpg.communicate(mailbody.encode('utf-8'))[0].decode('utf-8') + gpg = subprocess.Popen( + gpg_command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, + encoding='utf-8') + signed_report = gpg.communicate(mailbody)[0] if gpg.returncode != 0: Logger.error("%s failed.", gpg_command[0]) sys.exit(1) diff --git a/ubuntutools/sponsor_patch/patch.py b/ubuntutools/sponsor_patch/patch.py index cd99672..1a696ef 100644 --- a/ubuntutools/sponsor_patch/patch.py +++ b/ubuntutools/sponsor_patch/patch.py @@ -71,7 +71,7 @@ class Patch(object): patch_f.close() cmd = ["diffstat", "-l", "-p0", self._full_path] - process = subprocess.Popen(cmd, stdout=subprocess.PIPE) + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, encoding='utf-8') changed_files = process.communicate()[0] self._changed_files = [f for f in changed_files.split("\n") if f != ""] diff --git a/ubuntutools/sponsor_patch/source_package.py b/ubuntutools/sponsor_patch/source_package.py index 8adecd3..1b915cc 100644 --- a/ubuntutools/sponsor_patch/source_package.py +++ b/ubuntutools/sponsor_patch/source_package.py @@ -327,7 +327,7 @@ class SourcePackage(object): if not Logger.verbose: cmd.insert(1, "-q") Logger.command(cmd + [">", self._debdiff_filename]) - process = subprocess.Popen(cmd, stdout=subprocess.PIPE) + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, encoding='utf-8') debdiff = process.communicate()[0] # write debdiff file @@ -421,7 +421,7 @@ class SourcePackage(object): self._package + "_" + strip_epoch(self._version) + ".lintian") Logger.command(cmd + [">", lintian_filename]) - process = subprocess.Popen(cmd, stdout=subprocess.PIPE) + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, encoding='utf-8') report = process.communicate()[0] # write lintian report file diff --git a/ubuntutools/test/test_flake8.py b/ubuntutools/test/test_flake8.py index b604bc2..660b9bc 100644 --- a/ubuntutools/test/test_flake8.py +++ b/ubuntutools/test/test_flake8.py @@ -14,9 +14,9 @@ """test_flake8.py - Run flake8 check""" -import subprocess import sys +from ubuntutools import subprocess from ubuntutools.test import get_source_files, unittest, unittest_verbosity @@ -33,17 +33,18 @@ class Flake8TestCase(unittest.TestCase): cmd = [sys.executable, "-m", "flake8", "--max-line-length=99"] + get_source_files() if unittest_verbosity() >= 2: sys.stderr.write("Running following command:\n{}\n".format(" ".join(cmd))) - process = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, close_fds=True) + process = subprocess.Popen( + cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + encoding='utf-8') out, err = process.communicate() if process.returncode != 0: # pragma: no cover msgs = [] if err: msgs.append("flake8 exited with code {} and has unexpected output on stderr:\n{}" - .format(process.returncode, err.decode().rstrip())) + .format(process.returncode, err.rstrip())) if out: - msgs.append("flake8 found issues:\n{}".format(out.decode().rstrip())) + msgs.append("flake8 found issues:\n{}".format(out.rstrip())) if not msgs: msgs.append("flake8 exited with code {} and has no output on stdout or stderr." .format(process.returncode)) diff --git a/ubuntutools/test/test_help.py b/ubuntutools/test/test_help.py index 83c639a..ffe85a9 100644 --- a/ubuntutools/test/test_help.py +++ b/ubuntutools/test/test_help.py @@ -46,7 +46,7 @@ class HelpTestCase(unittest.TestCase): def tester(self): null = open('/dev/null', 'r') process = subprocess.Popen(['./' + script, '--help'], - close_fds=True, stdin=null, + encoding='utf-8', stdin=null, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) diff --git a/ubuntutools/test/test_pylint.py b/ubuntutools/test/test_pylint.py index 4bc3d53..147b150 100644 --- a/ubuntutools/test/test_pylint.py +++ b/ubuntutools/test/test_pylint.py @@ -40,8 +40,9 @@ class PylintTestCase(unittest.TestCase): "-E", "--"] + get_source_files() if unittest_verbosity() >= 2: sys.stderr.write("Running following command:\n{}\n".format(" ".join(cmd))) - process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - close_fds=True) + process = subprocess.Popen( + cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + encoding='utf-8') out, err = process.communicate() if process.returncode != 0: # pragma: no cover @@ -50,11 +51,11 @@ class PylintTestCase(unittest.TestCase): # ------------------------------------ # Your code has been rated at 10.00/10 # - out = re.sub("^(-+|Your code has been rated at .*)$", "", out.decode(), + out = re.sub("^(-+|Your code has been rated at .*)$", "", out, flags=re.MULTILINE).rstrip() # Strip logging of used config file (introduced in pylint 1.8) - err = re.sub("^Using config file .*\n", "", err.decode()).rstrip() + err = re.sub("^Using config file .*\n", "", err).rstrip() msgs = [] if err: