5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
24 # Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
27 # Copyright 2010, Richard Lowe
30 # Various database lookup classes/methods, i.e.:
32 # * bugs.opensolaris.org (b.o.o.)
33 # * redmine (illumos.org)
42 from xml
.etree
import ElementTree
44 from elementtree
import ElementTree
46 class NonExistentBug(Exception):
48 return "Bug %s does not exist" % (Exception.__str
__(self
))
50 class BugDBException(Exception):
52 return "Unknown bug database: %s" % (Exception.__str
__(self
))
55 """Lookup change requests.
59 r = bdb.lookup("6455550")
60 print r["6455550"]["synopsis"]
61 r = bdb.lookup(["6455550", "6505625"])
62 print r["6505625"]["synopsis"]
65 VALID_DBS
= ["illumos"]
67 def __init__(self
, priority
= ["illumos"]):
68 """Create a BugDB object.
71 priority: use bug databases in this order
73 for database
in priority
:
74 if database
not in self
.VALID_DBS
:
75 raise BugDBException
, database
76 self
.__priority
= priority
79 def __illbug(self
, cr
):
80 url
= "http://illumos.org/issues/%s.xml" % cr
81 req
= urllib2
.Request(url
)
84 data
= urllib2
.urlopen(req
)
85 except urllib2
.HTTPError
, e
:
87 raise NonExistentBug(cr
)
91 bug
= ElementTree
.parse(data
)
93 return {'cr_number': bug
.find('id').text
,
94 'synopsis': bug
.find('subject').text
,
95 'status': bug
.find('status').attrib
['name']
99 def lookup(self
, crs
):
100 """Return all info for requested change reports.
103 crs: one change request id (may be integer, string, or list),
104 or multiple change request ids (must be a list)
107 Dictionary, mapping CR=>dictionary, where the nested dictionary
108 is a mapping of field=>value
111 if not isinstance(crs
, list):
113 for database
in self
.__priority
:
114 if database
== "illumos":
117 results
[str(cr
)] = self
.__illbug
(cr
)
118 except NonExistentBug
:
121 # the CR has already been found by one bug database
122 # so don't bother looking it up in the others