Print this page
3674 onbld Checks should not query opensolaris.org


  45 
  46 class NonExistentBug(Exception):
  47         def __str__(self):
  48                 return "Bug %s does not exist" % (Exception.__str__(self))
  49 
  50 class BugDBException(Exception):
  51         def __str__(self):
  52                 return "Unknown bug database: %s" % (Exception.__str__(self))
  53 
  54 class BugDB(object):
  55         """Lookup change requests.
  56 
  57         Usage:
  58         bdb = BugDB()
  59         r = bdb.lookup("6455550")
  60         print r["6455550"]["synopsis"]
  61         r = bdb.lookup(["6455550", "6505625"])
  62         print r["6505625"]["synopsis"]
  63         """
  64 
  65         VALID_DBS = ["bugster", "illumos"]
  66 
  67         def __init__(self, priority = ("illumos", "bugster")):
  68                 """Create a BugDB object.
  69 
  70                 Keyword argument:
  71                 priority: use bug databases in this order
  72                 """
  73                 for database in priority:
  74                         if database not in self.VALID_DBS:
  75                                 raise BugDBException, database
  76                 self.__priority = priority
  77 
  78 
  79         def __illbug(self, cr):
  80                 url = "http://illumos.org/issues/%s.xml" % cr
  81                 req = urllib2.Request(url)
  82 
  83                 try:
  84                         data = urllib2.urlopen(req)
  85                 except urllib2.HTTPError, e:
  86                         if e.code == 404:
  87                                 raise NonExistentBug(cr)
  88                         else:
  89                                 raise
  90 
  91                 bug = ElementTree.parse(data)
  92 
  93                 return {'cr_number': bug.find('id').text,
  94                         'synopsis': bug.find('subject').text,
  95                         'status': bug.find('status').attrib['name']
  96                 }
  97 
  98 
  99         def __boobug(self, cr):
 100                 cr = str(cr)
 101                 url = "http://bugs.opensolaris.org/view_bug.do"
 102                 req = urllib2.Request(url, urllib.urlencode({"bug_id": cr}))
 103                 results = {}
 104                 try:
 105                         data = urllib2.urlopen(req).readlines()
 106                 except urllib2.HTTPError, e:
 107                         if e.code != 404:
 108                                 print "ERROR: HTTP error at " + \
 109                                         req.get_full_url() + \
 110                                         " got error: " + str(e.code)
 111                                 raise e
 112                         else:
 113                                 raise NonExistentBug(cr)
 114                 except urllib2.URLError, e:
 115                         print "ERROR: could not connect to " + \
 116                                 req.get_full_url() + \
 117                                 ' got error: "' + e.reason[1] + '"'
 118                         raise e
 119                 htmlParser = htmllib.HTMLParser(None)
 120                 metaHtmlRe = re.compile(r'^<meta name="([^"]+)" content="([^"]*)">$')
 121                 for line in data:
 122                         m = metaHtmlRe.search(line)
 123                         if not m:
 124                                 continue
 125                         val = urllib.unquote(m.group(2))
 126                         htmlParser.save_bgn()
 127                         htmlParser.feed(val)
 128                         results[m.group(1)] = htmlParser.save_end()
 129                 htmlParser.close()
 130 
 131                 if "synopsis" not in results:
 132                         raise NonExistentBug(cr)
 133 
 134                 results["cr_number"] = cr
 135                 results["sub_category"] = results.pop("subcategory")
 136                 results["status"] = results.pop("state")
 137                 results["date_submitted"] = results.pop("submit_date")
 138 
 139                 return results
 140 
 141         def lookup(self, crs):
 142                 """Return all info for requested change reports.
 143 
 144                 Argument:
 145                 crs: one change request id (may be integer, string, or list),
 146                      or multiple change request ids (must be a list)
 147 
 148                 Returns:
 149                 Dictionary, mapping CR=>dictionary, where the nested dictionary
 150                 is a mapping of field=>value
 151                 """
 152                 results = {}
 153                 if not isinstance(crs, list):
 154                         crs = [str(crs)]
 155                 for database in self.__priority:
 156                         if database == "bugster":
 157                                 for cr in crs:
 158                                         cr = str(cr)
 159                                         try:
 160                                                 results[cr] = self.__boobug(cr)
 161                                         except NonExistentBug:
 162                                                 continue
 163                         elif database == "illumos":
 164                                 for cr in crs:
 165                                         try:
 166                                                 results[str(cr)] = self.__illbug(cr)
 167                                         except NonExistentBug:
 168                                                 continue
 169 
 170                         # the CR has already been found by one bug database
 171                         # so don't bother looking it up in the others
 172                         for cr in crs:
 173                                 if cr in results:
 174                                         crs.remove(cr)
 175 
 176                 return results


  45 
  46 class NonExistentBug(Exception):
  47         def __str__(self):
  48                 return "Bug %s does not exist" % (Exception.__str__(self))
  49 
  50 class BugDBException(Exception):
  51         def __str__(self):
  52                 return "Unknown bug database: %s" % (Exception.__str__(self))
  53 
  54 class BugDB(object):
  55         """Lookup change requests.
  56 
  57         Usage:
  58         bdb = BugDB()
  59         r = bdb.lookup("6455550")
  60         print r["6455550"]["synopsis"]
  61         r = bdb.lookup(["6455550", "6505625"])
  62         print r["6505625"]["synopsis"]
  63         """
  64 
  65         VALID_DBS = ["illumos"]
  66 
  67         def __init__(self, priority = ["illumos"]):
  68                 """Create a BugDB object.
  69 
  70                 Keyword argument:
  71                 priority: use bug databases in this order
  72                 """
  73                 for database in priority:
  74                         if database not in self.VALID_DBS:
  75                                 raise BugDBException, database
  76                 self.__priority = priority
  77 
  78 
  79         def __illbug(self, cr):
  80                 url = "http://illumos.org/issues/%s.xml" % cr
  81                 req = urllib2.Request(url)
  82 
  83                 try:
  84                         data = urllib2.urlopen(req)
  85                 except urllib2.HTTPError, e:
  86                         if e.code == 404:
  87                                 raise NonExistentBug(cr)
  88                         else:
  89                                 raise
  90 
  91                 bug = ElementTree.parse(data)
  92 
  93                 return {'cr_number': bug.find('id').text,
  94                         'synopsis': bug.find('subject').text,
  95                         'status': bug.find('status').attrib['name']
  96                 }
  97 
  98 










































  99         def lookup(self, crs):
 100                 """Return all info for requested change reports.
 101 
 102                 Argument:
 103                 crs: one change request id (may be integer, string, or list),
 104                      or multiple change request ids (must be a list)
 105 
 106                 Returns:
 107                 Dictionary, mapping CR=>dictionary, where the nested dictionary
 108                 is a mapping of field=>value
 109                 """
 110                 results = {}
 111                 if not isinstance(crs, list):
 112                         crs = [str(crs)]
 113                 for database in self.__priority:
 114                         if database == "illumos":
 115                                 for cr in crs:

 116                                         try:






 117                                                 results[str(cr)] = self.__illbug(cr)
 118                                         except NonExistentBug:
 119                                                 continue
 120 
 121                         # the CR has already been found by one bug database
 122                         # so don't bother looking it up in the others
 123                         for cr in crs:
 124                                 if cr in results:
 125                                         crs.remove(cr)
 126 
 127                 return results