Port submittodebian to Python 3

This commit is contained in:
Stefano Rivera 2019-09-04 17:01:16 -03:00
parent 76609fde49
commit 3f5e56c75e
2 changed files with 16 additions and 15 deletions

View File

@ -40,6 +40,7 @@ if sys.version_info[0] >= 3:
'seeded-in-ubuntu', 'seeded-in-ubuntu',
'setup-packaging-environment', 'setup-packaging-environment',
'sponsor-patch', 'sponsor-patch',
'submittodebian',
] ]
data_files = [ data_files = [
('share/bash-completion/completions', glob.glob("bash_completion/*")), ('share/bash-completion/completions', glob.glob("bash_completion/*")),
@ -51,7 +52,6 @@ else:
scripts = [ scripts = [
'import-bug-from-debian', 'import-bug-from-debian',
'merge-changelog', 'merge-changelog',
'submittodebian',
'syncpackage', 'syncpackage',
'ubuntu-build', 'ubuntu-build',
'ubuntu-iso', 'ubuntu-iso',

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# submittodebian - tool to submit patches to Debian's BTS # submittodebian - tool to submit patches to Debian's BTS
@ -39,8 +39,8 @@ from ubuntutools.update_maintainer import update_maintainer, restore_maintainer
try: try:
from debian.changelog import Changelog from debian.changelog import Changelog
except ImportError: except ImportError:
print(u"This utility requires modules from the «python-debian» package, " print("This utility requires modules from the «python3-debian» package, "
u"which isn't currently installed.") "which isn't currently installed.")
sys.exit(1) sys.exit(1)
@ -94,7 +94,7 @@ def gen_debdiff(tmpdir, changelog):
devnull = open('/dev/null', 'w') devnull = open('/dev/null', 'w')
diff_cmd = ['bzr', 'diff', '-r', 'tag:' + str(oldver)] diff_cmd = ['bzr', 'diff', '-r', 'tag:' + str(oldver)]
if call(diff_cmd, stdout=devnull, stderr=devnull) == 1: if call(diff_cmd, stdout=devnull, stderr=devnull) == 1:
print "Extracting bzr diff between %s and %s" % (oldver, newver) print("Extracting bzr diff between %s and %s" % (oldver, newver))
else: else:
if oldver.epoch is not None: if oldver.epoch is not None:
oldver = str(oldver)[str(oldver).index(":") + 1:] oldver = str(oldver)[str(oldver).index(":") + 1:]
@ -107,7 +107,7 @@ def gen_debdiff(tmpdir, changelog):
check_file(olddsc) check_file(olddsc)
check_file(newdsc) check_file(newdsc)
print "Generating debdiff between %s and %s" % (oldver, newver) print("Generating debdiff between %s and %s" % (oldver, newver))
diff_cmd = ['debdiff', olddsc, newdsc] diff_cmd = ['debdiff', olddsc, newdsc]
diff = Popen(diff_cmd, stdout=PIPE) diff = Popen(diff_cmd, stdout=PIPE)
@ -128,15 +128,15 @@ def check_file(fname, critical=True):
else: else:
if not critical: if not critical:
return False return False
print u"Couldn't find «%s».\n" % fname print("Couldn't find «%s».\n" % fname)
sys.exit(1) sys.exit(1)
def submit_bugreport(body, debdiff, deb_version, changelog): def submit_bugreport(body, debdiff, deb_version, changelog):
try: try:
devel = UbuntuDistroInfo().devel() devel = UbuntuDistroInfo().devel()
except DistroDataOutdated, e: except DistroDataOutdated as e:
print str(e) print(str(e))
devel = '' devel = ''
if os.path.dirname(sys.argv[0]).startswith('/usr/bin'): if os.path.dirname(sys.argv[0]).startswith('/usr/bin'):
@ -203,10 +203,10 @@ no-cc
#smtptls #smtptls
""" % email """ % email
with file(fn, 'w') as f: with open(fn, 'w') as f:
f.write(reportbugrc) f.write(reportbugrc)
print """\ print("""\
You have not configured reportbug. Assuming this is the first time you have You have not configured reportbug. Assuming this is the first time you have
used it. Writing a ~/.reportbugrc that will use Debian's mail server, and CC used it. Writing a ~/.reportbugrc that will use Debian's mail server, and CC
the bug to you at <%s> the bug to you at <%s>
@ -217,7 +217,7 @@ the bug to you at <%s>
If this is not correct, please exit now and edit ~/.reportbugrc or run If this is not correct, please exit now and edit ~/.reportbugrc or run
reportbug --configure for its configuration wizard. reportbug --configure for its configuration wizard.
""" % (email, reportbugrc.strip()) """ % (email, reportbugrc.strip()))
if YesNoQuestion().ask("Continue submitting this bug", "yes") == "no": if YesNoQuestion().ask("Continue submitting this bug", "yes") == "no":
sys.exit(1) sys.exit(1)
@ -230,14 +230,15 @@ def main():
parser.parse_args() parser.parse_args()
if not os.path.exists('/usr/bin/reportbug'): if not os.path.exists('/usr/bin/reportbug'):
print(u"This utility requires the «reportbug» package, which isn't " print("This utility requires the «reportbug» package, which isn't "
u"currently installed.") "currently installed.")
sys.exit(1) sys.exit(1)
check_reportbug_config() check_reportbug_config()
changelog_file = (check_file('debian/changelog', critical=False) or changelog_file = (check_file('debian/changelog', critical=False) or
check_file('../debian/changelog')) check_file('../debian/changelog'))
changelog = Changelog(file(changelog_file).read()) with open(changelog_file) as f:
changelog = Changelog(f.read())
deb_version = get_most_recent_debian_version(changelog) deb_version = get_most_recent_debian_version(changelog)
bug_body = get_bug_body(changelog) bug_body = get_bug_body(changelog)