usr/src/tools/onbld/Checks/DbLookups.py
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--
6953156 dblookups should be more robust to app server outage
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7078
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
     1
#! /usr/bin/python
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
     2
#
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
     3
# CDDL HEADER START
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
     4
#
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
     8
#
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    11
# See the License for the specific language governing permissions
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    12
# and limitations under the License.
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    13
#
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    19
#
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    20
# CDDL HEADER END
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    21
#
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    22
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    25
#
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    26
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    27
#
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    28
# Various database lookup classes/methods, i.e.:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    29
#     * monaco
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    33
#
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    36
import re
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    37
import urllib
8042
54a2500a85d8 6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 7764
diff changeset
    38
import urllib2
7078
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    39
import htmllib
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    40
import os
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    41
from socket import socket, AF_INET, SOCK_STREAM
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    42
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    43
from onbld.Checks import onSWAN
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    52
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    53
class BugDB(object):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    54
	"""Lookup change requests.
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    55
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    56
	Object can be used on or off of SWAN, using either monaco or
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    57
	bugs.opensolaris.org as a database.
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    58
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    59
	Usage:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    60
	bdb = BugDB()
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    61
	r = bdb.lookup("6455550")
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    62
	print r["6455550"]["synopsis"]
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    63
	r = bdb.lookup(["6455550", "6505625"])
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    64
	print r["6505625"]["synopsis"]
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    65
	"""
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    68
		"""Create a BugDB object.
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    69
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    70
		Keyword argument:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   205
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   206
	def lookup(self, crs):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   207
		"""Return all info for requested change reports.
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   208
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   209
		Argument:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   210
		crs: one change request id (may be integer, string, or list),
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   211
	             or multiple change request ids (must be a list)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   212
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   213
		Returns:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   214
		Dictionary, mapping CR=>dictionary, where the nested dictionary
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   215
		is a mapping of field=>value
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   216
		"""
8042
54a2500a85d8 6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 7764
diff changeset
   217
		results = {}
7078
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   218
		if not isinstance(crs, list):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   276
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   277
####################################################################
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   278
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   279
# Pointers to the webrti server hostname & port to use
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   280
# Using it directly is probably not *officially* supported, so we'll
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   281
# have a pointer to the official `webrticli` command line interface
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   282
# if using a direct socket connection fails for some reason, so we
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   283
# have a fallback
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   284
WEBRTI_HOST = 'webrti.sfbay.sun.com'
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   287
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   288
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   291
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   292
class RtiCallFailed(RtiException):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   295
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   296
class RtiSystemProblem(RtiException):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   299
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   300
class RtiIncorrectCR(RtiException):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   303
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   304
class RtiNotFound(RtiException):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   307
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   308
class RtiNeedConsolidation(RtiException):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   311
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   312
class RtiBadGate(RtiException):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   319
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   320
class RtiOffSwan(RtiException):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   323
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   324
WEBRTI_ERRORS = {
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   325
	'1': RtiSystemProblem,
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   326
	'2': RtiIncorrectCR,
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   327
	'3': RtiNotFound,
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   328
	'4': RtiNeedConsolidation,
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   329
	'5': RtiBadGate,
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   330
}
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   331
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   332
# Our Rti object which we'll use to represent an Rti query
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   333
# It's really just a wrapper around the Rti connection, and attempts
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   334
# to establish a direct socket connection and query the webrti server
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   335
# directly (thus avoiding a system/fork/exec call).  If it fails, it
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   336
# falls back to the webrticli command line client.
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   337
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   338
returnCodeRe = re.compile(r'.*RETURN_CODE=(\d+)')
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   339
class Rti:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   340
	"""Lookup an RTI.
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   341
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   342
	Usage:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   343
	r = Rti("6640538")
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   344
	print r.rtiNumber();
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   345
	"""
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   346
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   347
	def __init__(self, cr, gate=None, consolidation=None):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   348
		"""Create an Rti object for the specified change request.
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   349
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   350
		Argument:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   351
		cr: change request id
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   352
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   353
		Keyword arguments, to limit scope of RTI search:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   354
		gate: path to gate workspace (default=None)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   355
		consolidation: consolidation name (default=None)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   356
		"""
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   357
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   358
		bufSz = 1024
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   359
		addr = (WEBRTI_HOST, WEBRTI_PORT)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   360
		# If the passed 'cr' was given as an int, then wrap it
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   361
		# into a string to make our life easier
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   362
		if isinstance(cr, int):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   363
			cr = str(cr)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   364
		self.__queryCr = cr
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   365
		self.__queryGate = gate
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   366
		self.__queryConsolidation = consolidation
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   375
		try:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   376
			# try to use a direct connection to the
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   377
			# webrti server first
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   378
			sock = socket(AF_INET, SOCK_STREAM)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   379
			sock.connect(addr)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   380
			command = "WEBRTICLI/1.0\nRTIstatus\n%s\n" % cr
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   381
			if consolidation:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   382
				command += "-c\n%s\n" % consolidation
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   383
			if gate:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   384
				command += "-g\n%s\n" % gate
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   385
			command += "\n"
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   386
			sock.send(command)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   387
			dataList = []
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   388
			# keep receiving data from the socket until the
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   389
			# server closes the connection
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   390
			stillReceiving = True
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   391
			while stillReceiving:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   392
				dataPiece = sock.recv(bufSz)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   393
				if dataPiece:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   394
					dataList.append(dataPiece)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   395
				else:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   396
					stillReceiving = False
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   397
			# create the lines, skipping the first
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   398
			# ("WEBRTCLI/1.0\n")
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   399
			data = '\n'.join(''.join(dataList).split('\n')[1:])
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   400
		except:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   401
			if not onSWAN():
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   402
				raise RtiOffSwan(cr)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   403
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   404
			if not os.path.exists(WEBRTICLI):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   405
				raise RtiCallFailed('not found')
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   406
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   407
			# fallback to the "supported" webrticli interface
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   408
			command = WEBRTICLI
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   409
			if consolidation:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   410
				command += " -c " + consolidation
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   411
			if gate:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   412
				command += " -g " + gate
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   413
			command += " RTIstatus " + cr
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   414
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   415
			try:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   416
				cliPipe = os.popen(command)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   417
			except:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   418
				# we couldn't call the webrticli for some
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   419
				# reason, so return a failure
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   420
				raise RtiCallFailed('unknown')
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   421
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   422
			data = cliPipe.readline()
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   423
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   424
		# parse the data to see if we got a return code
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   427
		m = returnCodeRe.search(data)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   430
			# we got a return code, set it in our
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   431
			# object, set the webRtiOutput for debugging
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   456
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   457
	# accessors in case callers need the raw data
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   458
	def mainCR(self):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   459
		return self.__mainCR
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   460
	def rtiNumber(self):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   461
		return self.__rtiNumber
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   462
	def consolidation(self):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   463
		return self.__consolidation
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   464
	def project(self):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   465
		return self.__project
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   466
	def status(self):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   467
		return self.__status
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   468
	def rtiType(self):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   469
		return self.__rtiType
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   470
	def queryCr(self):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   471
		return self.__queryCr
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   472
	def queryGate(self):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   473
		return self.__queryGate
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   474
	def queryConsolidation(self):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   475
		return self.__queryConsolidation
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   476
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   477
	# in practice, most callers only care about the following
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   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
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   483
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   484
	# for logging/debugging in case the caller wants the raw webrti output
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   485
	def webRtiOutput(self):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   486
		return self.__webRtiOutput
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   487