From 7c0efe2914c10f121cab39bf9e1fa321cce0d011 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Wed, 4 Sep 2019 16:09:16 -0300 Subject: [PATCH] Port requestbackport to Python 3 --- requestbackport | 14 +++++++------- setup.py | 2 +- ubuntutools/question.py | 14 ++++++++------ 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/requestbackport b/requestbackport index 903bce6..ae9585c 100755 --- a/requestbackport +++ b/requestbackport @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # # Copyright (C) 2011, Stefano Rivera # @@ -123,7 +123,7 @@ def find_rdepends(releases, published_binaries): except RDependsException: # Not published? TODO: Check continue - for relationship, rdeps in raw_rdeps.iteritems(): + for relationship, rdeps in raw_rdeps.items(): for rdep in rdeps: # Ignore circular deps: if rdep['Package'] in published_binaries: @@ -134,14 +134,14 @@ def find_rdepends(releases, published_binaries): intermediate[binpkg][rdep['Package']].append((release, relationship)) output = [] - for binpkg, rdeps in intermediate.iteritems(): + for binpkg, rdeps in intermediate.items(): output += ['', binpkg, '-' * len(binpkg)] - for pkg, appearences in rdeps.iteritems(): + for pkg, appearences in rdeps.items(): output += ['* %s' % pkg] for release, relationship in appearences: output += [' [ ] %s (%s)' % (release, relationship)] - found_any = sum(len(rdeps) for rdeps in intermediate.itervalues()) + found_any = sum(len(rdeps) for rdeps in intermediate.values()) if found_any: output = [ "Reverse dependencies:", @@ -168,7 +168,7 @@ def locate_package(package, distribution): try: package_spph = archive.getSourcePackage(package, distribution) return package_spph - except PackageNotFoundException, e: + except PackageNotFoundException as e: if pass_ == 'binary': Logger.error(str(e)) sys.exit(1) @@ -292,7 +292,7 @@ def main(): try: destinations = determine_destinations(options.source, options.destination) - except DestinationException, e: + except DestinationException as e: Logger.error(str(e)) sys.exit(1) diff --git a/setup.py b/setup.py index c8c0346..e829a15 100755 --- a/setup.py +++ b/setup.py @@ -33,6 +33,7 @@ if sys.version_info[0] >= 3: 'pull-lp-source', 'pull-revu-source', 'pull-uca-source', + 'requestbackport', 'reverse-build-depends', 'setup-packaging-environment', ] @@ -46,7 +47,6 @@ else: scripts = [ 'import-bug-from-debian', 'merge-changelog', - 'requestbackport', 'requestsync', 'reverse-depends', 'seeded-in-ubuntu', diff --git a/ubuntutools/question.py b/ubuntutools/question.py index 9adbeff..2869748 100644 --- a/ubuntutools/question.py +++ b/ubuntutools/question.py @@ -18,6 +18,7 @@ from __future__ import print_function +import codecs import tempfile import os import re @@ -27,6 +28,7 @@ import ubuntutools.subprocess if sys.version_info[0] < 3: input = raw_input # noqa, pylint: disable=undefined-variable + open = codecs.open class Question(object): @@ -133,7 +135,7 @@ class EditFile(object): def edit(self, optional=False): if optional: print("\n\nCurrently the %s looks like:" % self.description) - with open(self.filename, 'r') as f: + with open(self.filename, 'r', encoding='utf-8') as f: print(f.read()) if YesNoQuestion().ask("Edit", "no") == "no": return @@ -146,7 +148,7 @@ class EditFile(object): modified = old_mtime != os.stat(self.filename).st_mtime placeholders_present = False if self.placeholders: - with open(self.filename, 'r') as f: + with open(self.filename, 'r', encoding='utf-8') as f: for line in f: for placeholder in self.placeholders: if placeholder.search(line.strip()): @@ -188,8 +190,8 @@ class EditBugReport(EditFile): placeholders) def check_edit(self): - with open(self.filename, 'r') as f: - report = f.read().decode('utf-8') + with open(self.filename, 'r', encoding='utf-8') as f: + report = f.read() if self.split_re.match(report) is None: print("The %s doesn't start with 'Summary:' and 'Description:' " @@ -199,8 +201,8 @@ class EditBugReport(EditFile): return True def get_report(self): - with open(self.filename, 'r') as f: - report = f.read().decode('utf-8') + with open(self.filename, 'r', encoding='utf-8') as f: + report = f.read() match = self.split_re.match(report) title = match.group(1).replace(u'\n', u' ')