usr/src/tools/onbld/Checks/DbLookups.py
author Ondrej Kubecka <Ondrej.Kubecka@Sun.COM>
Sun, 13 Dec 2009 12:33:10 -0800
changeset 11308 8893db46e5f7
parent 9920 9a117fecafb3
child 12481 f23958781e92
permissions -rw-r--r--
6909211 'opt/onbld/lib/python/onbld/Checks/DbLookups.py' bugster query for 202+ CRs fails
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
#
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
    24
# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
7078
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    25
# Use is subject to license terms.
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
#
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    29
# Various database lookup classes/methods, i.e.:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    30
#     * monaco
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
    31
#     * bugs.opensolaris.org (b.o.o.)
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
    32
#     * arc.opensolaris.org/cgi-bin/arc.cgi (for ARC)
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:
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
   249
		arcPath = "http://arc.opensolaris.org/cgi-bin/arc.cgi"
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
   250
	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
   251
	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
   252
	req = urllib2.Request(arcPath, urllib.urlencode(opts))
8042
54a2500a85d8 6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 7764
diff changeset
   253
	try:
54a2500a85d8 6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 7764
diff changeset
   254
		data = urllib2.urlopen(req).readlines()
54a2500a85d8 6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 7764
diff changeset
   255
	except urllib2.HTTPError, e:
8174
29be171fb93b 6773896 hg pbchk throws exception when webrti disappears
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 8042
diff changeset
   256
		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
   257
			" got error: " + str(e.code)
54a2500a85d8 6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 7764
diff changeset
   258
		raise e
7078
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   259
8042
54a2500a85d8 6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 7764
diff changeset
   260
	except urllib2.URLError, e:
8174
29be171fb93b 6773896 hg pbchk throws exception when webrti disappears
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 8042
diff changeset
   261
		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
   262
			' got error: "' + e.reason[1] + '"'
54a2500a85d8 6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 7764
diff changeset
   263
		raise e
54a2500a85d8 6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 7764
diff changeset
   264
	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
   265
	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
   266
		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
   267
			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
   268
			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
   269
		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
   270
			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
   271
8042
54a2500a85d8 6750617 un-MacGyver BugDB lookups
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 7764
diff changeset
   272
	return ret
7078
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   273
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   274
####################################################################
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   275
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   276
# Pointers to the webrti server hostname & port to use
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   277
# Using it directly is probably not *officially* supported, so we'll
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   278
# have a pointer to the official `webrticli` command line interface
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   279
# 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
   280
# have a fallback
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   281
WEBRTI_HOST = 'webrti.sfbay.sun.com'
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   282
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
   283
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
   284
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   285
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   286
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
   287
	pass
7078
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 RtiCallFailed(RtiException):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   290
	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
   291
		return "Unable to call webrti: %s" % (RtiException.__str__(self))
7078
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   292
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   293
class RtiSystemProblem(RtiException):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   294
	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
   295
		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
   296
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   297
class RtiIncorrectCR(RtiException):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   298
	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
   299
		return "Incorrect CR number specified: %s" % (RtiException.__str__(self))
7078
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   300
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   301
class RtiNotFound(RtiException):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   302
	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
   303
		return "RTI not found for CR: %s" % (RtiException.__str__(self))
7078
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   304
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   305
class RtiNeedConsolidation(RtiException):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   306
	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
   307
		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
   308
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   309
class RtiBadGate(RtiException):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   310
	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
   311
		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
   312
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
   313
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
   314
	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
   315
		return "Unknown webrti return code: %s" % (RtiException.__str__(self))
7078
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   316
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   317
class RtiOffSwan(RtiException):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   318
	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
   319
		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
   320
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   321
WEBRTI_ERRORS = {
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   322
	'1': RtiSystemProblem,
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   323
	'2': RtiIncorrectCR,
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   324
	'3': RtiNotFound,
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   325
	'4': RtiNeedConsolidation,
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   326
	'5': RtiBadGate,
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   327
}
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   328
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   329
# 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
   330
# 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
   331
# to establish a direct socket connection and query the webrti server
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   332
# 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
   333
# falls back to the webrticli command line client.
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   334
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   335
returnCodeRe = re.compile(r'.*RETURN_CODE=(\d+)')
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   336
class Rti:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   337
	"""Lookup an RTI.
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   338
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   339
	Usage:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   340
	r = Rti("6640538")
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   341
	print r.rtiNumber();
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   342
	"""
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   343
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   344
	def __init__(self, cr, gate=None, consolidation=None):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   345
		"""Create an Rti object for the specified change request.
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
		Argument:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   348
		cr: change request id
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
		Keyword arguments, to limit scope of RTI search:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   351
		gate: path to gate workspace (default=None)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   352
		consolidation: consolidation name (default=None)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   353
		"""
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   354
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   355
		bufSz = 1024
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   356
		addr = (WEBRTI_HOST, WEBRTI_PORT)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   357
		# 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
   358
		# into a string to make our life easier
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   359
		if isinstance(cr, int):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   360
			cr = str(cr)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   361
		self.__queryCr = cr
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   362
		self.__queryGate = gate
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   363
		self.__queryConsolidation = consolidation
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   364
7764
06fde484fcce 6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 7711
diff changeset
   365
		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
   366
		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
   367
		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
   368
		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
   369
		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
   370
		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
   371
		self.__rtiType = []
7078
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   372
		try:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   373
			# try to use a direct connection to the
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   374
			# webrti server first
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   375
			sock = socket(AF_INET, SOCK_STREAM)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   376
			sock.connect(addr)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   377
			command = "WEBRTICLI/1.0\nRTIstatus\n%s\n" % cr
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   378
			if consolidation:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   379
				command += "-c\n%s\n" % consolidation
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   380
			if gate:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   381
				command += "-g\n%s\n" % gate
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   382
			command += "\n"
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   383
			sock.send(command)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   384
			dataList = []
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   385
			# keep receiving data from the socket until the
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   386
			# server closes the connection
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   387
			stillReceiving = True
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   388
			while stillReceiving:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   389
				dataPiece = sock.recv(bufSz)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   390
				if dataPiece:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   391
					dataList.append(dataPiece)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   392
				else:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   393
					stillReceiving = False
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   394
			# create the lines, skipping the first
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   395
			# ("WEBRTCLI/1.0\n")
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   396
			data = '\n'.join(''.join(dataList).split('\n')[1:])
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   397
		except:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   398
			if not onSWAN():
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   399
				raise RtiOffSwan(cr)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   400
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   401
			if not os.path.exists(WEBRTICLI):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   402
				raise RtiCallFailed('not found')
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
			# fallback to the "supported" webrticli interface
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   405
			command = WEBRTICLI
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   406
			if consolidation:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   407
				command += " -c " + consolidation
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   408
			if gate:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   409
				command += " -g " + gate
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   410
			command += " RTIstatus " + cr
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   411
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   412
			try:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   413
				cliPipe = os.popen(command)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   414
			except:
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   415
				# we couldn't call the webrticli for some
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   416
				# reason, so return a failure
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   417
				raise RtiCallFailed('unknown')
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   418
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   419
			data = cliPipe.readline()
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   420
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   421
		# parse the data to see if we got a return code
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   422
		# 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
   423
		# then our call was successful
7078
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   424
		m = returnCodeRe.search(data)
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   425
		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
   426
			rc = m.group(1)
7078
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   427
			# we got a return code, set it in our
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   428
			# object, set the webRtiOutput for debugging
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   429
			# 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
   430
			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
   431
				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
   432
				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
   433
					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
   434
				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
   435
					edata = cr
7078
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   436
			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
   437
				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
   438
				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
   439
			raise exc(edata)
7078
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   440
7764
06fde484fcce 6752197 rti check logic could be enhanced to deal with multiple returns
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 7711
diff changeset
   441
		data = data.splitlines()
7078
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   442
		# 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
   443
		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
   444
			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
   445
			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
   446
			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
   447
			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
   448
			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
   449
			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
   450
			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
   451
			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
   452
			self.__rtiType.append(fields[5])
7078
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   453
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   454
	# accessors in case callers need the raw data
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   455
	def mainCR(self):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   456
		return self.__mainCR
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   457
	def rtiNumber(self):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   458
		return self.__rtiNumber
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   459
	def consolidation(self):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   460
		return self.__consolidation
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   461
	def project(self):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   462
		return self.__project
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   463
	def status(self):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   464
		return self.__status
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   465
	def rtiType(self):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   466
		return self.__rtiType
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   467
	def queryCr(self):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   468
		return self.__queryCr
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   469
	def queryGate(self):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   470
		return self.__queryGate
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   471
	def queryConsolidation(self):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   472
		return self.__queryConsolidation
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   473
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   474
	# in practice, most callers only care about the following
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   475
	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
   476
		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
   477
			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
   478
				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
   479
		return True
7078
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   480
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   481
	# 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
   482
	def webRtiOutput(self):
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   483
		return self.__webRtiOutput
935563142864 6538468 add Mercurial support to ON developer tools
mjnelson
parents:
diff changeset
   484