OLD | NEW |
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 from slave import recipe_api | 5 from slave import recipe_api |
| 6 from slave import recipe_util |
6 | 7 |
7 class StepApi(recipe_api.RecipeApi): | 8 class StepApi(recipe_api.RecipeApi): |
8 def __init__(self, *args, **kwargs): | 9 def __init__(self, *args, **kwargs): |
9 self._auto_resolve_conflicts = False | 10 self._auto_resolve_conflicts = False |
10 self._name_function = None | 11 self._name_function = None |
11 self._step_names = {} | 12 self._step_names = {} |
12 super(StepApi, self).__init__(*args, **kwargs) | 13 super(StepApi, self).__init__(*args, **kwargs) |
13 | 14 |
14 # Making these properties makes them show up in show_me_the_modules, | 15 # Making these properties makes them show up in show_me_the_modules, |
15 # and also makes it clear that they are intended to be mutated. | 16 # and also makes it clear that they are intended to be mutated. |
(...skipping 14 matching lines...) Expand all Loading... |
30 cmd: A list of strings in the style of subprocess.Popen. | 31 cmd: A list of strings in the style of subprocess.Popen. |
31 **kwargs: Additional entries to add to the annotator.py step dictionary. | 32 **kwargs: Additional entries to add to the annotator.py step dictionary. |
32 | 33 |
33 Returns: | 34 Returns: |
34 A step dictionary which is compatible with annotator.py. | 35 A step dictionary which is compatible with annotator.py. |
35 """ | 36 """ |
36 assert 'shell' not in kwargs | 37 assert 'shell' not in kwargs |
37 assert isinstance(cmd, list) | 38 assert isinstance(cmd, list) |
38 | 39 |
39 if kwargs.get('abort_on_failure', False): | 40 if kwargs.get('abort_on_failure', False): |
40 @recipe_api.wrap_followup(kwargs) | 41 @recipe_util.wrap_followup(kwargs) |
41 def assert_success(step_result): | 42 def assert_success(step_result): |
42 if step_result.presentation.status == 'FAILURE': | 43 if step_result.presentation.status == 'FAILURE': |
43 raise recipe_api.RecipeAbort( | 44 raise recipe_util.RecipeAbort( |
44 "Step(%s) failed and was marked as abort_on_failure" % name) | 45 "Step(%s) failed and was marked as abort_on_failure" % name) |
45 kwargs['followup_fn'] = assert_success | 46 kwargs['followup_fn'] = assert_success |
46 | 47 |
47 cmd = list(cmd) # Create a copy in order to not alter the input argument. | 48 cmd = list(cmd) # Create a copy in order to not alter the input argument. |
48 if self.auto_resolve_conflicts: | 49 if self.auto_resolve_conflicts: |
49 step_count = self._step_names.setdefault(name, 0) + 1 | 50 step_count = self._step_names.setdefault(name, 0) + 1 |
50 self._step_names[name] = step_count | 51 self._step_names[name] = step_count |
51 if step_count > 1: | 52 if step_count > 1: |
52 name = "%s (%d)" % (name, step_count) | 53 name = "%s (%d)" % (name, step_count) |
53 ret = kwargs | 54 ret = kwargs |
54 ret.update({'name': name, 'cmd': cmd}) | 55 ret.update({'name': name, 'cmd': cmd}) |
55 return ret | 56 return ret |
OLD | NEW |