OLD | NEW |
| (Empty) |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 from infra.libs.infra_types import freeze, thaw | |
6 from recipe_engine import recipe_api | |
7 import collections | |
8 | |
9 # Use RecipeApiPlain because collections.Mapping has its own metaclass. | |
10 # Additionally, nothing in this class is a composite_step (nothing in this class | |
11 # is any sort of step :). | |
12 class PropertiesApi(recipe_api.RecipeApiPlain, collections.Mapping): | |
13 """ | |
14 Provide an immutable mapping view into the 'properties' for the current run. | |
15 | |
16 The value of this api is equivalent to this transformation of the legacy | |
17 build values: | |
18 val = factory_properties | |
19 val.update(build_properties) | |
20 """ | |
21 def __init__(self, **kwargs): | |
22 super(PropertiesApi, self).__init__(**kwargs) | |
23 self._properties = freeze(self._engine.properties) | |
24 | |
25 def __getitem__(self, key): | |
26 return self._properties[key] | |
27 | |
28 def __len__(self): | |
29 return len(self._properties) | |
30 | |
31 def __iter__(self): | |
32 return iter(self._properties) | |
33 | |
34 def legacy(self): | |
35 """Returns a reduced set of properties, possibly used by legacy scripts.""" | |
36 | |
37 # Add all properties to this blacklist that are required for testing, but | |
38 # not used by any lecacy scripts, in order to avoid vast expecation | |
39 # changes. | |
40 blacklist = set([ | |
41 'buildbotURL', | |
42 ]) | |
43 return {k: v for k, v in self.iteritems() if k not in blacklist} | |
44 | |
45 def thaw(self): | |
46 """Returns a vanilla python jsonish dictionary of properties.""" | |
47 | |
48 return thaw(self._engine.properties) | |
OLD | NEW |