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

Side by Side Diff: recipe_modules/step/api.py

Issue 2668113002: step: expose get_context() to get the context object (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | 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 LUCI Authors. All rights reserved. 1 # Copyright 2013 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file. 3 # that can be found in the LICENSE file.
4 4
5 import contextlib 5 import contextlib
6 import datetime 6 import datetime
7 7
8 from recipe_engine import recipe_api 8 from recipe_engine import recipe_api
9 9
10 10
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 new_step_text = result.json.output['step_text'] 70 new_step_text = result.json.output['step_text']
71 api.step.active_result.presentation.step_text = new_step_text 71 api.step.active_result.presentation.step_text = new_step_text
72 """ 72 """
73 return self.step_client.previous_step_result() 73 return self.step_client.previous_step_result()
74 74
75 @property 75 @property
76 def context(self): 76 def context(self):
77 """ See recipe_api.py for docs. """ 77 """ See recipe_api.py for docs. """
78 return recipe_api.context 78 return recipe_api.context
79 79
80 def get_context(self):
81 return recipe_api._STEP_CONTEXT
iannucci 2017/01/31 22:12:51 this should return a copy of the step context (unl
iannucci 2017/01/31 22:14:49 This is also confusing with the previous property.
82
80 @contextlib.contextmanager 83 @contextlib.contextmanager
81 def nest(self, name): 84 def nest(self, name):
82 """Nest is the high-level interface to annotated hierarchical steps. 85 """Nest is the high-level interface to annotated hierarchical steps.
83 86
84 Calling 87 Calling
85 88
86 with api.step.nest(<name>): 89 with api.step.nest(<name>):
87 ... 90 ...
88 91
89 will generate a dummy step and implicitly create a new context (as 92 will generate a dummy step and implicitly create a new context (as
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 168
166 if cmd is not None: 169 if cmd is not None:
167 command = list(wrapper) 170 command = list(wrapper)
168 command += cmd 171 command += cmd
169 kwargs['cmd'] = command 172 kwargs['cmd'] = command
170 173
171 kwargs['timeout'] = timeout 174 kwargs['timeout'] = timeout
172 kwargs['ok_ret'] = ok_ret 175 kwargs['ok_ret'] = ok_ret
173 176
174 # Obtain information from composite step parent. 177 # Obtain information from composite step parent.
175 compositor = recipe_api._STEP_CONTEXT 178 compositor = self.get_context()
176 179
177 # Calculate our full step name. If a step already has that name, add an 180 # Calculate our full step name. If a step already has that name, add an
178 # index to the end of it. 181 # index to the end of it.
179 # 182 #
180 # Note that another step could exist with that index already added to it 183 # Note that another step could exist with that index already added to it
181 # by the user. If this happens, we'll continue appending indexes until we 184 # by the user. If this happens, we'll continue appending indexes until we
182 # have a unique step name. 185 # have a unique step name.
183 while True: 186 while True:
184 full_name = compositor.get_with_context('name', name) 187 full_name = compositor.get_with_context('name', name)
185 if full_name not in self._seen_steps: 188 if full_name not in self._seen_steps:
(...skipping 14 matching lines...) Expand all
200 kwargs['base_name'] = name 203 kwargs['base_name'] = name
201 204
202 schema = self.make_config() 205 schema = self.make_config()
203 schema.set_val(kwargs) 206 schema.set_val(kwargs)
204 return self.run_from_dict(schema.as_jsonish()) 207 return self.run_from_dict(schema.as_jsonish())
205 208
206 # TODO(martiniss) delete, and make generator_script use **kwargs on step() 209 # TODO(martiniss) delete, and make generator_script use **kwargs on step()
207 @recipe_api.composite_step 210 @recipe_api.composite_step
208 def run_from_dict(self, dct): 211 def run_from_dict(self, dct):
209 return self.step_client.run_step(dct) 212 return self.step_client.run_step(dct)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698