arsenal-devel team mailing list archive
-
arsenal-devel team
-
Mailing list archive
-
Message #00040
[Merge] lp:~inspirated/arsenal/bugzilla-patches-python into lp:arsenal
Kamran Riaz Khan has proposed merging lp:~inspirated/arsenal/bugzilla-patches-python into lp:arsenal.
Requested reviews:
arsenal-devel (arsenal-devel)
Reimplemented scripts/bugzilla-patches in Python in scripts/bugzilla-info.
--
https://code.launchpad.net/~inspirated/arsenal/bugzilla-patches-python/+merge/22786
Your team arsenal-devel is subscribed to branch lp:arsenal.
=== added file 'scripts/bugzilla-info'
--- scripts/bugzilla-info 1970-01-01 00:00:00 +0000
+++ scripts/bugzilla-info 2010-04-04 11:01:19 +0000
@@ -0,0 +1,107 @@
+#!/usr/bin/env python
+
+import json
+import optparse
+import sgmllib
+import urllib
+
+class BugzillaParser(sgmllib.SGMLParser):
+ interesting_tags = [
+ {
+ 'name' : 'td',
+ 'attrs' : {'id' : 'title'},
+ 'key' : 'title',
+ },
+ {
+ 'name' : 'td',
+ 'attrs' : {'id' : 'field_container_product'},
+ 'key' : 'product',
+ },
+ {
+ 'name' : 'td',
+ 'attrs' : {'id' : 'bz_field_status'},
+ 'key' : 'status',
+ },
+ {
+ 'name' : 'p',
+ 'attrs' : {'class' : 'subheader'},
+ 'key' : 'subtitle',
+ },
+ {
+ 'name' : 'p',
+ 'attrs' : {'class' : 'header_addl_info'},
+ 'key' : 'last_modified',
+ },
+ ]
+
+ def __init__(self, verbose=0):
+ sgmllib.SGMLParser.__init__(self, verbose)
+
+ self.bug = {}
+ self.current_tag = False
+ self.current_key = False
+
+ def parse(self, contents):
+ self.feed(contents)
+ self.close()
+
+ for (key, value) in self.bug.items():
+ self.bug[key] = value.strip()
+
+ def unknown_starttag(self, tag, attrs_list):
+ attrs = dict(attrs_list)
+
+ for interesting_tag in BugzillaParser.interesting_tags:
+ if not interesting_tag['name'] == tag:
+ continue
+
+ match = True
+ for (key, value) in interesting_tag['attrs'].items():
+ try:
+ if not value == attrs[key]:
+ match = False
+ except KeyError:
+ match = False
+
+ if match:
+ self.current_tag = interesting_tag['name']
+ self.current_key = interesting_tag['key']
+
+ def unknown_endtag(self, tag):
+ if tag == self.current_tag:
+ self.current_tag = False
+ self.current_key = False
+
+ def handle_data(self, data):
+ if self.current_tag:
+ key = self.current_key
+ if self.bug.has_key(key):
+ self.bug[key] = self.bug[key] + data
+ else:
+ self.bug[key] = data
+
+if __name__ == '__main__':
+ usage = '''
+ %prog [-j] URL
+ Example: %prog -j https://bugzilla.redhat.com/show_bug.cgi?id=477955
+ '''
+
+ parser = optparse.OptionParser(usage=usage)
+ parser.add_option('-j', '--json',
+ action='store_true', dest='json', default=False,
+ help='Output bug details in JSON')
+ (options, args) = parser.parse_args()
+
+ if len(args) < 1:
+ parser.print_help()
+
+ file = urllib.urlopen(args[0])
+ contents = file.read()
+ bugzilla_parser = BugzillaParser()
+ bugzilla_parser.parse(contents)
+
+ if options.json:
+ print json.dumps(bugzilla_parser.bug, sort_keys=True, indent=4)
+ else:
+ print bugzilla_parser.bug['subtitle']
+
Follow ups