Package moap :: Package bug :: Module bugzilla
[hide private]
[frames] | no frames]

Source Code for Module moap.bug.bugzilla

 1  # -*- Mode: Python; test-case-name: moap.test.test_bug_bugzilla -*- 
 2  # vi:si:et:sw=4:sts=4:ts=4 
 3   
 4  import csv 
 5  import urllib2 
 6   
 7  from moap.bug import bug 
 8   
9 -def detect(URL):
10 # FIXME: do smarter stuff in there 11 if URL.find('bugzilla') == -1: 12 return None 13 14 return URL
15
16 -class Bugzilla(bug.BugTracker):
17 """ 18 Queries bugzilla using the CSV format. 19 CSV is supported by both Red Hat's and GNOME's bugzilla. 20 """
21 - def __init__(self, URL):
22 # when we get the URL from a DOAP file, scrub the submission part 23 # from it 24 if URL and 'enter_bug.cgi' in URL: 25 URL = URL[:URL.find('enter_bug.cgi')] 26 bug.BugTracker.__init__(self, URL) 27 self.debug('Initialized with URL %s' % URL)
28
29 - def getBug(self, id, handle=None):
30 # a handle can be passed for tests to bypass retrieving a URL 31 return self.query('bug_id=%s' % id, handle)[0]
32
33 - def query(self, queryString, handle=None):
34 result = [] 35 36 if not handle: 37 url = self.URL + \ 38 "/buglist.cgi?query_format=advanced&ctype=csv&%s" % queryString 39 self.debug('Retrieving url %s' % url) 40 handle = urllib2.urlopen(url) 41 42 reader = csv.reader(handle) 43 44 header = reader.next() 45 for row in reader: 46 # turn into a dict 47 d = {} 48 pairs = map(None, header, row) 49 for key, value in pairs: 50 d[key] = value 51 52 # create the bug 53 b = bug.Bug(d['bug_id'], d['short_short_desc']) 54 result.append(b) 55 56 return result
57 58 # FIXME: not yet used
59 -class _BugzillaRDF:
60 """ 61 I wrap an RDF location from a bugzilla server. 62 """
63 - def __init__(self):
64 # FIXME: obviously Querier is generic RDF 65 from moap.doap import common 66 self._querier = common.Querier()
67
68 - def addLocation(self, location):
69 self._querier.addLocation(location)
70
71 - def getById(self, id):
72 querystring = """ 73 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 74 PREFIX bz: <http://www.bugzilla.org/rdf#> 75 PREFIX nc: <http://home.netscape.com/NC-rdf#> 76 SELECT ?description 77 WHERE { 78 ?result rdf:type bz:result . 79 ?result bz:short_short_desc ?description 80 } 81 """ 82 list = self._querier.query(querystring, query_language='sparql') 83 print list 84 assert len(list) == 1, \ 85 "Length of list is %d instead of 1" % len(list) 86 # because r[0] won't work 87 for r in list: pass
88 89 BugClass = Bugzilla 90