DbLookups.py revision 52ddba9904103f8c266a5331f922af7eda83fae1
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# * monaco
# * bugs.opensolaris.org (b.o.o.)
# * arc.opensolaris.org/cgi-bin/arc.cgi (for ARC)
#
import csv
import re
import urllib
import urllib2
import htmllib
import os
class NonExistentBug(Exception):
class BugDBException(Exception):
"""Lookup change requests.
Object can be used on or off of SWAN, using either monaco or
bugs.opensolaris.org as a database.
Usage:
bdb = BugDB()
r = bdb.lookup("6455550")
print r["6455550"]["synopsis"]
r = bdb.lookup(["6455550", "6505625"])
print r["6505625"]["synopsis"]
"""
"""Create a BugDB object.
Keyword argument:
forceBoo: use b.o.o even from SWAN (default=False)
priority: use bug databases in this order
"""
raise BugDBException, database
results = {}
try:
if e.code != 404:
print "ERROR: HTTP error at " + \
req.get_full_url() + \
raise e
else:
raise NonExistentBug
print "ERROR: could not connect to " + \
req.get_full_url() + \
raise e
if not m:
continue
if "synopsis" not in results:
raise NonExistentBug(cr)
return results
"""Return all info for requested change reports.
Argument:
crs: list of change request ids
Returns:
Dictionary, mapping CR=>dictionary, where the nested dictionary
is a mapping of field=>value
"""
#
# See if 'maxcrs' for maximal batch query size is defined
# if not, default to 200.
# This clears the 2499 chars query limit
#
try:
except NameError:
maxcrs = 200
i = 0
results = {}
data = []
else:
j = i + maxcrs
#
# We request synopsis last, and split on only
# the number of separators that we expect to
# see such that a | in the synopsis doesn't
# throw us out of whack.
#
"area", "release", "build", "responsible_manager",
"responsible_engineer", "priority", "status", "sub_status",
"submitted_by", "date_submitted", "synopsis" ]
cmd = []
url += "Pipe-delimited+text;Go=2;no_header=on;cmds="
try:
print "ERROR: HTTP error at " + url + \
raise e
print "ERROR: could not connect to " + url + \
raise e
i += maxcrs
v = 0
for field in monacoFields:
v += 1
return results
"""Return all info for requested change reports.
Argument:
crs: one change request id (may be integer, string, or list),
or multiple change request ids (must be a list)
Returns:
Dictionary, mapping CR=>dictionary, where the nested dictionary
is a mapping of field=>value
"""
results = {}
if database == "bugster":
# else we're off-swan and querying via boo, which we can
# only do one bug at a time
else:
try:
except NonExistentBug:
continue
# the CR has already been found by one bug database
# so don't bother looking it up in the others
return results
####################################################################
class ARCException(Exception):
"""This covers arc.cgi script failure."""
if not arcPath:
try:
raise e
raise e
ret = {}
return ret
####################################################################
# Pointers to the webrti server hostname & port to use
# Using it directly is probably not *officially* supported, so we'll
# have a pointer to the official `webrticli` command line interface
# if using a direct socket connection fails for some reason, so we
# have a fallback
WEBRTI_HOST = 'webrti.sfbay.sun.com'
WEBRTI_PORT = 9188
class RtiException(Exception):
pass
class RtiCallFailed(RtiException):
class RtiSystemProblem(RtiException):
class RtiIncorrectCR(RtiException):
class RtiNotFound(RtiException):
class RtiNeedConsolidation(RtiException):
class RtiBadGate(RtiException):
class RtiUnknownException(Exception):
class RtiOffSwan(RtiException):
WEBRTI_ERRORS = {
'1': RtiSystemProblem,
'2': RtiIncorrectCR,
'3': RtiNotFound,
'4': RtiNeedConsolidation,
'5': RtiBadGate,
}
# Our Rti object which we'll use to represent an Rti query
# It's really just a wrapper around the Rti connection, and attempts
# to establish a direct socket connection and query the webrti server
# falls back to the webrticli command line client.
class Rti:
"""Lookup an RTI.
Usage:
r = Rti("6640538")
print r.rtiNumber();
"""
"""Create an Rti object for the specified change request.
Argument:
cr: change request id
Keyword arguments, to limit scope of RTI search:
gate: path to gate workspace (default=None)
consolidation: consolidation name (default=None)
"""
bufSz = 1024
# If the passed 'cr' was given as an int, then wrap it
# into a string to make our life easier
self.__webRtiOutput = []
self.__rtiNumber = []
self.__consolidation = []
try:
# try to use a direct connection to the
# webrti server first
if consolidation:
if gate:
command += "\n"
dataList = []
# keep receiving data from the socket until the
# server closes the connection
while stillReceiving:
if dataPiece:
else:
# create the lines, skipping the first
# ("WEBRTCLI/1.0\n")
except:
if not onSWAN():
raise RtiOffSwan(cr)
raise RtiCallFailed('not found')
# fallback to the "supported" webrticli interface
if consolidation:
if gate:
try:
except:
# we couldn't call the webrticli for some
# reason, so return a failure
raise RtiCallFailed('unknown')
# parse the data to see if we got a return code
# if we did, then that's bad. if we didn't,
# then our call was successful
if m:
# we got a return code, set it in our
# object, set the webRtiOutput for debugging
# or logging, and return a failure
if rc in WEBRTI_ERRORS:
if exc == RtiBadGate:
else:
else:
# At this point, we should have valid data
# accessors in case callers need the raw data
return self.__rtiNumber
def consolidation(self):
return self.__consolidation
return self.__queryGate
def queryConsolidation(self):
return self.__queryConsolidation
# in practice, most callers only care about the following
if status != "S_ACCEPTED":
return False
return True
def webRtiOutput(self):
return self.__webRtiOutput