author | Mark J. Nelson <Mark.J.Nelson@Oracle.COM> |
Mon, 24 May 2010 14:32:16 -0600 | |
changeset 12481 | f23958781e92 |
parent 11308 | 8893db46e5f7 |
child 13156 | 9b805b8d713b |
permissions | -rw-r--r-- |
7078 | 1 |
#! /usr/bin/python |
2 |
# |
|
3 |
# CDDL HEADER START |
|
4 |
# |
|
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. |
|
8 |
# |
|
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. |
|
13 |
# |
|
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] |
|
19 |
# |
|
20 |
# CDDL HEADER END |
|
21 |
# |
|
22 |
||
23 |
# |
|
12481
f23958781e92
6953156 dblookups should be more robust to app server outage
Mark J. Nelson <Mark.J.Nelson@Oracle.COM>
parents:
11308
diff
changeset
|
24 |
# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. |
7078 | 25 |
# |
26 |
||
27 |
# |
|
28 |
# Various database lookup classes/methods, i.e.: |
|
29 |
# * monaco |
|
30 |
# * bugs.opensolaris.org (b.o.o.) |
|
12481
f23958781e92
6953156 dblookups should be more robust to app server outage
Mark J. Nelson <Mark.J.Nelson@Oracle.COM>
parents:
11308
diff
changeset
|
31 |
# * arc.opensolaris.org/cgi-bin/arc.cgi (for ARC off SWAN) |
f23958781e92
6953156 dblookups should be more robust to app server outage
Mark J. Nelson <Mark.J.Nelson@Oracle.COM>
parents:
11308
diff
changeset
|
32 |
# * candi.sfbay.sun.com/cgi-bin/arc.cgi (for ARC on SWAN) |
7078 | 33 |
# |
34 |
||
9920
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
35 |
import csv |
7078 | 36 |
import re |
37 |
import urllib |
|
8042
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
38 |
import urllib2 |
7078 | 39 |
import htmllib |
40 |
import os |
|
41 |
from socket import socket, AF_INET, SOCK_STREAM |
|
42 |
||
43 |
from onbld.Checks import onSWAN |
|
44 |
||
9920
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
45 |
class NonExistentBug(Exception): |
7078 | 46 |
def __str__(self): |
9920
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
47 |
return "Bug %s does not exist" % (Exception.__str__(self)) |
7078 | 48 |
|
8042
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
49 |
class BugDBException(Exception): |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
50 |
def __str__(self): |
9920
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
51 |
return "Unknown bug database: %s" % (Exception.__str__(self)) |
7078 | 52 |
|
53 |
class BugDB(object): |
|
54 |
"""Lookup change requests. |
|
55 |
||
56 |
Object can be used on or off of SWAN, using either monaco or |
|
57 |
bugs.opensolaris.org as a database. |
|
58 |
||
59 |
Usage: |
|
60 |
bdb = BugDB() |
|
61 |
r = bdb.lookup("6455550") |
|
62 |
print r["6455550"]["synopsis"] |
|
63 |
r = bdb.lookup(["6455550", "6505625"]) |
|
64 |
print r["6505625"]["synopsis"] |
|
65 |
""" |
|
66 |
||
9920
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
67 |
def __init__(self, priority = ("bugster",), forceBoo=False): |
7078 | 68 |
"""Create a BugDB object. |
69 |
||
70 |
Keyword argument: |
|
71 |
forceBoo: use b.o.o even from SWAN (default=False) |
|
8042
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
72 |
priority: use bug databases in this order |
7078 | 73 |
""" |
8042
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
74 |
self.__validBugDB = ["bugster"] |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
75 |
self.__onSWAN = not forceBoo and onSWAN() |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
76 |
for database in priority: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
77 |
if database not in self.__validBugDB: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
78 |
raise BugDBException, database |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
79 |
self.__priority = priority |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
80 |
|
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
81 |
|
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
82 |
def __boobug(self, cr): |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
83 |
cr = str(cr) |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
84 |
url = "http://bugs.opensolaris.org/view_bug.do" |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
85 |
req = urllib2.Request(url, urllib.urlencode({"bug_id": cr})) |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
86 |
results = {} |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
87 |
try: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
88 |
data = urllib2.urlopen(req).readlines() |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
89 |
except urllib2.HTTPError, e: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
90 |
if e.code != 404: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
91 |
print "ERROR: HTTP error at " + \ |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
92 |
req.get_full_url() + \ |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
93 |
" got error: " + str(e.code) |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
94 |
raise e |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
95 |
else: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
96 |
raise NonExistentBug |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
97 |
except urllib2.URLError, e: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
98 |
print "ERROR: could not connect to " + \ |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
99 |
req.get_full_url() + \ |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
100 |
' got error: "' + e.reason[1] + '"' |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
101 |
raise e |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
102 |
htmlParser = htmllib.HTMLParser(None) |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
103 |
metaHtmlRe = re.compile(r'^<meta name="([^"]+)" content="([^"]*)">$') |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
104 |
for line in data: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
105 |
m = metaHtmlRe.search(line) |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
106 |
if not m: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
107 |
continue |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
108 |
val = urllib.unquote(m.group(2)) |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
109 |
htmlParser.save_bgn() |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
110 |
htmlParser.feed(val) |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
111 |
results[m.group(1)] = htmlParser.save_end() |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
112 |
htmlParser.close() |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
113 |
|
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
114 |
if "synopsis" not in results: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
115 |
raise NonExistentBug(cr) |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
116 |
|
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
117 |
results["cr_number"] = cr |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
118 |
results["sub_category"] = results.pop("subcategory") |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
119 |
results["status"] = results.pop("state") |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
120 |
results["date_submitted"] = results.pop("submit_date") |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
121 |
|
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
122 |
return results |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
123 |
|
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
124 |
|
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
125 |
def __monaco(self, crs): |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
126 |
"""Return all info for requested change reports. |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
127 |
|
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
128 |
Argument: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
129 |
crs: list of change request ids |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
130 |
|
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
131 |
Returns: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
132 |
Dictionary, mapping CR=>dictionary, where the nested dictionary |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
133 |
is a mapping of field=>value |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
134 |
""" |
11308
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
135 |
|
8042
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
136 |
# |
11308
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
137 |
# See if 'maxcrs' for maximal batch query size is defined |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
138 |
# if not, default to 200. |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
139 |
# This clears the 2499 chars query limit |
8042
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
140 |
# |
11308
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
141 |
try: |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
142 |
maxcrs |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
143 |
except NameError: |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
144 |
maxcrs = 200 |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
145 |
|
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
146 |
i = 0 |
8042
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
147 |
results = {} |
11308
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
148 |
data = [] |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
149 |
|
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
150 |
while i < len(crs): |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
151 |
if len(crs) < ( i + maxcrs ): |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
152 |
j = len(crs) |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
153 |
else: |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
154 |
j = i + maxcrs |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
155 |
|
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
156 |
crstmp=crs[i:j] |
8042
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
157 |
|
11308
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
158 |
# |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
159 |
# We request synopsis last, and split on only |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
160 |
# the number of separators that we expect to |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
161 |
# see such that a | in the synopsis doesn't |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
162 |
# throw us out of whack. |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
163 |
# |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
164 |
monacoFields = [ "cr_number", "category", "sub_category", |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
165 |
"area", "release", "build", "responsible_manager", |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
166 |
"responsible_engineer", "priority", "status", "sub_status", |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
167 |
"submitted_by", "date_submitted", "synopsis" ] |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
168 |
cmd = [] |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
169 |
cmd.append("set What = cr." + ', cr.'.join(monacoFields)) |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
170 |
cmd.append("") |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
171 |
cmd.append("set Which = cr.cr_number in (" + ','.join(crstmp) +")") |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
172 |
cmd.append("") |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
173 |
cmd.append("set FinalClauses = order by cr.cr_number") |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
174 |
cmd.append("") |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
175 |
cmd.append("doMeta genQuery cr") |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
176 |
url = "http://hestia.sfbay.sun.com/cgi-bin/expert?format=" |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
177 |
url += "Pipe-delimited+text;Go=2;no_header=on;cmds=" |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
178 |
url += urllib.quote_plus("\n".join(cmd)) |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
179 |
try: |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
180 |
data += urllib2.urlopen(url).readlines() |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
181 |
except urllib2.HTTPError, e: |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
182 |
print "ERROR: HTTP error at " + url + \ |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
183 |
" got error: " + str(e.code) |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
184 |
raise e |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
185 |
|
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
186 |
except urllib2.URLError, e: |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
187 |
print "ERROR: could not connect to " + url + \ |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
188 |
' got error: "' + e.reason[1] + '"' |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
189 |
raise e |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
190 |
|
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
191 |
i += maxcrs |
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
192 |
|
8042
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
193 |
for line in data: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
194 |
line = line.rstrip('\n') |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
195 |
values = line.split('|', len(monacoFields) - 1) |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
196 |
v = 0 |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
197 |
cr = values[0] |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
198 |
results[cr] = {} |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
199 |
for field in monacoFields: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
200 |
results[cr][field] = values[v] |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
201 |
v += 1 |
11308
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
202 |
|
8893db46e5f7
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
parents:
9920
diff
changeset
|
203 |
|
8042
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
204 |
return results |
7078 | 205 |
|
206 |
def lookup(self, crs): |
|
207 |
"""Return all info for requested change reports. |
|
208 |
||
209 |
Argument: |
|
210 |
crs: one change request id (may be integer, string, or list), |
|
211 |
or multiple change request ids (must be a list) |
|
212 |
||
213 |
Returns: |
|
214 |
Dictionary, mapping CR=>dictionary, where the nested dictionary |
|
215 |
is a mapping of field=>value |
|
216 |
""" |
|
8042
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
217 |
results = {} |
7078 | 218 |
if not isinstance(crs, list): |
219 |
crs = [str(crs)] |
|
8042
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
220 |
for database in self.__priority: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
221 |
if database == "bugster": |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
222 |
if self.__onSWAN: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
223 |
results.update(self.__monaco(crs)) |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
224 |
# else we're off-swan and querying via boo, which we can |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
225 |
# only do one bug at a time |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
226 |
else: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
227 |
for cr in crs: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
228 |
cr = str(cr) |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
229 |
try: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
230 |
results[cr] = self.__boobug(cr) |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
231 |
except NonExistentBug: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
232 |
continue |
7078 | 233 |
|
8042
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
234 |
# the CR has already been found by one bug database |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
235 |
# so don't bother looking it up in the others |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
236 |
for cr in crs: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
237 |
if cr in results: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
238 |
crs.remove(cr) |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
239 |
|
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
240 |
return results |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
241 |
#################################################################### |
9920
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
242 |
class ARCException(Exception): |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
243 |
"""This covers arc.cgi script failure.""" |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
244 |
def __str__(self): |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
245 |
return "Error retrieving ARC data: %s" % (Exception.__str__(self)) |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
246 |
|
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
247 |
def ARC(arclist, arcPath=None): |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
248 |
if not arcPath: |
12481
f23958781e92
6953156 dblookups should be more robust to app server outage
Mark J. Nelson <Mark.J.Nelson@Oracle.COM>
parents:
11308
diff
changeset
|
249 |
if onSWAN(): |
f23958781e92
6953156 dblookups should be more robust to app server outage
Mark J. Nelson <Mark.J.Nelson@Oracle.COM>
parents:
11308
diff
changeset
|
250 |
arcPath = "http://candi.sfbay.sun.com/cgi-bin/arc.cgi" |
f23958781e92
6953156 dblookups should be more robust to app server outage
Mark J. Nelson <Mark.J.Nelson@Oracle.COM>
parents:
11308
diff
changeset
|
251 |
else: |
f23958781e92
6953156 dblookups should be more robust to app server outage
Mark J. Nelson <Mark.J.Nelson@Oracle.COM>
parents:
11308
diff
changeset
|
252 |
arcPath = "http://arc.opensolaris.org/cgi-bin/arc.cgi" |
9920
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
253 |
fields = ["present", "arc", "year", "case", "status", "title"] |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
254 |
opts = [("case", "%s/%s" % (a, c)) for a, c in arclist] |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
255 |
req = urllib2.Request(arcPath, urllib.urlencode(opts)) |
8042
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
256 |
try: |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
257 |
data = urllib2.urlopen(req).readlines() |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
258 |
except urllib2.HTTPError, e: |
8174
29be171fb93b
6773896 hg pbchk throws exception when webrti disappears
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
8042
diff
changeset
|
259 |
print "ERROR: HTTP error at " + req.get_full_url() + \ |
8042
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
260 |
" got error: " + str(e.code) |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
261 |
raise e |
7078 | 262 |
|
8042
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
263 |
except urllib2.URLError, e: |
8174
29be171fb93b
6773896 hg pbchk throws exception when webrti disappears
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
8042
diff
changeset
|
264 |
print "ERROR: could not connect to " + req.get_full_url() + \ |
8042
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
265 |
' got error: "' + e.reason[1] + '"' |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
266 |
raise e |
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
267 |
ret = {} |
9920
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
268 |
for line in csv.DictReader(data, fields): |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
269 |
if line["present"] == "exists": |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
270 |
yc = "%s/%s" % (line["year"], line["case"]) |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
271 |
ret[(line["arc"], yc)] = line["title"] |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
272 |
elif line["present"] == "fatal": |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
273 |
raise ARCException(line["arc"]) |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
274 |
|
8042
54a2500a85d8
6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7764
diff
changeset
|
275 |
return ret |
7078 | 276 |
|
277 |
#################################################################### |
|
278 |
||
279 |
# Pointers to the webrti server hostname & port to use |
|
280 |
# Using it directly is probably not *officially* supported, so we'll |
|
281 |
# have a pointer to the official `webrticli` command line interface |
|
282 |
# if using a direct socket connection fails for some reason, so we |
|
283 |
# have a fallback |
|
284 |
WEBRTI_HOST = 'webrti.sfbay.sun.com' |
|
285 |
WEBRTI_PORT = 9188 |
|
7764
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
286 |
WEBRTICLI = '/net/onnv.sfbay.sun.com/export/onnv-gate/public/bin/webrticli' |
7078 | 287 |
|
288 |
||
289 |
class RtiException(Exception): |
|
9920
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
290 |
pass |
7078 | 291 |
|
292 |
class RtiCallFailed(RtiException): |
|
293 |
def __str__(self): |
|
9920
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
294 |
return "Unable to call webrti: %s" % (RtiException.__str__(self)) |
7078 | 295 |
|
296 |
class RtiSystemProblem(RtiException): |
|
297 |
def __str__(self): |
|
9920
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
298 |
return "RTI status cannot be determined for CR: %s" % (RtiException.__str__(self)) |
7078 | 299 |
|
300 |
class RtiIncorrectCR(RtiException): |
|
301 |
def __str__(self): |
|
9920
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
302 |
return "Incorrect CR number specified: %s" % (RtiException.__str__(self)) |
7078 | 303 |
|
304 |
class RtiNotFound(RtiException): |
|
305 |
def __str__(self): |
|
9920
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
306 |
return "RTI not found for CR: %s" % (RtiException.__str__(self)) |
7078 | 307 |
|
308 |
class RtiNeedConsolidation(RtiException): |
|
309 |
def __str__(self): |
|
9920
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
310 |
return "More than one consolidation has this CR: %s" % (RtiException.__str__(self)) |
7078 | 311 |
|
312 |
class RtiBadGate(RtiException): |
|
313 |
def __str__(self): |
|
9920
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
314 |
return "Incorrect gate name specified: %s" % (RtiException.__str__(self)) |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
315 |
|
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
316 |
class RtiUnknownException(Exception): |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
317 |
def __str__(self): |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
318 |
return "Unknown webrti return code: %s" % (RtiException.__str__(self)) |
7078 | 319 |
|
320 |
class RtiOffSwan(RtiException): |
|
321 |
def __str__(self): |
|
9920
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
322 |
return "RTI status checks need SWAN access: %s" % (RtiException.__str__(self)) |
7078 | 323 |
|
324 |
WEBRTI_ERRORS = { |
|
325 |
'1': RtiSystemProblem, |
|
326 |
'2': RtiIncorrectCR, |
|
327 |
'3': RtiNotFound, |
|
328 |
'4': RtiNeedConsolidation, |
|
329 |
'5': RtiBadGate, |
|
330 |
} |
|
331 |
||
332 |
# Our Rti object which we'll use to represent an Rti query |
|
333 |
# It's really just a wrapper around the Rti connection, and attempts |
|
334 |
# to establish a direct socket connection and query the webrti server |
|
335 |
# directly (thus avoiding a system/fork/exec call). If it fails, it |
|
336 |
# falls back to the webrticli command line client. |
|
337 |
||
338 |
returnCodeRe = re.compile(r'.*RETURN_CODE=(\d+)') |
|
339 |
class Rti: |
|
340 |
"""Lookup an RTI. |
|
341 |
||
342 |
Usage: |
|
343 |
r = Rti("6640538") |
|
344 |
print r.rtiNumber(); |
|
345 |
""" |
|
346 |
||
347 |
def __init__(self, cr, gate=None, consolidation=None): |
|
348 |
"""Create an Rti object for the specified change request. |
|
349 |
||
350 |
Argument: |
|
351 |
cr: change request id |
|
352 |
||
353 |
Keyword arguments, to limit scope of RTI search: |
|
354 |
gate: path to gate workspace (default=None) |
|
355 |
consolidation: consolidation name (default=None) |
|
356 |
""" |
|
357 |
||
358 |
bufSz = 1024 |
|
359 |
addr = (WEBRTI_HOST, WEBRTI_PORT) |
|
360 |
# If the passed 'cr' was given as an int, then wrap it |
|
361 |
# into a string to make our life easier |
|
362 |
if isinstance(cr, int): |
|
363 |
cr = str(cr) |
|
364 |
self.__queryCr = cr |
|
365 |
self.__queryGate = gate |
|
366 |
self.__queryConsolidation = consolidation |
|
367 |
||
7764
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
368 |
self.__webRtiOutput = [] |
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
369 |
self.__mainCR = [] |
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
370 |
self.__rtiNumber = [] |
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
371 |
self.__consolidation = [] |
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
372 |
self.__project = [] |
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
373 |
self.__status = [] |
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
374 |
self.__rtiType = [] |
7078 | 375 |
try: |
376 |
# try to use a direct connection to the |
|
377 |
# webrti server first |
|
378 |
sock = socket(AF_INET, SOCK_STREAM) |
|
379 |
sock.connect(addr) |
|
380 |
command = "WEBRTICLI/1.0\nRTIstatus\n%s\n" % cr |
|
381 |
if consolidation: |
|
382 |
command += "-c\n%s\n" % consolidation |
|
383 |
if gate: |
|
384 |
command += "-g\n%s\n" % gate |
|
385 |
command += "\n" |
|
386 |
sock.send(command) |
|
387 |
dataList = [] |
|
388 |
# keep receiving data from the socket until the |
|
389 |
# server closes the connection |
|
390 |
stillReceiving = True |
|
391 |
while stillReceiving: |
|
392 |
dataPiece = sock.recv(bufSz) |
|
393 |
if dataPiece: |
|
394 |
dataList.append(dataPiece) |
|
395 |
else: |
|
396 |
stillReceiving = False |
|
397 |
# create the lines, skipping the first |
|
398 |
# ("WEBRTCLI/1.0\n") |
|
399 |
data = '\n'.join(''.join(dataList).split('\n')[1:]) |
|
400 |
except: |
|
401 |
if not onSWAN(): |
|
402 |
raise RtiOffSwan(cr) |
|
403 |
||
404 |
if not os.path.exists(WEBRTICLI): |
|
405 |
raise RtiCallFailed('not found') |
|
406 |
||
407 |
# fallback to the "supported" webrticli interface |
|
408 |
command = WEBRTICLI |
|
409 |
if consolidation: |
|
410 |
command += " -c " + consolidation |
|
411 |
if gate: |
|
412 |
command += " -g " + gate |
|
413 |
command += " RTIstatus " + cr |
|
414 |
||
415 |
try: |
|
416 |
cliPipe = os.popen(command) |
|
417 |
except: |
|
418 |
# we couldn't call the webrticli for some |
|
419 |
# reason, so return a failure |
|
420 |
raise RtiCallFailed('unknown') |
|
421 |
||
422 |
data = cliPipe.readline() |
|
423 |
||
424 |
# parse the data to see if we got a return code |
|
425 |
# if we did, then that's bad. if we didn't, |
|
9920
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
426 |
# then our call was successful |
7078 | 427 |
m = returnCodeRe.search(data) |
428 |
if m: |
|
9920
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
429 |
rc = m.group(1) |
7078 | 430 |
# we got a return code, set it in our |
431 |
# object, set the webRtiOutput for debugging |
|
432 |
# or logging, and return a failure |
|
9920
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
433 |
if rc in WEBRTI_ERRORS: |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
434 |
exc = WEBRTI_ERRORS[rc] |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
435 |
if exc == RtiBadGate: |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
436 |
edata = gate |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
437 |
else: |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
438 |
edata = cr |
7078 | 439 |
else: |
9920
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
440 |
exc = RtiUnknownException |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
441 |
edata = rc |
9a117fecafb3
6829051 DbLookups.py needs to be updated to use arc.cgi, instead of the recently-EOLed arc.py
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
8174
diff
changeset
|
442 |
raise exc(edata) |
7078 | 443 |
|
7764
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
444 |
data = data.splitlines() |
7078 | 445 |
# At this point, we should have valid data |
7764
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
446 |
for line in data: |
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
447 |
line = line.rstrip('\r\n') |
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
448 |
self.__webRtiOutput.append(line) |
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
449 |
fields = line.split(':') |
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
450 |
self.__mainCR.append(fields[0]) |
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
451 |
self.__rtiNumber.append(fields[1]) |
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
452 |
self.__consolidation.append(fields[2]) |
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
453 |
self.__project.append(fields[3]) |
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
454 |
self.__status.append(fields[4]) |
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
455 |
self.__rtiType.append(fields[5]) |
7078 | 456 |
|
457 |
# accessors in case callers need the raw data |
|
458 |
def mainCR(self): |
|
459 |
return self.__mainCR |
|
460 |
def rtiNumber(self): |
|
461 |
return self.__rtiNumber |
|
462 |
def consolidation(self): |
|
463 |
return self.__consolidation |
|
464 |
def project(self): |
|
465 |
return self.__project |
|
466 |
def status(self): |
|
467 |
return self.__status |
|
468 |
def rtiType(self): |
|
469 |
return self.__rtiType |
|
470 |
def queryCr(self): |
|
471 |
return self.__queryCr |
|
472 |
def queryGate(self): |
|
473 |
return self.__queryGate |
|
474 |
def queryConsolidation(self): |
|
475 |
return self.__queryConsolidation |
|
476 |
||
477 |
# in practice, most callers only care about the following |
|
478 |
def accepted(self): |
|
7764
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
479 |
for status in self.__status: |
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
480 |
if status != "S_ACCEPTED": |
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
481 |
return False |
06fde484fcce
6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents:
7711
diff
changeset
|
482 |
return True |
7078 | 483 |
|
484 |
# for logging/debugging in case the caller wants the raw webrti output |
|
485 |
def webRtiOutput(self): |
|
486 |
return self.__webRtiOutput |
|
487 |