Chromium Code Reviews| Index: scripts/slave/recipe_modules/buildbucket/api.py |
| diff --git a/scripts/slave/recipe_modules/buildbucket/api.py b/scripts/slave/recipe_modules/buildbucket/api.py |
| index 572a0b7c2407a65729a6048e0b949bf15bf694c9..01cde4b9f0bf623b49084b9d820fd0e6d775baca 100644 |
| --- a/scripts/slave/recipe_modules/buildbucket/api.py |
| +++ b/scripts/slave/recipe_modules/buildbucket/api.py |
| @@ -18,6 +18,10 @@ from recipe_engine import recipe_api |
| class BuildbucketApi(recipe_api.RecipeApi): |
| """A module for interacting with buildbucket.""" |
| + def __init__(self, *args, **kwargs): |
| + super(BuildbucketApi, self).__init__(*args, **kwargs) |
| + self._properties = None |
| + |
| def get_config_defaults(self): |
| if self.m.platform.is_win: |
| return {'PLATFORM': 'win'} |
| @@ -37,9 +41,7 @@ class BuildbucketApi(recipe_api.RecipeApi): |
| self.set_config('production_buildbucket') |
| def _tags_for_build(self, bucket, parameters, override_tags=None): |
| - buildbucket_info = self.m.properties.get('buildbucket', {}) |
| - if isinstance(buildbucket_info, basestring): # pragma: no cover |
| - buildbucket_info = json.loads(buildbucket_info) |
| + buildbucket_info = (self.properties or {}) |
|
Sergey Berezin
2016/09/13 20:55:49
nit: no need for parentheses.
|
| original_tags_list = buildbucket_info.get('build', {}).get('tags', []) |
| original_tags = dict(t.split(':', 1) for t in original_tags_list) |
| @@ -56,6 +58,17 @@ class BuildbucketApi(recipe_api.RecipeApi): |
| new_tags.update(override_tags or {}) |
| return sorted([':'.join((x, y)) for x, y in new_tags.iteritems()]) |
| + @property |
| + def properties(self): |
| + """Returns (dict-like or None): The BuildBucket properties, if present.""" |
| + if self._properties is None: |
| + # Not cached, load and deserialize from properties. |
| + props = self.m.properties.get('buildbucket') |
| + if props is not None: |
| + if isinstance(props, basestring): |
| + props = json.loads(props) |
| + self._properties = props |
| + return self._properties |
| def put(self, builds, service_account=None, **kwargs): |
| """Puts a batch of builds. |