mirror of
				https://git.launchpad.net/ubuntu-dev-tools
				synced 2025-10-31 05:54:03 +00:00 
			
		
		
		
	Use the Popen() encoding flag to decode to unicode
This should make behavior identical on Python 2 & 3.
This commit is contained in:
		
							parent
							
								
									43ad610a66
								
							
						
					
					
						commit
						2d3765522e
					
				| @ -620,8 +620,8 @@ def rmadison(url, package, suite=None, arch=None): | |||||||
|     if arch: |     if arch: | ||||||
|         cmd += ['-a', arch] |         cmd += ['-a', arch] | ||||||
|     cmd.append(package) |     cmd.append(package) | ||||||
|     process = subprocess.Popen(cmd, stdout=subprocess.PIPE, |     process = subprocess.Popen( | ||||||
|                                stderr=subprocess.PIPE, close_fds=True) |         cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8') | ||||||
|     output, error_output = process.communicate() |     output, error_output = process.communicate() | ||||||
|     if process.wait() != 0: |     if process.wait() != 0: | ||||||
|         if error_output: |         if error_output: | ||||||
| @ -636,7 +636,7 @@ def rmadison(url, package, suite=None, arch=None): | |||||||
| 
 | 
 | ||||||
|     # pylint bug: http://www.logilab.org/ticket/46273 |     # pylint bug: http://www.logilab.org/ticket/46273 | ||||||
|     # pylint: disable=E1103 |     # pylint: disable=E1103 | ||||||
|     for line in output.decode().strip().splitlines(): |     for line in output.strip().splitlines(): | ||||||
|         # pylint: enable=E1103 |         # pylint: enable=E1103 | ||||||
|         pkg, ver, dist, archs = [x.strip() for x in line.split('|')] |         pkg, ver, dist, archs = [x.strip() for x in line.split('|')] | ||||||
|         comp = 'main' |         comp = 'main' | ||||||
|  | |||||||
| @ -34,7 +34,7 @@ class Builder(object): | |||||||
|     def __init__(self, name): |     def __init__(self, name): | ||||||
|         self.name = name |         self.name = name | ||||||
|         cmd = ["dpkg-architecture", "-qDEB_BUILD_ARCH_CPU"] |         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() |         self.architecture = process.communicate()[0].strip() | ||||||
| 
 | 
 | ||||||
|     def _build_failure(self, returncode, dsc_file): |     def _build_failure(self, returncode, dsc_file): | ||||||
| @ -124,7 +124,8 @@ class Sbuild(Builder): | |||||||
|     def update(self, dist): |     def update(self, dist): | ||||||
|         cmd = ["schroot", "--list"] |         cmd = ["schroot", "--list"] | ||||||
|         Logger.command(cmd) |         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() |         chroots, _ = process.communicate()[0].strip().split() | ||||||
|         if process.returncode != 0: |         if process.returncode != 0: | ||||||
|             return process.returncode |             return process.returncode | ||||||
|  | |||||||
| @ -161,9 +161,10 @@ def mail_bug(srcpkg, subscribe, status, bugtitle, bugtext, bug_mail_domain, | |||||||
|         gpg_command.extend(('-u', keyid)) |         gpg_command.extend(('-u', keyid)) | ||||||
| 
 | 
 | ||||||
|     # sign the mail body |     # sign the mail body | ||||||
|     gpg = subprocess.Popen(gpg_command, stdin=subprocess.PIPE, |     gpg = subprocess.Popen( | ||||||
|                            stdout=subprocess.PIPE) |         gpg_command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, | ||||||
|     signed_report = gpg.communicate(mailbody.encode('utf-8'))[0].decode('utf-8') |         encoding='utf-8') | ||||||
|  |     signed_report = gpg.communicate(mailbody)[0] | ||||||
|     if gpg.returncode != 0: |     if gpg.returncode != 0: | ||||||
|         Logger.error("%s failed.", gpg_command[0]) |         Logger.error("%s failed.", gpg_command[0]) | ||||||
|         sys.exit(1) |         sys.exit(1) | ||||||
|  | |||||||
| @ -71,7 +71,7 @@ class Patch(object): | |||||||
|         patch_f.close() |         patch_f.close() | ||||||
| 
 | 
 | ||||||
|         cmd = ["diffstat", "-l", "-p0", self._full_path] |         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] |         changed_files = process.communicate()[0] | ||||||
|         self._changed_files = [f for f in changed_files.split("\n") if f != ""] |         self._changed_files = [f for f in changed_files.split("\n") if f != ""] | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -327,7 +327,7 @@ class SourcePackage(object): | |||||||
|         if not Logger.verbose: |         if not Logger.verbose: | ||||||
|             cmd.insert(1, "-q") |             cmd.insert(1, "-q") | ||||||
|         Logger.command(cmd + [">", self._debdiff_filename]) |         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] |         debdiff = process.communicate()[0] | ||||||
| 
 | 
 | ||||||
|         # write debdiff file |         # write debdiff file | ||||||
| @ -421,7 +421,7 @@ class SourcePackage(object): | |||||||
|                                         self._package + "_" + |                                         self._package + "_" + | ||||||
|                                         strip_epoch(self._version) + ".lintian") |                                         strip_epoch(self._version) + ".lintian") | ||||||
|         Logger.command(cmd + [">", lintian_filename]) |         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] |         report = process.communicate()[0] | ||||||
| 
 | 
 | ||||||
|         # write lintian report file |         # write lintian report file | ||||||
|  | |||||||
| @ -14,9 +14,9 @@ | |||||||
| 
 | 
 | ||||||
| """test_flake8.py - Run flake8 check""" | """test_flake8.py - Run flake8 check""" | ||||||
| 
 | 
 | ||||||
| import subprocess |  | ||||||
| import sys | import sys | ||||||
| 
 | 
 | ||||||
|  | from ubuntutools import subprocess | ||||||
| from ubuntutools.test import get_source_files, unittest, unittest_verbosity | 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() |         cmd = [sys.executable, "-m", "flake8", "--max-line-length=99"] + get_source_files() | ||||||
|         if unittest_verbosity() >= 2: |         if unittest_verbosity() >= 2: | ||||||
|             sys.stderr.write("Running following command:\n{}\n".format(" ".join(cmd))) |             sys.stderr.write("Running following command:\n{}\n".format(" ".join(cmd))) | ||||||
|         process = subprocess.Popen(cmd, stdout=subprocess.PIPE, |         process = subprocess.Popen( | ||||||
|                                    stderr=subprocess.PIPE, close_fds=True) |             cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, | ||||||
|  |             encoding='utf-8') | ||||||
| 
 | 
 | ||||||
|         out, err = process.communicate() |         out, err = process.communicate() | ||||||
|         if process.returncode != 0:  # pragma: no cover |         if process.returncode != 0:  # pragma: no cover | ||||||
|             msgs = [] |             msgs = [] | ||||||
|             if err: |             if err: | ||||||
|                 msgs.append("flake8 exited with code {} and has unexpected output on stderr:\n{}" |                 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: |             if out: | ||||||
|                 msgs.append("flake8 found issues:\n{}".format(out.decode().rstrip())) |                 msgs.append("flake8 found issues:\n{}".format(out.rstrip())) | ||||||
|             if not msgs: |             if not msgs: | ||||||
|                 msgs.append("flake8 exited with code {} and has no output on stdout or stderr." |                 msgs.append("flake8 exited with code {} and has no output on stdout or stderr." | ||||||
|                             .format(process.returncode)) |                             .format(process.returncode)) | ||||||
|  | |||||||
| @ -46,7 +46,7 @@ class HelpTestCase(unittest.TestCase): | |||||||
|         def tester(self): |         def tester(self): | ||||||
|             null = open('/dev/null', 'r') |             null = open('/dev/null', 'r') | ||||||
|             process = subprocess.Popen(['./' + script, '--help'], |             process = subprocess.Popen(['./' + script, '--help'], | ||||||
|                                        close_fds=True, stdin=null, |                                        encoding='utf-8', stdin=null, | ||||||
|                                        universal_newlines=True, |                                        universal_newlines=True, | ||||||
|                                        stdout=subprocess.PIPE, |                                        stdout=subprocess.PIPE, | ||||||
|                                        stderr=subprocess.PIPE) |                                        stderr=subprocess.PIPE) | ||||||
|  | |||||||
| @ -40,8 +40,9 @@ class PylintTestCase(unittest.TestCase): | |||||||
|                "-E", "--"] + get_source_files() |                "-E", "--"] + get_source_files() | ||||||
|         if unittest_verbosity() >= 2: |         if unittest_verbosity() >= 2: | ||||||
|             sys.stderr.write("Running following command:\n{}\n".format(" ".join(cmd))) |             sys.stderr.write("Running following command:\n{}\n".format(" ".join(cmd))) | ||||||
|         process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, |         process = subprocess.Popen( | ||||||
|                                    close_fds=True) |             cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, | ||||||
|  |             encoding='utf-8') | ||||||
|         out, err = process.communicate() |         out, err = process.communicate() | ||||||
| 
 | 
 | ||||||
|         if process.returncode != 0:  # pragma: no cover |         if process.returncode != 0:  # pragma: no cover | ||||||
| @ -50,11 +51,11 @@ class PylintTestCase(unittest.TestCase): | |||||||
|             # ------------------------------------ |             # ------------------------------------ | ||||||
|             # Your code has been rated at 10.00/10 |             # 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() |                          flags=re.MULTILINE).rstrip() | ||||||
| 
 | 
 | ||||||
|             # Strip logging of used config file (introduced in pylint 1.8) |             # 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 = [] |             msgs = [] | ||||||
|             if err: |             if err: | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user