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

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

Issue 1241323004: Cross-repo recipe package system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Roll to latest recipes-py Created 5 years, 3 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
OLDNEW
(Empty)
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
3 # found in the LICENSE file.
4
5 from recipe_engine import recipe_api
6
7 import textwrap
8
9 class PythonApi(recipe_api.RecipeApi):
10 def __call__(self, name, script, args=None, unbuffered=True, **kwargs):
11 """Return a step to run a python script with arguments."""
12 cmd = ['python']
13 if unbuffered:
14 cmd.append('-u')
15 cmd.append(script)
16 return self.m.step(name, cmd + list(args or []), **kwargs)
17
18 def inline(self, name, program, add_python_log=True, **kwargs):
19 """Run an inline python program as a step.
20
21 Program is output to a temp file and run when this step executes.
22 """
23 program = textwrap.dedent(program)
24 compile(program, '<string>', 'exec', dont_inherit=1)
25
26 try:
27 self(name, self.m.raw_io.input(program, '.py'), **kwargs)
28 finally:
29 result = self.m.step.active_result
30 if result and add_python_log:
31 result.presentation.logs['python.inline'] = program.splitlines()
32
33 return result
34
35 def result_step(self, name, text, retcode, as_log=None):
36 """Return a no-op step that exits with a specified return code."""
37 try:
38 self.inline(name,
39 'import sys; sys.exit(%d)' % (retcode,),
40 add_python_log=False,
41 step_test_data=lambda: self.m.raw_io.test_api.output(
42 text, retcode=retcode))
43 finally:
44 if as_log:
45 self.m.step.active_result.presentation.logs[as_log] = text
46 else:
47 self.m.step.active_result.presentation.step_text = text
48
49 def succeeding_step(self, name, text, as_log=None):
50 """Return a succeeding step (correctly recognized in expectations)."""
51 return self.result_step(name, text, 0, as_log=as_log)
52
53 def failing_step(self, name, text, as_log=None):
54 """Return a failing step (correctly recognized in expectations)."""
55 return self.result_step(name, text, 1, as_log=as_log)
OLDNEW
« no previous file with comments | « scripts/slave/recipe_modules/python/__init__.py ('k') | scripts/slave/recipe_modules/python/example.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698