Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(958)

Side by Side Diff: scripts/slave/recipe_modules/step_history/api.py

Issue 187203005: Minor cleanup of some recipe framework code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Rietveld >_< Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « scripts/slave/recipe_modules/step/api.py ('k') | scripts/slave/recipe_test_api.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import collections 5 import collections
6 6
7 from slave import recipe_api 7 from slave import recipe_api
8 8
9 class StepHistoryApi(recipe_api.RecipeApi, collections.Mapping): 9 class StepHistoryApi(recipe_api.RecipeApi, collections.Mapping):
10 """ 10 """
11 Provide an OrderedDict-like view into the steps that have run, and what 11 Provide an OrderedDict-like view into the steps that have run, and what
12 data they've returned. 12 data they've returned.
13 13
14 Each entry in step_history is an object() which has the attributes: 14 Each entry in step_history is an object() which has the attributes:
15 * retcode 15 * retcode
16 * <module_name>.<module_specific_data> 16 * <module_name>.<module_specific_data>
17 """ 17 """
18 18
19 def __init__(self, step_history, **kwargs): 19 def __init__(self, step_history, **kwargs):
20 super(StepHistoryApi, self).__init__(**kwargs) 20 super(StepHistoryApi, self).__init__(**kwargs)
21 # step_history is instantiated in annontated_run.py. Recipe engine is
22 # responsible for updating it.
23 assert isinstance(step_history, collections.OrderedDict)
21 self._step_history = step_history 24 self._step_history = step_history
22 25
23 def __getitem__(self, key): 26 def __getitem__(self, key):
24 # NOTE: Ideally, we could constify the values here. However, APIs are 27 # NOTE: Ideally, we could constify the values here. However, APIs are
25 # allowed to add any arbitrary data to step history items, so this would 28 # allowed to add any arbitrary data to step history items, so this would
26 # be essentially impossible without significant additional code. 29 # be essentially impossible without significant additional code.
27 return self._step_history[key] 30 return self._step_history[key]
28 31
29 def __iter__(self): # pragma: no cover 32 def __iter__(self): # pragma: no cover
30 return iter(self._step_history) 33 return iter(self._step_history)
31 34
32 def __len__(self): # pragma: no cover 35 def __len__(self): # pragma: no cover
33 return len(self._step_history) 36 return len(self._step_history)
34 37
35 @property 38 @property
36 def failed(self): 39 def failed(self):
37 """Return status of the build so far, as a bool.""" 40 """Return status of the build so far, as a bool."""
38 return self._step_history.failed 41 return self._step_history.failed
39 42
40 def last_step(self): 43 def last_step(self):
41 """Return the last StepData object, or None if no steps have run.""" 44 """Return the last StepData object, or None if no steps have run."""
42 key = next(reversed(self._step_history), None) 45 key = next(reversed(self._step_history), None)
43 return self[key] if key else None 46 return self[key] if key else None
OLDNEW
« no previous file with comments | « scripts/slave/recipe_modules/step/api.py ('k') | scripts/slave/recipe_test_api.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698