sbsv2/raptor/python/raptor_api.py
author timothy.murphy@nokia.com
Tue, 18 May 2010 22:13:09 +0100
branchfix
changeset 567 d420c77a7248
parent 507 54a88b895bcd
permissions -rw-r--r--
release note and review comment tidyup for tcom speedup
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
     1
#
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
     2
# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
     3
# All rights reserved.
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
     4
# This component and the accompanying materials are made available
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
     6
# which accompanies this distribution, and is available
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
     8
#
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
     9
# Initial Contributors:
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    11
#
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    12
# Contributors:
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    13
#
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    14
# Description: 
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    15
#
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    16
# raptor_api module
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    17
#
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    18
# Python API for Raptor. External code should interact with Raptor via this
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    19
# module only, as it is the only programatic interface considered public. The
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    20
# command line --query option is also implemented using this module.
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    21
507
54a88b895bcd apply review comments
Richard Taylor <richard.i.taylor@nokia.com>
parents: 504
diff changeset
    22
# constants
54a88b895bcd apply review comments
Richard Taylor <richard.i.taylor@nokia.com>
parents: 504
diff changeset
    23
ALL = 1
54a88b895bcd apply review comments
Richard Taylor <richard.i.taylor@nokia.com>
parents: 504
diff changeset
    24
54a88b895bcd apply review comments
Richard Taylor <richard.i.taylor@nokia.com>
parents: 504
diff changeset
    25
# objects
54a88b895bcd apply review comments
Richard Taylor <richard.i.taylor@nokia.com>
parents: 504
diff changeset
    26
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    27
class Reply(object):
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    28
	"""object to return values from API calls.
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    29
	"""
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    30
	def __init__(self, text=""):
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    31
		self.text = text
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    32
	
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    33
	def __str__(self):
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    34
		name = type(self).__name__.lower()
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    35
		
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    36
		string = "<" + name
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    37
		children = []
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    38
		longend = False
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    39
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    40
		for attribute,value in self.__dict__.items():
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    41
			if attribute != "text":
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    42
				if isinstance(value, Reply):
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    43
					children.append(value)
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    44
				else:
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    45
					string += " %s='%s'" % (attribute, value)
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    46
		
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    47
		if children or self.text:
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    48
			string += ">"
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    49
			longend = True
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    50
		
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    51
		if self.text:
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    52
			string += self.text
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    53
		
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    54
		if children:
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    55
			string += "\n"
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    56
				
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    57
		for c in children:
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    58
			string += str(c)
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    59
			
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    60
		if longend:
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    61
			string += "</%s>\n" % name
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    62
		else:	
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    63
			string += "/>\n"
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    64
		
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    65
		return string
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    66
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    67
class Alias(Reply):
504
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
    68
	def __init__(self, name, meaning):
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
    69
		super(Alias,self).__init__()
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
    70
		self.name = name
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
    71
		self.meaning = meaning
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    72
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    73
class Config(Reply):
504
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
    74
	def __init__(self, fullname, outputpath):
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
    75
		super(Config,self).__init__()
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
    76
		self.fullname = fullname
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
    77
		self.outputpath = outputpath
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    78
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    79
class Product(Reply):
504
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
    80
	def __init__(self, name):
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
    81
		super(Product,self).__init__()
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
    82
		self.name = name
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    83
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    84
import generic_path
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    85
import raptor
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    86
import raptor_data
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    87
import re
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    88
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    89
class Context(object):
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    90
	"""object to contain state information for API calls.
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    91
	
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    92
	For example,
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    93
	
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    94
	api = raptor_api.Context()
504
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
    95
	val = api.getaliases("X")
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    96
	"""
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    97
	def __init__(self, initialiser=None):
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    98
		# this object has a private Raptor object that can either be
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    99
		# passed in or created internally.
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   100
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   101
		if initialiser == None:
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   102
			self.__raptor = raptor.Raptor()
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   103
		else:
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   104
			self.__raptor = initialiser
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   105
			
504
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
   106
	def stringquery(self, query):
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   107
		"""turn a string into an API call and execute it.
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   108
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   109
		This is a convenience method for "lazy" callers.
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   110
		
507
54a88b895bcd apply review comments
Richard Taylor <richard.i.taylor@nokia.com>
parents: 504
diff changeset
   111
		The return value is also converted into a well-formed XML string.
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   112
		"""
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   113
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   114
		if query == "aliases":
504
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
   115
			aliases = self.getaliases()
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   116
			return "".join(map(str, aliases)).strip()
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   117
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   118
		elif query == "products":
504
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
   119
			variants = self.getproducts()
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   120
			return "".join(map(str, variants)).strip()
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   121
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   122
		elif query.startswith("config"):
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   123
			match = re.match("config\[(.*)\]", query)
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   124
			if match:
504
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
   125
				config = self.getconfig(match.group(1))
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   126
				return str(config).strip()
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   127
			else:
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   128
				raise BadQuery("syntax error")
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   129
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   130
		raise BadQuery("unknown query")
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   131
504
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
   132
	def getaliases(self, type=""):
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   133
		"""extract all aliases of a given type.
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   134
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   135
		the default type is "".
507
54a88b895bcd apply review comments
Richard Taylor <richard.i.taylor@nokia.com>
parents: 504
diff changeset
   136
		to get all aliases pass type=ALL
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   137
		"""
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   138
		aliases = []
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   139
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   140
		for a in self.__raptor.cache.aliases.values():
507
54a88b895bcd apply review comments
Richard Taylor <richard.i.taylor@nokia.com>
parents: 504
diff changeset
   141
			if type == ALL or a.type == type:
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   142
				# copy the members we want to expose
504
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
   143
				aliases.append( Alias(a.name, a.meaning) )
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   144
			
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   145
		return aliases
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   146
	
504
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
   147
	def getconfig(self, name):
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   148
		"""extract the values for a given configuration.
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   149
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   150
		'name' should be an alias or variant followed optionally by a
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   151
		dot-separated list of variants. For example "armv5_urel" or
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   152
		"armv5_urel.savespace.vasco".
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   153
		"""
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   154
		names = name.split(".")
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   155
		if names[0] in self.__raptor.cache.aliases:
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   156
			x = self.__raptor.cache.FindNamedAlias(names[0])
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   157
			
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   158
			if len(names) > 1:
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   159
				fullname = x.meaning + "." + ".".join(names[1:])
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   160
			else:
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   161
				fullname = x.meaning
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   162
				
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   163
		elif names[0] in self.__raptor.cache.variants:
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   164
			fullname = name
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   165
			
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   166
		else:
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   167
			raise BadQuery("'%s' is not an alias or a variant" % names[0])
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   168
		
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   169
		# create an evaluator for the named configuration
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   170
		tmp = raptor_data.Alias("tmp")
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   171
		tmp.SetProperty("meaning", fullname)
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   172
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   173
		units = tmp.GenerateBuildUnits(self.__raptor.cache)
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   174
		evaluator = self.__raptor.GetEvaluator(None, units[0])
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   175
		
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   176
		# get the outputpath
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   177
		# this is messy as some configs construct the path inside the FLM
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   178
		# rather than talking it from the XML: usually because of some
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   179
		# conditional logic... but maybe some refactoring could avoid that.
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   180
		releasepath = evaluator.Get("RELEASEPATH")
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   181
		if not releasepath:
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   182
			raise BadQuery("could not get RELEASEPATH for config '%s'" % name)
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   183
		
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   184
		variantplatform = evaluator.Get("VARIANTPLATFORM")
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   185
		varianttype = evaluator.Get("VARIANTTYPE")
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   186
		featurevariantname = evaluator.Get("FEATUREVARIANTNAME")
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   187
		
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   188
		platform = evaluator.Get("TRADITIONAL_PLATFORM")
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   189
		
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   190
		if platform == "TOOLS2":
503
e182c2a8794d missed a file
Richard Taylor <richard.i.taylor@nokia.com>
parents: 499
diff changeset
   191
			outputpath = releasepath
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   192
		else:
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   193
			if not variantplatform:
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   194
				raise BadQuery("could not get VARIANTPLATFORM for config '%s'" % name)
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   195
			
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   196
			if featurevariantname:
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   197
				variantplatform += featurevariantname
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   198
				
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   199
			if not varianttype:
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   200
				raise BadQuery("could not get VARIANTTYPE for config '%s'" % name)
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   201
			
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   202
			outputpath = str(generic_path.Join(releasepath, variantplatform, varianttype))
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   203
		
504
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
   204
		return Config(fullname, outputpath)
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   205
		
504
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
   206
	def getproducts(self):
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   207
		"""extract all product variants."""
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   208
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   209
		variants = []
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   210
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   211
		for v in self.__raptor.cache.variants.values():
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   212
			if v.type == "product":
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   213
				# copy the members we want to expose
504
ea75c3a64a17 change to lowercase method names
Richard Taylor <richard.i.taylor@nokia.com>
parents: 503
diff changeset
   214
				variants.append( Product(v.name) )
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   215
			
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   216
		return variants
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   217
	
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   218
class BadQuery(Exception):
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   219
	pass
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   220
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   221
# end of the raptor_api module