Print this page
3674 onbld Checks should not query opensolaris.org
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/onbld/Checks/DbLookups.py
+++ new/usr/src/tools/onbld/Checks/DbLookups.py
1 1 #! /usr/bin/python
2 2 #
3 3 # CDDL HEADER START
4 4 #
5 5 # The contents of this file are subject to the terms of the
6 6 # Common Development and Distribution License (the "License").
7 7 # You may not use this file except in compliance with the License.
8 8 #
9 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 # or http://www.opensolaris.org/os/licensing.
11 11 # See the License for the specific language governing permissions
12 12 # and limitations under the License.
13 13 #
14 14 # When distributing Covered Code, include this CDDL HEADER in each
15 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 # If applicable, add the following below this CDDL HEADER, with the
17 17 # fields enclosed by brackets "[]" replaced with your own identifying
18 18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 19 #
20 20 # CDDL HEADER END
21 21 #
22 22
23 23 #
24 24 # Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
25 25 #
26 26
27 27 # Copyright 2010, Richard Lowe
28 28
29 29 #
30 30 # Various database lookup classes/methods, i.e.:
31 31 # * monaco
32 32 # * bugs.opensolaris.org (b.o.o.)
33 33 # * redmine (illumos.org)
34 34 #
35 35
36 36 import htmllib
37 37 import re
38 38 import urllib
39 39 import urllib2
40 40
41 41 try: # Python >= 2.5
42 42 from xml.etree import ElementTree
43 43 except ImportError:
44 44 from elementtree import ElementTree
45 45
46 46 class NonExistentBug(Exception):
47 47 def __str__(self):
48 48 return "Bug %s does not exist" % (Exception.__str__(self))
49 49
50 50 class BugDBException(Exception):
51 51 def __str__(self):
52 52 return "Unknown bug database: %s" % (Exception.__str__(self))
53 53
54 54 class BugDB(object):
↓ open down ↓ |
54 lines elided |
↑ open up ↑ |
55 55 """Lookup change requests.
56 56
57 57 Usage:
58 58 bdb = BugDB()
59 59 r = bdb.lookup("6455550")
60 60 print r["6455550"]["synopsis"]
61 61 r = bdb.lookup(["6455550", "6505625"])
62 62 print r["6505625"]["synopsis"]
63 63 """
64 64
65 - VALID_DBS = ["bugster", "illumos"]
65 + VALID_DBS = ["illumos"]
66 66
67 - def __init__(self, priority = ("illumos", "bugster")):
67 + def __init__(self, priority = ["illumos"]):
68 68 """Create a BugDB object.
69 69
70 70 Keyword argument:
71 71 priority: use bug databases in this order
72 72 """
73 73 for database in priority:
74 74 if database not in self.VALID_DBS:
75 75 raise BugDBException, database
76 76 self.__priority = priority
77 77
78 78
79 79 def __illbug(self, cr):
80 80 url = "http://illumos.org/issues/%s.xml" % cr
81 81 req = urllib2.Request(url)
82 82
83 83 try:
84 84 data = urllib2.urlopen(req)
85 85 except urllib2.HTTPError, e:
86 86 if e.code == 404:
87 87 raise NonExistentBug(cr)
88 88 else:
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
89 89 raise
90 90
91 91 bug = ElementTree.parse(data)
92 92
93 93 return {'cr_number': bug.find('id').text,
94 94 'synopsis': bug.find('subject').text,
95 95 'status': bug.find('status').attrib['name']
96 96 }
97 97
98 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 99 def lookup(self, crs):
142 100 """Return all info for requested change reports.
143 101
144 102 Argument:
145 103 crs: one change request id (may be integer, string, or list),
146 104 or multiple change request ids (must be a list)
147 105
148 106 Returns:
149 107 Dictionary, mapping CR=>dictionary, where the nested dictionary
150 108 is a mapping of field=>value
151 109 """
152 110 results = {}
153 111 if not isinstance(crs, list):
154 112 crs = [str(crs)]
155 113 for database in self.__priority:
156 - if database == "bugster":
114 + if database == "illumos":
157 115 for cr in crs:
158 - cr = str(cr)
159 116 try:
160 - results[cr] = self.__boobug(cr)
161 - except NonExistentBug:
162 - continue
163 - elif database == "illumos":
164 - for cr in crs:
165 - try:
166 117 results[str(cr)] = self.__illbug(cr)
167 118 except NonExistentBug:
168 119 continue
169 120
170 121 # the CR has already been found by one bug database
171 122 # so don't bother looking it up in the others
172 123 for cr in crs:
173 124 if cr in results:
174 125 crs.remove(cr)
175 126
176 127 return results
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX