sbsv2/raptor/python/raptor_api.py
author Richard Taylor <richard.i.taylor@nokia.com>
Thu, 29 Apr 2010 09:54:32 +0100
branchwip
changeset 500 69637e02a1ce
parent 499 cad3b96a4fb1
child 503 e182c2a8794d
permissions -rw-r--r--
forgot windows drive letter in test
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
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    22
class Reply(object):
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    23
	"""object to return values from API calls.
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    24
	"""
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    25
	def __init__(self, text=""):
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    26
		self.text = text
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    27
	
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    28
	def __str__(self):
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    29
		name = type(self).__name__.lower()
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    30
		
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    31
		string = "<" + name
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    32
		children = []
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    33
		longend = False
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    34
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    35
		for attribute,value in self.__dict__.items():
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    36
			if attribute != "text":
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    37
				if isinstance(value, Reply):
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    38
					children.append(value)
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    39
				else:
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    40
					string += " %s='%s'" % (attribute, value)
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    41
		
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    42
		if children or self.text:
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    43
			string += ">"
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    44
			longend = True
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    45
		
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    46
		if self.text:
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    47
			string += self.text
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    48
		
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    49
		if children:
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    50
			string += "\n"
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    51
				
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    52
		for c in children:
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    53
			string += str(c)
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    54
			
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    55
		if longend:
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    56
			string += "</%s>\n" % name
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    57
		else:	
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
    58
			string += "/>\n"
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
		return string
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    61
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    62
class Alias(Reply):
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    63
	pass
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    64
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    65
class Config(Reply):
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    66
	pass
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    67
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    68
class Product(Reply):
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    69
	pass
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    70
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    71
import generic_path
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    72
import raptor
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    73
import raptor_data
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    74
import re
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    75
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    76
class Context(object):
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    77
	"""object to contain state information for API calls.
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
	For example,
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    80
	
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    81
	api = raptor_api.Context()
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    82
	val = api.get(X)
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
	def __init__(self, initialiser=None):
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    85
		# 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
    86
		# passed in or created internally.
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    87
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    88
		if initialiser == None:
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    89
			self.__raptor = raptor.Raptor()
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    90
		else:
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    91
			self.__raptor = initialiser
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    92
			
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    93
	def StringQuery(self, query):
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    94
		"""turn a string into an API call and execute it.
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    95
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    96
		This is a convenience method for "lazy" callers.
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    97
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    98
		The return value is also converted into a string.
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
    99
		"""
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 query == "aliases":
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   102
			aliases = self.GetAliases()
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   103
			return "".join(map(str, aliases)).strip()
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   104
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   105
		elif query == "products":
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   106
			variants = self.GetProducts()
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   107
			return "".join(map(str, variants)).strip()
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
		elif query.startswith("config"):
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   110
			match = re.match("config\[(.*)\]", query)
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   111
			if match:
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   112
				config = self.GetConfig(match.group(1))
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   113
				return str(config).strip()
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   114
			else:
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   115
				raise BadQuery("syntax error")
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   116
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   117
		raise BadQuery("unknown query")
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   118
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   119
	def GetAliases(self, type=""):
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   120
		"""extract all aliases of a given type.
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
		the default type is "".
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   123
		to get all aliases pass type=None
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   124
		"""
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   125
		aliases = []
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   126
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   127
		for a in self.__raptor.cache.aliases.values():
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   128
			if a.type == type or type == None:
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   129
				r = Alias()
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   130
				# copy the members we want to expose
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   131
				r.name = a.name
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   132
				r.meaning = a.meaning
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   133
				aliases.append(r)
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
		return aliases
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   136
	
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   137
	def GetConfig(self, name):
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   138
		"""extract the values for a given configuration.
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
		'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
   141
		dot-separated list of variants. For example "armv5_urel" or
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   142
		"armv5_urel.savespace.vasco".
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   143
		"""
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   144
		names = name.split(".")
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   145
		if names[0] in self.__raptor.cache.aliases:
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   146
			x = self.__raptor.cache.FindNamedAlias(names[0])
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   147
			
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   148
			if len(names) > 1:
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   149
				fullname = x.meaning + "." + ".".join(names[1:])
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   150
			else:
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   151
				fullname = x.meaning
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   152
				
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   153
		elif names[0] in self.__raptor.cache.variants:
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   154
			fullname = name
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   155
			
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   156
		else:
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   157
			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
   158
		
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   159
		# create an evaluator for the named configuration
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   160
		tmp = raptor_data.Alias("tmp")
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   161
		tmp.SetProperty("meaning", fullname)
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
		units = tmp.GenerateBuildUnits(self.__raptor.cache)
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   164
		evaluator = self.__raptor.GetEvaluator(None, units[0])
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   165
		
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   166
		# get the outputpath
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   167
		# 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
   168
		# 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
   169
		# conditional logic... but maybe some refactoring could avoid that.
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   170
		releasepath = evaluator.Get("RELEASEPATH")
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   171
		if not releasepath:
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   172
			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
   173
		
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   174
		variantplatform = evaluator.Get("VARIANTPLATFORM")
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   175
		varianttype = evaluator.Get("VARIANTTYPE")
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   176
		featurevariantname = evaluator.Get("FEATUREVARIANTNAME")
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   177
		
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   178
		platform = evaluator.Get("TRADITIONAL_PLATFORM")
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   179
		
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   180
		if platform == "TOOLS2":
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   181
			outputpath = releasepath.replace("$(TOOLPLATFORMDIR)", "")
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   182
		else:
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   183
			if not variantplatform:
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   184
				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
   185
			
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   186
			if featurevariantname:
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   187
				variantplatform += featurevariantname
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   188
				
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   189
			if not varianttype:
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   190
				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
   191
			
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   192
			outputpath = str(generic_path.Join(releasepath, variantplatform, varianttype))
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   193
		
499
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   194
		r = Config()
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   195
		r.fullname = fullname
cad3b96a4fb1 refactoring for --query
Richard Taylor <richard.i.taylor@nokia.com>
parents: 498
diff changeset
   196
		r.outputpath = outputpath
498
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   197
		return r
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   198
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   199
	def GetProducts(self):
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   200
		"""extract all product variants."""
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   201
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   202
		variants = []
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   203
		
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   204
		for v in self.__raptor.cache.variants.values():
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   205
			if v.type == "product":
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   206
				r = Product()
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   207
				# copy the members we want to expose
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   208
				r.name = v.name
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   209
				variants.append(r)
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
		return variants
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   212
	
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   213
class BadQuery(Exception):
564986768b79 add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff changeset
   214
	pass
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
# end of the raptor_api module