diff options
author | William Hubbs <w.d.hubbs@gmail.com> | 2014-12-13 13:33:09 -0600 |
---|---|---|
committer | Pawel Hajdan, Jr <phajdan.jr@gentoo.org> | 2014-12-29 15:52:27 +0100 |
commit | 842f3d251d81ffc274fa01a1d9ba9b5794a2d714 (patch) | |
tree | 8754a07f108bb8715a2c83c4f0fdd25c485c33e2 /stabilization-candidates.py | |
parent | Fix issue in batch-stabilize leading to errors from Bugzilla (diff) | |
download | arch-tools-842f3d251d81ffc274fa01a1d9ba9b5794a2d714.tar.gz arch-tools-842f3d251d81ffc274fa01a1d9ba9b5794a2d714.tar.bz2 arch-tools-842f3d251d81ffc274fa01a1d9ba9b5794a2d714.zip |
Port most tools to python 3
This commit ports the following tools to python 3.
- common code
- batch-stabilize
- file-stabilization-bugs
- maintainer-timeout
- reverse-dependencies
- stabilization-candidates
This is a list of the changes:
- Remove the dependency on pybugz; these tools now use xmlrpc.client
directly. This is needed because the next release of pybugz does the
same thing; we no longer have a bugzilla module since it was just a
wrapper.
Handle tokens correctly:
- When we log into Bugzilla, we are given a
token we must pass back to it with every command we issue.
- Log out at the end of every session to expire the token.
Fix the state file processing:
- The pickle module handles binary files, not text files, so read and
write the state file in binary mode.
- Add fix_imports=True when reading the state file so a python-2
compatible state file can be read.
- Do not set the URL for a stabilization request
X-Gentoo-Bug: 532054
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=532054
X-Gentoo-Bug: 532368
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=532368
Diffstat (limited to 'stabilization-candidates.py')
-rwxr-xr-x | stabilization-candidates.py | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/stabilization-candidates.py b/stabilization-candidates.py index 52c88f1..d324bdb 100755 --- a/stabilization-candidates.py +++ b/stabilization-candidates.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # Copyright 2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 @@ -8,10 +8,8 @@ import os.path import random import re import subprocess -import xmlrpclib -import urllib +import xmlrpc.client -from bugz.bugzilla import BugzillaProxy from portage.package.ebuild.getmaskingstatus import getmaskingstatus from portage.xml.metadata import MetaDataXML import portage.versions @@ -36,9 +34,9 @@ if __name__ == "__main__": parser.error("unrecognized command-line args") url = 'https://bugs.gentoo.org/xmlrpc.cgi' - print 'You will be prompted for your Gentoo Bugzilla username and password (%s).' % url - bugzilla = BugzillaProxy(url) - login(bugzilla) + print('You will be prompted for your Gentoo Bugzilla username and password (%s).' % url) + bugzilla = xmlrpc.client.ServerProxy(url) + user, login_data = login(bugzilla) final_candidates = [] now = datetime.datetime.now() @@ -77,7 +75,7 @@ if __name__ == "__main__": best_stable = portage.versions.best(portage.portdb.match(cp)) if not best_stable: continue - print 'Working on %s...' % cp, + print('Working on %s...' % cp, end=' ') candidates = [] for cpv in portage.portdb.cp_list(cp): # Only consider higher versions than best stable. @@ -100,12 +98,12 @@ if __name__ == "__main__": continue # Eliminate hard masked packages among others. - if getmaskingstatus(cpv) not in [[u'~%s keyword' % arch] for arch in options.arch]: + if getmaskingstatus(cpv) not in [['~%s keyword' % arch] for arch in options.arch]: continue candidates.append(cpv) if not candidates: - print 'no candidates' + print('no candidates') continue candidates.sort(key=portage.versions.cpv_sort_key()) @@ -122,14 +120,14 @@ if __name__ == "__main__": regex = '\*%s \((.*)\)' % re.escape(pv) match = re.search(regex, changelog_file.read()) if not match: - print 'error parsing ChangeLog' + print('error parsing ChangeLog') continue changelog_date = datetime.datetime.strptime(match.group(1), '%d %b %Y') if now - changelog_date < datetime.timedelta(days=options.days): - print 'not old enough' + print('not old enough') continue - except IOError, e: - print e + except IOError as e: + print(e) continue keywords = portage.db["/"]["porttree"].dbapi.aux_get(best_candidate, ['KEYWORDS'])[0] @@ -139,19 +137,25 @@ if __name__ == "__main__": missing_arch = True break if missing_arch: - print 'not keyworded ~arch' + print('not keyworded ~arch') continue # Do not risk trying to stabilize a package with known bugs. - bugs = [x for x in bugzilla.Bug.search({'summary': cp})['bugs'] if x['is_open'] and x['severity'] not in ['enhancement', 'QA']] + params = {} + params['Bugzilla_token'] = login_data['token'] + params['summary'] = cp + bugs = [x for x in bugzilla.Bug.search(params)['bugs'] if x['is_open'] and x['severity'] not in ['enhancement', 'QA']] if bugs: - print 'has bugs' + print('has bugs') continue # Protection against filing a stabilization bug twice. - bugs = bugzilla.Bug.search({'summary': best_candidate})['bugs'] + params = {} + params['Bugzilla_token'] = login_data['token'] + params['summary'] = best_candidate + bugs = bugzilla.Bug.search(params)['bugs'] if bugs: - print 'version has bugs' + print('version has bugs') continue ebuild_name = portage.versions.catsplit(best_candidate)[1] + ".ebuild" @@ -160,8 +164,8 @@ if __name__ == "__main__": try: original_contents = open(ebuild_path).read() manifest_contents = open(manifest_path).read() - except IOError, e: - print e + except IOError as e: + print(e) continue try: for arch in options.arch: @@ -169,7 +173,7 @@ if __name__ == "__main__": subprocess.check_output(["repoman", "manifest"], cwd=cvs_path) subprocess.check_output(["repoman", "full"], cwd=cvs_path) except subprocess.CalledProcessError: - print 'repoman error' + print('repoman error') continue finally: f = open(ebuild_path, "w") @@ -182,4 +186,8 @@ if __name__ == "__main__": with open(options.output_filename, 'a') as f: f.write('# %s %s\n' % (maintainer, ', '.join(other_maintainers))) f.write('%s\n' % best_candidate) - print (best_candidate, maintainer, other_maintainers) + print((best_candidate, maintainer, other_maintainers)) + + params = {} + params['Bugzilla_token'] = login_data['token'] + bugzilla.User.logout(params) |