author | Ross Qin <ross.qin@nokia.com> |
Tue, 30 Nov 2010 14:05:41 +0800 | |
changeset 713 | 7b7f0409fc00 |
parent 625 | a1925fb7753a |
permissions | -rw-r--r-- |
591 | 1 |
# |
2 |
# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
# All rights reserved. |
|
4 |
# This component and the accompanying materials are made available |
|
5 |
# under the terms of the License "Eclipse Public License v1.0" |
|
6 |
# which accompanies this distribution, and is available |
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
# |
|
9 |
# Initial Contributors: |
|
10 |
# Nokia Corporation - initial contribution. |
|
11 |
# |
|
12 |
# Contributors: |
|
13 |
# |
|
14 |
# Description: |
|
15 |
# |
|
16 |
# raptor_api module |
|
17 |
# |
|
18 |
# Python API for Raptor. External code should interact with Raptor via this |
|
19 |
# module only, as it is the only programatic interface considered public. The |
|
20 |
# command line --query option is also implemented using this module. |
|
21 |
||
22 |
# constants |
|
23 |
ALL = 1 |
|
24 |
||
25 |
# objects |
|
26 |
||
27 |
class Reply(object): |
|
28 |
"""object to return values from API calls. |
|
29 |
""" |
|
625
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
30 |
def __init__(self, text="", raptor=None): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
31 |
self._raptor = raptor |
591 | 32 |
self.text = text |
625
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
33 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
34 |
def _getEvaluator(self, meaning): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
35 |
""" Note: Will pass on Evaluator constructor exceptions """ |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
36 |
try: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
37 |
return self.__evaluator |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
38 |
except AttributeError: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
39 |
# create an evaluator for the named configuration |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
40 |
tmp = raptor_data.Alias("tmp") |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
41 |
tmp.SetProperty("meaning", meaning) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
42 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
43 |
units = tmp.GenerateBuildUnits(self._raptor.cache) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
44 |
self.__evaluator = self._raptor.GetEvaluator(None, units[0]) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
45 |
return self.__evaluator |
591 | 46 |
|
47 |
def __str__(self): |
|
48 |
name = type(self).__name__.lower() |
|
49 |
||
50 |
string = "<" + name |
|
51 |
children = [] |
|
52 |
longend = False |
|
53 |
||
54 |
for attribute,value in self.__dict__.items(): |
|
625
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
55 |
if attribute != "text" and not attribute.startswith('_'): |
591 | 56 |
if isinstance(value, Reply): |
57 |
children.append(value) |
|
625
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
58 |
elif isinstance(value, list): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
59 |
for item in value: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
60 |
if isinstance(item, Reply): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
61 |
children.append(item) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
62 |
else: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
63 |
raise BadReply(str(item)+" is not a Reply object") |
591 | 64 |
else: |
625
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
65 |
if value != None: # skip attributes whose value is None |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
66 |
string += " %s='%s'" % (attribute, value) |
591 | 67 |
|
68 |
if children or self.text: |
|
69 |
string += ">" |
|
70 |
longend = True |
|
71 |
||
72 |
if self.text: |
|
73 |
string += self.text |
|
625
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
74 |
children.sort() |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
75 |
# Note mixing sortable and unsortable lists results in |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
76 |
# sort not working, so if you really need your |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
77 |
# children to come out in the right order, put them in |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
78 |
# a list. This is only for niceness, where it works. |
591 | 79 |
|
80 |
if children: |
|
81 |
string += "\n" |
|
82 |
||
625
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
83 |
for c in children: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
84 |
clines = str(c).rstrip().split("\n") |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
85 |
string += "".join(map(lambda l:" "+l+"\n",clines)) |
591 | 86 |
|
87 |
if longend: |
|
88 |
string += "</%s>\n" % name |
|
89 |
else: |
|
90 |
string += "/>\n" |
|
91 |
||
92 |
return string |
|
93 |
||
625
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
94 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
95 |
class BadReply(Exception): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
96 |
pass |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
97 |
|
591 | 98 |
class Alias(Reply): |
99 |
def __init__(self, name, meaning): |
|
100 |
super(Alias,self).__init__() |
|
101 |
self.name = name |
|
102 |
self.meaning = meaning |
|
625
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
103 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
104 |
def __cmp__(self, other): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
105 |
""" Add __cmp__ to enable comparisons between two Alias objects based upon name.""" |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
106 |
return cmp(self.name, other.name) |
591 | 107 |
|
108 |
class Config(Reply): |
|
625
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
109 |
def __init__(self, raptor, name, text = None): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
110 |
""" Constructor to create a Config from a user-supplied name. |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
111 |
possibly including aliases (but not groups) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
112 |
""" |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
113 |
super(Config,self).__init__(text, raptor) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
114 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
115 |
self.query = name |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
116 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
117 |
# Work out the real name |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
118 |
names = name.split(".") |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
119 |
if names[0] in self._raptor.cache.aliases: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
120 |
x = self._raptor.cache.FindNamedAlias(names[0]) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
121 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
122 |
if len(names) > 1: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
123 |
self.meaning = x.meaning + "." + ".".join(names[1:]) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
124 |
else: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
125 |
self.meaning = x.meaning |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
126 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
127 |
elif names[0] in self._raptor.cache.variants: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
128 |
self.meaning = name |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
129 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
130 |
else: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
131 |
raise BadQuery("'%s' is not an alias or a variant" % names[0]) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
132 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
133 |
def resolveOutputPath(self): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
134 |
""" Get the outputpath """ |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
135 |
try: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
136 |
evaluator = self._getEvaluator(self.meaning) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
137 |
# This is messy as some configs construct the path inside the FLM |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
138 |
# rather than talking it from the XML: usually because of some |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
139 |
# conditional logic... but maybe some refactoring could avoid that. |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
140 |
releasepath = evaluator.Get("RELEASEPATH") |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
141 |
if not releasepath: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
142 |
raise BadQuery("could not get RELEASEPATH for config '%s'" % self.fullname) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
143 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
144 |
variantplatform = evaluator.Get("VARIANTPLATFORM") |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
145 |
varianttype = evaluator.Get("VARIANTTYPE") |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
146 |
featurevariantname = evaluator.Get("FEATUREVARIANTNAME") |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
147 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
148 |
platform = evaluator.Get("TRADITIONAL_PLATFORM") |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
149 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
150 |
if platform == "TOOLS2": |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
151 |
self.outputpath = releasepath |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
152 |
else: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
153 |
if not variantplatform: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
154 |
raise BadQuery("could not get VARIANTPLATFORM for config '%s'" % self.fullname) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
155 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
156 |
if featurevariantname: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
157 |
variantplatform += featurevariantname |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
158 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
159 |
if not varianttype: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
160 |
raise BadQuery("could not get VARIANTTYPE for config '%s'" % self.fullname) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
161 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
162 |
self.outputpath = str(generic_path.Join(releasepath, variantplatform, varianttype)) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
163 |
except Exception, e: # Unable to determine output path |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
164 |
self.text = str(e) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
165 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
166 |
def resolveMetadata(self): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
167 |
try: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
168 |
metadata = self.metadata |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
169 |
except AttributeError: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
170 |
metadata = MetaData(self.meaning, self._raptor) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
171 |
self.metadata = metadata |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
172 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
173 |
try: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
174 |
metadata.resolve() |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
175 |
except Exception: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
176 |
# Evaluator exception hopefully - already handled |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
177 |
self.metadata = None |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
178 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
179 |
def resolveBuild(self): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
180 |
try: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
181 |
build = self.build |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
182 |
except AttributeError: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
183 |
build = Build(self.meaning, self._raptor) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
184 |
self.build = build |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
185 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
186 |
try: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
187 |
build.resolve() |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
188 |
except Exception: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
189 |
# Evaluator exception, hopefully - already handled |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
190 |
self.build = None |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
191 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
192 |
def resolveTargettypes(self): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
193 |
try: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
194 |
build = self.build |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
195 |
except AttributeError: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
196 |
build = Build(self.meaning, self._raptor) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
197 |
self.build = build |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
198 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
199 |
try: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
200 |
build.resolveTargettypes() |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
201 |
except Exception: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
202 |
# Evaluator exception hopefully - already handled |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
203 |
self.build = None |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
204 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
205 |
class MetaData(Reply): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
206 |
def __init__(self, meaning, raptor): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
207 |
super(MetaData,self).__init__("", raptor) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
208 |
self.__meaning = meaning |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
209 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
210 |
def resolve(self): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
211 |
includepaths = [] |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
212 |
preincludeheader = "" |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
213 |
platmacros = [] |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
214 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
215 |
evaluator = self._getEvaluator(self.__meaning) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
216 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
217 |
# Initialise data and metadata objects |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
218 |
buildunits = raptor_data.GetBuildUnits([self.__meaning], self._raptor.cache, self._raptor) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
219 |
metareader = raptor_meta.MetaReader(self._raptor, buildunits) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
220 |
metadatafile = raptor_meta.MetaDataFile(generic_path.Path("bld.inf"), "cpp", [], None, self._raptor) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
221 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
222 |
# There is only one build platform here; obtain the pre-processing include paths, |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
223 |
# OS pre-include file, compiler pre-include file and macros. |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
224 |
includepaths = metadatafile.preparePreProcessorIncludePaths(metareader.BuildPlatforms[0]) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
225 |
preincludeheader = metareader.BuildPlatforms[0]['VARIANT_HRH'] |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
226 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
227 |
# Macros arrive as a a list of strings, or a single string, containing definitions of the form "name" or "name=value". |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
228 |
platmacrolist = metadatafile.preparePreProcessorMacros(metareader.BuildPlatforms[0]) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
229 |
platmacros.extend(map(lambda macrodef: [macrodef.partition("=")[0], macrodef.partition("=")[2]], platmacrolist)) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
230 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
231 |
# Add child elements to appropriate areas if they were calculated |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
232 |
if len(includepaths) > 0: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
233 |
self.includepaths = map(lambda x: Include(str(x)), includepaths) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
234 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
235 |
if preincludeheader != "": |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
236 |
self.preincludeheader = PreInclude(str(preincludeheader)) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
237 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
238 |
if len(platmacros): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
239 |
self.platmacros = map(lambda x: Macro(x[0],x[1]) if x[1] else Macro(x[0]), platmacros) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
240 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
241 |
class Build(Reply): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
242 |
def __init__(self, meaning, raptor): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
243 |
super(Build,self).__init__("", raptor) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
244 |
self.__meaning = meaning |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
245 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
246 |
def resolve(self): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
247 |
compilerpreincludeheader = "" |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
248 |
sourcemacros = [] |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
249 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
250 |
evaluator = self._getEvaluator(self.__meaning) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
251 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
252 |
platform = evaluator.Get("TRADITIONAL_PLATFORM") |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
253 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
254 |
# Compiler preinclude files may or may not be present, depending on the configuration. |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
255 |
if evaluator.Get("PREINCLUDE"): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
256 |
compilerpreincludeheader = generic_path.Path(evaluator.Get("PREINCLUDE")) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
257 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
258 |
# Macros arrive as a a list of strings, or a single string, containing definitions of the form "name" or "name=value". |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
259 |
# If required, we split to a list, and then processes the constituent parts of the macro. |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
260 |
sourcemacrolist = evaluator.Get("CDEFS").split() |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
261 |
sourcemacros.extend(map(lambda macrodef: [macrodef.partition("=")[0], macrodef.partition("=")[2]], sourcemacrolist)) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
262 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
263 |
if platform == "TOOLS2": |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
264 |
# Source macros are determined in the FLM for tools2 builds, therefore we have to |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
265 |
# mimic the logic here |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
266 |
if 'win' in raptor.hostplatform or 'win32' in self.__meaning: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
267 |
sourcemacrolist = evaluator.Get("CDEFS.WIN32").split() |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
268 |
else: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
269 |
sourcemacrolist = evaluator.Get("CDEFS.LINUX").split() |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
270 |
sourcemacros.extend(map(lambda macrodef: [macrodef.partition("=")[0], macrodef.partition("=")[2]], sourcemacrolist)) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
271 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
272 |
if len(sourcemacros): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
273 |
self.sourcemacros = map(lambda x: Macro(x[0],x[1]) if x[1] else Macro(x[0]), sourcemacros) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
274 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
275 |
if compilerpreincludeheader: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
276 |
self.compilerpreincludeheader = PreInclude(str(compilerpreincludeheader)) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
277 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
278 |
def resolveTargettypes(self): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
279 |
evaluator = self._getEvaluator(self.__meaning) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
280 |
targettypes = evaluator.Get("TARGET_TYPES").split(' ') |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
281 |
self.targettypes = [] |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
282 |
for type in targettypes: |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
283 |
self.targettypes.append(TargetType(type)) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
284 |
self.targettypes.sort() |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
285 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
286 |
class TargetType(Reply): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
287 |
def __init__(self, name): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
288 |
super(TargetType,self).__init__() |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
289 |
self.name = name |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
290 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
291 |
def __cmp__(self, other): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
292 |
return cmp(self.name, other.name) |
591 | 293 |
|
294 |
class Product(Reply): |
|
295 |
def __init__(self, name): |
|
296 |
super(Product,self).__init__() |
|
297 |
self.name = name |
|
625
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
298 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
299 |
def __cmp__(self, other): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
300 |
""" Add __cmp__ to enable comparisons between two Product objects based upon name.""" |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
301 |
return cmp(self.name, other.name) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
302 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
303 |
class Include(Reply): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
304 |
def __init__(self, path): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
305 |
super(Include,self).__init__() |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
306 |
self.path = path |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
307 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
308 |
class PreInclude(Reply): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
309 |
def __init__(self, file): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
310 |
super(PreInclude,self).__init__() |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
311 |
self.file = file |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
312 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
313 |
class Macro(Reply): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
314 |
def __init__(self, name, value=None): |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
315 |
super(Macro,self).__init__() |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
316 |
self.name = name |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
317 |
self.value = value |
591 | 318 |
|
319 |
import generic_path |
|
320 |
import raptor |
|
321 |
import raptor_data |
|
625
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
322 |
import raptor_meta |
591 | 323 |
import re |
324 |
||
325 |
class Context(object): |
|
326 |
"""object to contain state information for API calls. |
|
327 |
||
328 |
For example, |
|
329 |
||
330 |
api = raptor_api.Context() |
|
331 |
val = api.getaliases("X") |
|
332 |
""" |
|
333 |
def __init__(self, initialiser=None): |
|
334 |
# this object has a private Raptor object that can either be |
|
335 |
# passed in or created internally. |
|
336 |
||
337 |
if initialiser == None: |
|
338 |
self.__raptor = raptor.Raptor() |
|
339 |
else: |
|
340 |
self.__raptor = initialiser |
|
341 |
||
342 |
def stringquery(self, query): |
|
343 |
"""turn a string into an API call and execute it. |
|
344 |
||
345 |
This is a convenience method for "lazy" callers. |
|
346 |
||
347 |
The return value is also converted into a well-formed XML string. |
|
348 |
""" |
|
349 |
||
350 |
if query == "aliases": |
|
351 |
aliases = self.getaliases() |
|
352 |
return "".join(map(str, aliases)).strip() |
|
353 |
||
354 |
elif query == "products": |
|
355 |
variants = self.getproducts() |
|
356 |
return "".join(map(str, variants)).strip() |
|
357 |
||
358 |
elif query.startswith("config"): |
|
359 |
match = re.match("config\[(.*)\]", query) |
|
360 |
if match: |
|
361 |
config = self.getconfig(match.group(1)) |
|
362 |
return str(config).strip() |
|
363 |
else: |
|
364 |
raise BadQuery("syntax error") |
|
365 |
||
366 |
raise BadQuery("unknown query") |
|
367 |
||
368 |
def getaliases(self, type=""): |
|
369 |
"""extract all aliases of a given type. |
|
370 |
||
371 |
the default type is "". |
|
372 |
to get all aliases pass type=ALL |
|
373 |
""" |
|
374 |
aliases = [] |
|
375 |
||
376 |
for a in self.__raptor.cache.aliases.values(): |
|
377 |
if type == ALL or a.type == type: |
|
378 |
# copy the members we want to expose |
|
379 |
aliases.append( Alias(a.name, a.meaning) ) |
|
625
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
380 |
aliases.sort() |
591 | 381 |
return aliases |
382 |
||
383 |
def getconfig(self, name): |
|
384 |
"""extract the values for a given configuration. |
|
385 |
||
386 |
'name' should be an alias or variant followed optionally by a |
|
387 |
dot-separated list of variants. For example "armv5_urel" or |
|
388 |
"armv5_urel.savespace.vasco". |
|
389 |
""" |
|
625
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
390 |
|
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
391 |
config = Config(self.__raptor, name) |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
392 |
config.resolveOutputPath() |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
393 |
config.resolveTargettypes() |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
394 |
config.resolveMetadata() |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
395 |
config.resolveBuild() |
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
396 |
return config |
591 | 397 |
|
398 |
def getproducts(self): |
|
399 |
"""extract all product variants.""" |
|
400 |
||
401 |
variants = [] |
|
402 |
||
403 |
for v in self.__raptor.cache.variants.values(): |
|
404 |
if v.type == "product": |
|
405 |
# copy the members we want to expose |
|
406 |
variants.append( Product(v.name) ) |
|
625
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
407 |
variants.sort() |
591 | 408 |
return variants |
409 |
||
410 |
class BadQuery(Exception): |
|
411 |
pass |
|
412 |
||
413 |
# end of the raptor_api module |