DbLookups.py revision cdf0c1d55d9b3b6beaf994835440dfb01aef5cf0
#
# 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 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# ident "%Z%%M% %I% %E% SMI"
#
#
# * monaco
# * bugs.opensolaris.org (b.o.o.)
# * opensolaris.org/cgi/arc.py (for ARC)
#
import re
import urllib
import htmllib
import os
class BugException(Exception):
class NonExistentBug(BugException):
"""
Query bug database.
Methods:
queryBugs()
expertQuery()
"""
"""Return results of user-supplied bug query.
Argument:
cmd: query to run
Keyword arguments:
format: desired output format (default="Normal+text")
header: include headers in output? (default=False)
Returns:
List of lines representing the output from Monaco
"""
"""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
"""
"area", "release", "build", "responsible_manager",
"responsible_engineer", "priority", "status", "sub_status",
"submitted_by", "date_submitted" ]
cmd = []
results = {}
v = 0
for field in monacoFields:
v += 1
return results
"""Look up a single bug on bugs.opensolaris.org."""
if not m:
continue
raise NonExistentBug(cr)
def submit_date(self):
"""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)
"""
if forceBoo:
else:
"""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
"""
# else we're off-swan and querying via boo, which we can
# only do one bug at a time
results = {}
try:
except NonExistentBug:
continue
return results
####################################################################
"""Lookup an ARC case on opensolaris.org.
Usage:
a = ARC("PSARC", "2008/002")
if a.valid():
print a.name()
"""
q += "&arc0=" + arc
q += "&case0=" + case
if validity != "0":
return
else:
####################################################################
# 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):
# RtiInvalidOutput & RtiCallFailed are our "own" failures
# The other exceptions are triggered from WebRTI itself
class RtiInvalidOutput(RtiException):
class RtiCallFailed(RtiException):
class RtiSystemProblem(RtiException):
class RtiIncorrectCR(RtiException):
class RtiNotFound(RtiException):
class RtiNeedConsolidation(RtiException):
class RtiBadGate(RtiException):
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
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 successfully
if m:
# we got a return code, set it in our
# object, set the webRtiOutput for debugging
# or logging, and return a failure
else:
# there shouldn't be more than one line in
# the output. if we got more than one line,
# then let's be paranoid, and abort.
raise RtiInvalidOutput(data)
# 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
def webRtiOutput(self):
return self.__webRtiOutput