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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
#!/usr/bin/python
import os
import sys
import locale
import optparse
import re
import copy
from getpass import getpass
try:
import bugzilla
except ImportError:
print "Unable to import bugzilla. Is python-bugzilla installed?"
sys.exit(1)
try:
from simplemediawiki import MediaWiki
except ImportError:
print "Unable to import simplemediawiki. Is python-simpemediawiki installed?"
sys.exit(1)
BUG_STATUS = ['NEW', 'ASSIGNED', 'ON_DEV', 'MODIFIED', 'POST', 'ON_QA', 'FAILS_QA',
'PASSES_QA', 'REOPENED', 'VERIFIED', 'RELEASE_PENDING']
# Blocker query values
BLOCKER_ACCEPTED = {'status_whiteboard': 'AcceptedBlocker',
'status_whiteboard_type': 'anywords'}
BLOCKER_PROPOSED = {'status_whiteboard': 'AcceptedBlocker RejectedBlocker',
'status_whiteboard_type': 'nowords'}
# NTH query values
NTH_ACCEPTED = {'status_whiteboard': 'AcceptedNTH',
'status_whiteboard_type': 'anywords'}
NTH_PROPOSED = {'status_whiteboard': 'AcceptedNTH RejectedNTH',
'status_whiteboard_type': 'nowords'}
COOKIE_FILE = os.path.join(os.environ.get('HOME','/tmp'), '.fedora_cookiefile')
# UTF8 helper - "borrored" from python-bugzilla
def to_encoding(ustring):
if isinstance(ustring, basestring):
if isinstance(ustring, unicode):
return ustring.encode(locale.getpreferredencoding(), 'replace')
return ustring
return u''
# Display list of bugs, organized by components
def wikilist_bugs(bugs_by_component, bugs_by_id):
buf = ''
components = sorted(bugs_by_component.keys())
for component in components:
buf += '\n=== %s ===\n' % component
# sorted list
bugs = sorted(bugs_by_component.get(component,[]))
for b in bugs:
b = bugs_by_id[b]
buf += '* [https://bugzilla.redhat.com/show_bug.cgi?id=%s %s] (%s) - %s\n' % (b.bug_id, b.bug_id, b.bug_status, b.short_desc)
return buf
# Display sortable table of bugs
def wikitable_bugs(bugs_by_component, bugs_by_id):
buf = ''
components = sorted(bugs_by_component.keys())
if len(components) > 0:
buf = '''{| class="wikitable sortable"
! Bug !! Component !! Status !! Description
|- \n'''
for component in components:
# sorted list
bugs = sorted(bugs_by_component.get(component,[]))
for b in bugs:
b = bugs_by_id[b]
buf += '| [https://bugzilla.redhat.com/show_bug.cgi?id=%s %s] || %s || %s || %s\n' % (b.bug_id, b.bug_id, component, b.bug_status, b.short_desc)
buf += '|-\n'
buf += '|}\n'
return buf
def parse_args():
'''Set up the option parser'''
parser = optparse.OptionParser(usage="%prog [options]")
parser.add_option('-v', '--verbose', action='store_true', default=False,
help='Enable verbosity')
parser.add_option('--hotdog', action='store_true', default=False,
help='Enable hot dog (default: %default)')
parser.add_option('--cookiefile', action='store', default=COOKIE_FILE,
help='Cookiejar path to store wiki login cookies (default: %default)')
optgrp = optparse.OptionGroup(parser, "Required options")
optgrp.add_option('-n', '--name', action='store', default=None,
help='Wiki page name to save results')
optgrp.add_option('--blocker', action='store', default=None,
help='Blocker tracking bug number')
optgrp.add_option('--nth', action='store', default=None,
help='Nice-to-Have tracking bug number')
optgrp.add_option('-u', '--user', action='store', default=None,
help='Mediawiki username')
optgrp.add_option('-p', '--passwd', action='store', default=None,
help='Mediawiki password')
parser.add_option_group(optgrp)
(opts, args) = parser.parse_args()
# sanitize helper
def sanitize_input(parser, value, label, ispass=False):
if value is None and sys.stdin.isatty():
prompt = 'Enter %s: ' % label
if ispass:
value = getpass(prompt)
else:
value = raw_input(prompt)
if value is None:
parser.error('Must provide a valid %s' % label)
return value
def valid_cookiefile(parser, cookiefile):
# if it doesn't exist, it can't be valid
if not os.path.exists(cookiefile):
return False
# Check if it contains valid data
fd = open(cookiefile, 'r')
buf = fd.read()
fd.close()
valid = False
for line in buf.split('\n'):
# Skip empty lines or lines with only comments
if re.match(r'^(\s*#|\s*$)', line):
continue
return True
# Otherwise, no valid content found
return False
if not valid_cookiefile(parser, opts.cookiefile):
opts.user = sanitize_input(parser, opts.user, "username")
opts.passwd = sanitize_input(parser, opts.passwd, "password", ispass=True)
opts.blocker = sanitize_input(parser, opts.blocker, "Blocker bug number")
opts.nth = sanitize_input(parser, opts.nth, "Nice-to-have bug number")
opts.name = sanitize_input(parser, opts.name, "Wiki page name")
return opts
def flatten_bug_list(query_args, max_depth=4):
buglist = bz.query(query_args)
# avoid endless recursion
if max_depth <= 0:
return buglist
# find any additional dependencies
new_deps = list()
for b in buglist:
if len(b.dependson) > 0:
new_deps.append(b.bug_id)
# Remove any duplicates
existing_deps = {int(bug):True for bug in query_args['value0-0-0'].split()}.keys()
new_deps = {bug:True for bug in new_deps}.keys()
# Ignore anything already being tracked
copy_new_deps = copy.deepcopy(new_deps)
for bug in copy_new_deps:
if bug in existing_deps:
new_deps.remove(bug)
if len(new_deps) > 0:
query_args['value0-0-0'] = ' '.join([str(bug) for bug in existing_deps]) + ' ' + ' '.join([str(bug) for bug in new_deps])
if opts.verbose: print ' additional dependencies: %s' % ' '.join([str(bug) for bug in new_deps])
return flatten_bug_list(query_args, max_depth-1)
return buglist
if __name__ == '__main__':
opts = parse_args()
# Connect to bugzilla
bz = bugzilla.RHBugzilla3(url='https://bugzilla.redhat.com/xmlrpc.cgi')
# If needed, Convert bug alias to number
if not opts.blocker.isdigit():
opts.blocker = bz.getbug(opts.blocker).id
if not opts.nth.isdigit():
opts.nth = bz.getbug(opts.nth).id
# Get a list of accepted blocker bugs
if opts.verbose: print 'Querying accepted blocker bugs ...'
q = {'bug_status': BUG_STATUS,
'value0-0-0': str(opts.blocker),
'type0-0-0': 'anywords',
'field0-0-0': 'blocked'}
q.update(BLOCKER_ACCEPTED)
accepted_blockers = flatten_bug_list(q)
# Get a list of proposed blocker bugs
if opts.verbose: print 'Querying proposed blocker bugs ...'
q = {'bug_status': BUG_STATUS,
'value0-0-0': str(opts.blocker),
'type0-0-0': 'anywords',
'field0-0-0': 'blocked'}
q.update(BLOCKER_PROPOSED)
proposed_blockers = flatten_bug_list(q)
# Get a list of accepted NTH bugs
if opts.verbose: print 'Querying accepted nice-to-have bugs ...'
q = {'bug_status': BUG_STATUS,
'value0-0-0': str(opts.nth),
'type0-0-0': 'anywords',
'field0-0-0': 'blocked'}
q.update(NTH_ACCEPTED)
accepted_nths = flatten_bug_list(q)
# Get a list of proposed NTH bugs
if opts.verbose: print 'Querying proposed nice-to-have bugs ...'
q = {'bug_status': BUG_STATUS,
'value0-0-0': str(opts.nth),
'type0-0-0': 'anywords',
'field0-0-0': 'blocked'}
q.update(NTH_PROPOSED)
proposed_nths = flatten_bug_list(q)
# Organize bugs for later reference
if opts.verbose: print 'Organizing bugs ...'
bugs_by_id = dict()
# walk accepted blockers
accepted_blocker_by_component = dict()
for b in accepted_blockers:
# Skip Tracking bugs
if 'Tracking' in b.keywords:
continue
if not accepted_blocker_by_component.has_key(b.component):
accepted_blocker_by_component[b.component] = list()
accepted_blocker_by_component[b.component].append(b.bug_id)
bugs_by_id[b.bug_id] = b
# walk proposed blockers
proposed_blocker_by_component = dict()
for b in proposed_blockers:
# Skip Tracking bugs
if 'Tracking' in b.keywords:
continue
if not proposed_blocker_by_component.has_key(b.component):
proposed_blocker_by_component[b.component] = list()
proposed_blocker_by_component[b.component].append(b.bug_id)
bugs_by_id[b.bug_id] = b
# walk accepted nths
accepted_nth_by_component = dict()
for b in accepted_nths:
# Skip Tracking bugs
if 'Tracking' in b.keywords:
continue
if not accepted_nth_by_component.has_key(b.component):
accepted_nth_by_component[b.component] = list()
accepted_nth_by_component[b.component].append(b.bug_id)
bugs_by_id[b.bug_id] = b
# walk proposed nths
proposed_nth_by_component = dict()
for b in proposed_nths:
# Skip Tracking bugs
if 'Tracking' in b.keywords:
continue
if not proposed_nth_by_component.has_key(b.component):
proposed_nth_by_component[b.component] = list()
proposed_nth_by_component[b.component].append(b.bug_id)
bugs_by_id[b.bug_id] = b
# Generate page content
page_content = '''
''This page generated automatically using [http://fedorapeople.org/gitweb?p=jlaska/public_git/scripts.git %s].''
''' % (os.path.basename(sys.argv[0]),)
# Display hotdog if requested, or if no blockers (approved or proposed) exist
if opts.hotdog or \
(not accepted_blocker_by_component and not proposed_blocker_by_component):
page_content += '[[File:Hotdog.gif|right]]'
# Otherwise, display release logo
else:
page_content += '[[File:F{{FedoraVersionNumber|next}}_anaconda_center.png|right]]'
def join_lists(l):
'''
Takes a list of lists, and joins them into a single list. For example:
[[1,2,3],[4],[5,6,7]] will become [1,2,3,4,5,6,7]
'''
return [item for sublist in l for item in sublist]
# Display approved blockers
# FIXME - automatically display the hotdog if no approved + proposed blockers exist
page_content += '''
== Approved Blockers ==
The following list of bugs are approved blockers that must be resolved. There
{{plural:%(bug_count)s|is|are}} %(bug_count)s bug{{plural:%(bug_count)s||s}}
affecting %(component_count)s component{{plural:%(component_count)s||s}}.
''' % dict (bug_count=len(join_lists(accepted_blocker_by_component.values())),
component_count=len(accepted_blocker_by_component))
# Sorted list of approved bugs
page_content += wikitable_bugs(accepted_blocker_by_component, bugs_by_id)
# Display proposed blockers
page_content += '''
== Proposed Blockers ==
The following list of bugs are not yet approved to block the release. There
{{plural:%(bug_count)s|is|are}} %(bug_count)s bug{{plural:%(bug_count)s||s}}
affecting %(component_count)s component{{plural:%(component_count)s||s}}. For
guidance on reviewing the following bugs, refer to
[[QA:SOP_blocker_bug_process]].
''' % dict (bug_count=len(join_lists(proposed_blocker_by_component.values())),
component_count=len(proposed_blocker_by_component))
# Sorted list of proposed bugs
page_content += wikitable_bugs(proposed_blocker_by_component, bugs_by_id)
# Display approved nths
page_content += '''
== Approved NICE-TO-HAVE ==
The following list of of bugs are approved nice-to-have. Fixes for
nice-to-have bugs will be accepted during the freeze. There
{{plural:%(bug_count)s|is|are}} %(bug_count)s bug{{plural:%(bug_count)s||s}}
affecting %(component_count)s component{{plural:%(component_count)s||s}}.
''' % dict (bug_count=len(join_lists(accepted_nth_by_component.values())),
component_count=len(accepted_nth_by_component))
# Sorted list of approved bugs
page_content += wikitable_bugs(accepted_nth_by_component, bugs_by_id)
# Display proposed nths
page_content += '''
== Proposed NICE-TO-HAVE ==
The following list of bugs are not yet approved nice-to-have issues. Only
fixes for approved nice-to-have bugs will be accepted during the freeze. There
{{plural:%(bug_count)s|is|are}} %(bug_count)s bug{{plural:%(bug_count)s||s}}
affecting %(component_count)s component{{plural:%(component_count)s||s}}. For
guidance on reviewing the following bugs, refer to [[QA:SOP_nth_bug_process]].
''' % dict (bug_count=len(join_lists(proposed_nth_by_component.values())),
component_count=len(proposed_nth_by_component))
# Sorted list of proposed bugs
page_content += wikitable_bugs(proposed_nth_by_component, bugs_by_id)
# Create mediawiki handle
if opts.verbose: print 'Connecting to mediawiki ...'
wiki = MediaWiki('https://fedoraproject.org/w/api.php', cookie_file=opts.cookiefile)
# Login to the wiki
if opts.user:
if opts.verbose: print 'Logging into mediawiki ...'
if not wiki.login(opts.user, opts.passwd):
print "Error: invalid mediawiki username or password"
sys.exit(1)
else:
if opts.verbose: print 'Using cookies in %s for authentication' % opts.cookiefile
# Get an edit token
q = dict(action='query',
prop='info',
intoken='edit',
titles=opts.name)
response = wiki.call(q)
pages = [v for k,v in response.get('query', {}).get('pages',{}).items()]
edit_token = list()
if pages:
edit_token = pages[0]
# Make the wiki edit
q = dict(action='edit',
token=edit_token.get('edittoken',''),
starttimestamp=edit_token.get('starttimestamp',''),
summary='This scripted update brought to you by python-simplemediawiki and python-bugzilla.',
text=to_encoding(u'%s' % page_content),
title=opts.name)
response = wiki.call(q)
url = "https://fedoraproject.org/wiki/%s" % q.get('title')
# Failure - Captcha
if response.get('edit',{}).get('result','').lower() == 'failure':
# Is a captcha required?
captcha = response.get('edit', {}).get('captcha', False)
if captcha:
q.update(dict(captchaid=captcha.get('id'),
captchaword=eval(captcha.get('question'))))
response = wiki.call(q)
# Error - Permission denied
if response.has_key('error'):
print "Failed to update '%s'\n%s" % (q.get('title'), response.get('error',{}).get('info',''))
sys.exit(1)
if response.get('result','').lower() == 'failure':
print "Failed to update '%s'\n%s" % (q.get('title'), response)
sys.exit(1)
# Info - nochange
elif response.get('edit',{}).has_key('nochange'):
print "No changes, %s not updated" % (q.get('title'),)
# Success
elif response.get('edit',{}).has_key('newrevid'):
print "Updated %s (revision: %s)" % (url,
response.get('edit',{}).get('newrevid'))
# Unknown
else:
print "Unknown result while updating %s\n%s" % (q.get('title'), response)
sys.exit(0)
|