77 """object to contain state information for API calls. |
85 """object to contain state information for API calls. |
78 |
86 |
79 For example, |
87 For example, |
80 |
88 |
81 api = raptor_api.Context() |
89 api = raptor_api.Context() |
82 val = api.get(X) |
90 val = api.getaliases("X") |
83 """ |
91 """ |
84 def __init__(self, initialiser=None): |
92 def __init__(self, initialiser=None): |
85 # this object has a private Raptor object that can either be |
93 # this object has a private Raptor object that can either be |
86 # passed in or created internally. |
94 # passed in or created internally. |
87 |
95 |
88 if initialiser == None: |
96 if initialiser == None: |
89 self.__raptor = raptor.Raptor() |
97 self.__raptor = raptor.Raptor() |
90 else: |
98 else: |
91 self.__raptor = initialiser |
99 self.__raptor = initialiser |
92 |
100 |
93 def StringQuery(self, query): |
101 def stringquery(self, query): |
94 """turn a string into an API call and execute it. |
102 """turn a string into an API call and execute it. |
95 |
103 |
96 This is a convenience method for "lazy" callers. |
104 This is a convenience method for "lazy" callers. |
97 |
105 |
98 The return value is also converted into a string. |
106 The return value is also converted into a string. |
99 """ |
107 """ |
100 |
108 |
101 if query == "aliases": |
109 if query == "aliases": |
102 aliases = self.GetAliases() |
110 aliases = self.getaliases() |
103 return "".join(map(str, aliases)).strip() |
111 return "".join(map(str, aliases)).strip() |
104 |
112 |
105 elif query == "products": |
113 elif query == "products": |
106 variants = self.GetProducts() |
114 variants = self.getproducts() |
107 return "".join(map(str, variants)).strip() |
115 return "".join(map(str, variants)).strip() |
108 |
116 |
109 elif query.startswith("config"): |
117 elif query.startswith("config"): |
110 match = re.match("config\[(.*)\]", query) |
118 match = re.match("config\[(.*)\]", query) |
111 if match: |
119 if match: |
112 config = self.GetConfig(match.group(1)) |
120 config = self.getconfig(match.group(1)) |
113 return str(config).strip() |
121 return str(config).strip() |
114 else: |
122 else: |
115 raise BadQuery("syntax error") |
123 raise BadQuery("syntax error") |
116 |
124 |
117 raise BadQuery("unknown query") |
125 raise BadQuery("unknown query") |
118 |
126 |
119 def GetAliases(self, type=""): |
127 def getaliases(self, type=""): |
120 """extract all aliases of a given type. |
128 """extract all aliases of a given type. |
121 |
129 |
122 the default type is "". |
130 the default type is "". |
123 to get all aliases pass type=None |
131 to get all aliases pass type=None |
124 """ |
132 """ |
125 aliases = [] |
133 aliases = [] |
126 |
134 |
127 for a in self.__raptor.cache.aliases.values(): |
135 for a in self.__raptor.cache.aliases.values(): |
128 if a.type == type or type == None: |
136 if a.type == type or type == None: |
129 r = Alias() |
|
130 # copy the members we want to expose |
137 # copy the members we want to expose |
131 r.name = a.name |
138 aliases.append( Alias(a.name, a.meaning) ) |
132 r.meaning = a.meaning |
|
133 aliases.append(r) |
|
134 |
139 |
135 return aliases |
140 return aliases |
136 |
141 |
137 def GetConfig(self, name): |
142 def getconfig(self, name): |
138 """extract the values for a given configuration. |
143 """extract the values for a given configuration. |
139 |
144 |
140 'name' should be an alias or variant followed optionally by a |
145 'name' should be an alias or variant followed optionally by a |
141 dot-separated list of variants. For example "armv5_urel" or |
146 dot-separated list of variants. For example "armv5_urel" or |
142 "armv5_urel.savespace.vasco". |
147 "armv5_urel.savespace.vasco". |
189 if not varianttype: |
194 if not varianttype: |
190 raise BadQuery("could not get VARIANTTYPE for config '%s'" % name) |
195 raise BadQuery("could not get VARIANTTYPE for config '%s'" % name) |
191 |
196 |
192 outputpath = str(generic_path.Join(releasepath, variantplatform, varianttype)) |
197 outputpath = str(generic_path.Join(releasepath, variantplatform, varianttype)) |
193 |
198 |
194 r = Config() |
199 return Config(fullname, outputpath) |
195 r.fullname = fullname |
200 |
196 r.outputpath = outputpath |
201 def getproducts(self): |
197 return r |
|
198 |
|
199 def GetProducts(self): |
|
200 """extract all product variants.""" |
202 """extract all product variants.""" |
201 |
203 |
202 variants = [] |
204 variants = [] |
203 |
205 |
204 for v in self.__raptor.cache.variants.values(): |
206 for v in self.__raptor.cache.variants.values(): |
205 if v.type == "product": |
207 if v.type == "product": |
206 r = Product() |
|
207 # copy the members we want to expose |
208 # copy the members we want to expose |
208 r.name = v.name |
209 variants.append( Product(v.name) ) |
209 variants.append(r) |
|
210 |
210 |
211 return variants |
211 return variants |
212 |
212 |
213 class BadQuery(Exception): |
213 class BadQuery(Exception): |
214 pass |
214 pass |