Merge lp:~inspirated/arsenal/bugzilla-patches-python into lp:arsenal/trunk

Proposed by Kamran Riaz Khan
Status: Merged
Merged at revision: not available
Proposed branch: lp:~inspirated/arsenal/bugzilla-patches-python
Merge into: lp:arsenal/trunk
Diff against target: 111 lines (+107/-0)
1 file modified
scripts/bugzilla-info (+107/-0)
To merge this branch: bzr merge lp:~inspirated/arsenal/bugzilla-patches-python
Reviewer Review Type Date Requested Status
arsenal-devel Pending
Review via email: mp+22786@code.launchpad.net

Description of the change

Reimplemented scripts/bugzilla-patches in Python in scripts/bugzilla-info.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'scripts/bugzilla-info'
2--- scripts/bugzilla-info 1970-01-01 00:00:00 +0000
3+++ scripts/bugzilla-info 2010-04-04 11:01:19 +0000
4@@ -0,0 +1,107 @@
5+#!/usr/bin/env python
6+
7+import json
8+import optparse
9+import sgmllib
10+import urllib
11+
12+class BugzillaParser(sgmllib.SGMLParser):
13+ interesting_tags = [
14+ {
15+ 'name' : 'td',
16+ 'attrs' : {'id' : 'title'},
17+ 'key' : 'title',
18+ },
19+ {
20+ 'name' : 'td',
21+ 'attrs' : {'id' : 'field_container_product'},
22+ 'key' : 'product',
23+ },
24+ {
25+ 'name' : 'td',
26+ 'attrs' : {'id' : 'bz_field_status'},
27+ 'key' : 'status',
28+ },
29+ {
30+ 'name' : 'p',
31+ 'attrs' : {'class' : 'subheader'},
32+ 'key' : 'subtitle',
33+ },
34+ {
35+ 'name' : 'p',
36+ 'attrs' : {'class' : 'header_addl_info'},
37+ 'key' : 'last_modified',
38+ },
39+ ]
40+
41+ def __init__(self, verbose=0):
42+ sgmllib.SGMLParser.__init__(self, verbose)
43+
44+ self.bug = {}
45+ self.current_tag = False
46+ self.current_key = False
47+
48+ def parse(self, contents):
49+ self.feed(contents)
50+ self.close()
51+
52+ for (key, value) in self.bug.items():
53+ self.bug[key] = value.strip()
54+
55+ def unknown_starttag(self, tag, attrs_list):
56+ attrs = dict(attrs_list)
57+
58+ for interesting_tag in BugzillaParser.interesting_tags:
59+ if not interesting_tag['name'] == tag:
60+ continue
61+
62+ match = True
63+ for (key, value) in interesting_tag['attrs'].items():
64+ try:
65+ if not value == attrs[key]:
66+ match = False
67+ except KeyError:
68+ match = False
69+
70+ if match:
71+ self.current_tag = interesting_tag['name']
72+ self.current_key = interesting_tag['key']
73+
74+ def unknown_endtag(self, tag):
75+ if tag == self.current_tag:
76+ self.current_tag = False
77+ self.current_key = False
78+
79+ def handle_data(self, data):
80+ if self.current_tag:
81+ key = self.current_key
82+ if self.bug.has_key(key):
83+ self.bug[key] = self.bug[key] + data
84+ else:
85+ self.bug[key] = data
86+
87+if __name__ == '__main__':
88+ usage = '''
89+ %prog [-j] URL
90+ Example: %prog -j https://bugzilla.redhat.com/show_bug.cgi?id=477955
91+ '''
92+
93+ parser = optparse.OptionParser(usage=usage)
94+ parser.add_option('-j', '--json',
95+ action='store_true', dest='json', default=False,
96+ help='Output bug details in JSON')
97+ (options, args) = parser.parse_args()
98+
99+ if len(args) < 1:
100+ parser.print_help()
101+
102+ file = urllib.urlopen(args[0])
103+ contents = file.read()
104+ bugzilla_parser = BugzillaParser()
105+ bugzilla_parser.parse(contents)
106+
107+ if options.json:
108+ print json.dumps(bugzilla_parser.bug, sort_keys=True, indent=4)
109+ else:
110+ print bugzilla_parser.bug['subtitle']
111+

Subscribers

People subscribed via source and target branches

to status/vote changes: