summaryrefslogtreecommitdiff
blob: 1c5bbe9c365f1e2395320cd0533c11e13ddb17d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python2
# Copyright 2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

import glob
import itertools
import optparse
import os
import pickle
import re
import shutil
import subprocess
import sys
import urllib
import xmlrpclib

from bugz.bugzilla import BugzillaProxy
from common import login
import portage.versions
from portage.xml.metadata import MetaDataXML

def save_state(done_cpvs):
	with open('file-stabilization-bugs.state', 'w') as state_file:
		pickle.dump(done_cpvs, state_file)

if __name__ == "__main__":
	exit_code = 0

	parser = optparse.OptionParser()
	parser.add_option("-i", "--input", dest="input_filename", default="stabilization-candidates.txt", help="Input filename [default=%default]")
	parser.add_option("--repo", dest="repo", help="Path to portage CVS repository")

	(options, args) = parser.parse_args()
	if not options.input_filename:
		parser.error("--input option is required")
	if not options.repo:
		parser.error("--repo option is required")
	if args:
		parser.error("unrecognized command-line args")

	done_cpvs = []
	if os.path.exists('file-stabilization-bugs.state'):
		with open('file-stabilization-bugs.state', 'r') as state_file:
			done_cpvs = pickle.load(state_file)

	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)
	
	with open(options.input_filename, "r") as input_file:
		for line in input_file:
			line = line.strip()

			# Skip empty/whitespace/comment lines.
			if not line or line.startswith("#"):
				continue

			cpv = line
			if cpv in done_cpvs:
				print 'Skipping %s because it\'s marked as done' % cpv
				continue

			cp = portage.versions.pkgsplit(cpv)[0]

			cvs_path = os.path.join(options.repo, cp)
			metadata = MetaDataXML(os.path.join(cvs_path, 'metadata.xml'), '/usr/portage/metadata/herds.xml')
			maintainer_split = metadata.format_maintainer_string().split(' ', 1)
			maintainer = maintainer_split[0]
			if len(maintainer_split) > 1:
				other_maintainers = maintainer_split[1].split(',')
			else:
				other_maintainers = []

			description = ('Is it OK to stabilize =%s ?\n' % cpv +
				       'If so, please CC all arches which have stable keywords\n' +
				       'for older versions of this package.')
			url = 'http://packages.gentoo.org/package/%s?arches=linux' % urllib.quote(cp)
			params = {}
			params['product'] = 'Gentoo Linux'
			params['version'] = 'unspecified'
			params['component'] = 'Keywording and Stabilization'
			params['summary'] = '%s: stabilization request' % cpv
			params['description'] = description
			params['url'] = url
			params['assigned_to'] = maintainer
			params['cc'] = other_maintainers
			params['severity'] = 'enhancement'
			try:
				bug_id = bugzilla.Bug.create(params)['id']
				print 'Submitted bug #%d for %s. ;-)' % (bug_id, cpv)
				done_cpvs += cpv
				save_state(done_cpvs)
				try:
					params = {}
					params['ids'] = [bug_id]
					params['keywords'] = {'set': 'STABLEREQ'}
					bugzilla.Bug.update(params)
				except xmlrpclib.Fault, f:
					exit_code = 1
					print f
					print 'Failed to add STABLEREQ keyword for %s. :-/' % cpv
			except xmlrpclib.Fault, f:
				exit_code = 1
				print f
				print 'Failed to submit bug for %s. :-(' % cpv
	
	if exit_code == 0 and os.path.exists('file-stabilization-bugs.state'):
		os.remove('file-stabilization-bugs.state')
	
	sys.exit(exit_code)