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 import textwrap | 8 import textwrap |
8 | 9 |
9 class PythonApi(recipe_api.RecipeApi): | 10 class PythonApi(recipe_api.RecipeApi): |
10 def __call__(self, name, script, args=None, unbuffered=True, **kwargs): | 11 def __call__(self, name, script, args=None, unbuffered=True, **kwargs): |
11 """Return a step to run a python script with arguments.""" | 12 """Return a step to run a python script with arguments.""" |
12 cmd = ['python'] | 13 cmd = ['python'] |
13 if unbuffered: | 14 if unbuffered: |
14 cmd.append('-u') | 15 cmd.append('-u') |
15 cmd.append(script) | 16 cmd.append(script) |
16 return self.m.step(name, cmd + list(args or []), **kwargs) | 17 return self.m.step(name, cmd + list(args or []), **kwargs) |
17 | 18 |
18 def inline(self, name, program, **kwargs): | 19 def inline(self, name, program, **kwargs): |
19 """Run an inline python program as a step. | 20 """Run an inline python program as a step. |
20 | 21 |
21 Program is output to a temp file and run when this step executes. | 22 Program is output to a temp file and run when this step executes. |
22 """ | 23 """ |
23 program = textwrap.dedent(program) | 24 program = textwrap.dedent(program) |
24 compile(program, '<string>', 'exec', dont_inherit=1) | 25 compile(program, '<string>', 'exec', dont_inherit=1) |
25 | 26 |
26 @recipe_api.wrap_followup(kwargs) | 27 @recipe_util.wrap_followup(kwargs) |
27 def inline_followup(step_result): | 28 def inline_followup(step_result): |
28 step_result.presentation.logs['python.inline'] = program.splitlines() | 29 step_result.presentation.logs['python.inline'] = program.splitlines() |
29 | 30 |
30 return self(name, recipe_api.InputDataPlaceholder(program, '.py'), | 31 return self(name, self.m.raw.input(program, '.py', self.name), |
31 followup_fn=inline_followup, **kwargs) | 32 followup_fn=inline_followup, **kwargs) |
OLD | NEW |