#!/usr/bin/env python # Copyright 2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 import datetime import optparse import bugz.bugzilla import portage.versions from common import Bug, chunks class MyBugz(bugz.bugzilla.Bugz): def get_input(self, prompt): return raw_input(prompt) if __name__ == "__main__": parser = optparse.OptionParser() parser.add_option("--days", dest="days", type=int, default=30, help="Number of days after maintainer timeout occurs.") (options, args) = parser.parse_args() if args: parser.error("unrecognized command-line args") url = 'https://bugs.gentoo.org' print 'You may be prompted for your Gentoo Bugzilla username and password (%s).' % url bugzilla = MyBugz(url, forget=True) bugzilla.auth() bugs = [] raw_bugs = bugzilla.search('please stabilize', reporter=bugzilla.user, status=None) for chunk in chunks(raw_bugs, 100): bugs += [Bug(xml) for xml in bugzilla.get([bug['bugid'] for bug in chunk]).findall("bug")] for bug in bugs: # Skip bugs where stabilization seems to be already in progress. arch_found = False for arch in portage.archlist: if '%s@gentoo.org' % arch in bug.cc(): arch_found = True break if arch_found: continue # Skip bugs with comments, they may indicate objections or problem reports. if len(bug.comments()) > 1: continue # Skip too recent bugs. if datetime.datetime.now() - bug.creation_timestamp() < datetime.timedelta(days=options.days): continue bug.detect_cpvs() if len(bug.cpvs()) != 1: continue target_keywords = set() cp = portage.versions.cpv_getkey(bug.cpvs()[0]) for cpv in portage.portdb.cp_list(cp): for keyword in portage.portdb.aux_get(cpv, ['KEYWORDS'])[0].split(): if '~' not in keyword and '-' not in keyword: target_keywords.add(keyword) bugzilla.modify( bug.id_number(), comment='Maintainer timeout (%d days). Arches please go ahead.' % options.days, add_cc=['%s@gentoo.org' % k for k in target_keywords], keywords='STABLEREQ') print 'Updated bug #%d (%s). Target KEYWORDS: %s ;-)' % ( bug.id_number(), bug.summary(), ', '.join(list(target_keywords)))