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_engine/util.py

Issue 1785543004: Split Placeholder into InputPlaceholder and OutputPlaceholder. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/recipes-py@master
Patch Set: Simplify InputPlaceholder.cleanup Created 4 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
« no previous file with comments | « recipe_engine/step_runner.py ('k') | recipe_modules/json/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-2015 The Chromium Authors. All rights reserved. 1 # Copyright 2013-2015 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 contextlib 5 import contextlib
6 import functools 6 import functools
7 import os 7 import os
8 import sys 8 import sys
9 import traceback 9 import traceback
10 import urllib 10 import urllib
(...skipping 16 matching lines...) Expand all
27 if self.owner_module is None: 27 if self.owner_module is None:
28 raise ModuleInjectionError( 28 raise ModuleInjectionError(
29 "RecipeApi has no dependency %r. (Add it to DEPS?)" % (key,)) 29 "RecipeApi has no dependency %r. (Add it to DEPS?)" % (key,))
30 else: 30 else:
31 raise ModuleInjectionError( 31 raise ModuleInjectionError(
32 "Recipe Module %r has no dependency %r. (Add it to __init__.py:DEPS?)" 32 "Recipe Module %r has no dependency %r. (Add it to __init__.py:DEPS?)"
33 % (self.owner_module.name, key)) 33 % (self.owner_module.name, key))
34 34
35 35
36 class Placeholder(object): 36 class Placeholder(object):
37 """Base class for json placeholders. Do not use directly.""" 37 """Base class for command line argument placeholders. Do not use directly."""
38 def __init__(self): 38 def __init__(self):
39 self.name_pieces = None 39 self.name_pieces = None
40 40
41 @property 41 @property
42 def backing_file(self): # pragma: no cover 42 def backing_file(self): # pragma: no cover
43 """Return path to a temp file that holds or receives the data. 43 """Return path to a temp file that holds or receives the data.
44 44
45 Valid only after 'render' has been called. 45 Valid only after 'render' has been called.
46 """ 46 """
47 raise NotImplementedError 47 raise NotImplementedError
48 48
49 def render(self, test): # pragma: no cover 49 def render(self, test): # pragma: no cover
50 """Return [cmd items]*""" 50 """Return [cmd items]*"""
51 raise NotImplementedError 51 raise NotImplementedError
52 52
53 @property
54 def name(self):
55 assert self.name_pieces
56 return "%s.%s" % self.name_pieces
57
58
59 class InputPlaceholder(Placeholder):
60 """Base class for json/raw_io input placeholders. Do not use directly."""
61 def cleanup(self, test_enabled):
62 """Called after step completion.
63
64 Args:
65 test_enabled (bool) - indicate whether running in simulation mode.
66 """
67 pass
68
69
70 class OutputPlaceholder(Placeholder):
71 """Base class for json/raw_io output placeholders. Do not use directly."""
53 def result(self, presentation, test): 72 def result(self, presentation, test):
54 """Called after step completion. 73 """Called after step completion.
55 74
56 Args: 75 Args:
57 presentation (StepPresentation) - for the current step. 76 presentation (StepPresentation) - for the current step.
58 test (PlaceholderTestData) - test data for this placeholder. 77 test (PlaceholderTestData) - test data for this placeholder.
59 78
60 Returns value to add to step result.
61
62 May optionally modify presentation as a side-effect. 79 May optionally modify presentation as a side-effect.
80 Returned value will be added to the step result.
63 """ 81 """
64 pass 82 pass
65 83
66 @property
67 def name(self):
68 assert self.name_pieces
69 return "%s.%s" % self.name_pieces
70
71 84
72 def static_wraps(func): 85 def static_wraps(func):
73 wrapped_fn = func 86 wrapped_fn = func
74 if isinstance(func, staticmethod): 87 if isinstance(func, staticmethod):
75 # __get__(obj) is the way to get the function contained in the staticmethod. 88 # __get__(obj) is the way to get the function contained in the staticmethod.
76 # python 2.7+ has a __func__ member, but previous to this the attribute 89 # python 2.7+ has a __func__ member, but previous to this the attribute
77 # doesn't exist. It doesn't matter what the obj is, as long as it's not 90 # doesn't exist. It doesn't matter what the obj is, as long as it's not
78 # None. 91 # None.
79 wrapped_fn = func.__get__(object) 92 wrapped_fn = func.__get__(object)
80 return functools.wraps(wrapped_fn) 93 return functools.wraps(wrapped_fn)
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 self.lines[-1].write(s) 177 self.lines[-1].write(s)
165 break 178 break
166 self.lines[-1].write(s[:i]) 179 self.lines[-1].write(s[:i])
167 self.lines[-1] = self.lines[-1].getvalue() 180 self.lines[-1] = self.lines[-1].getvalue()
168 self.lines.append(StringIO()) 181 self.lines.append(StringIO())
169 s = s[i+1:] 182 s = s[i+1:]
170 183
171 def close(self): 184 def close(self):
172 if not isinstance(self.lines[-1], basestring): 185 if not isinstance(self.lines[-1], basestring):
173 self.lines[-1] = self.lines[-1].getvalue() 186 self.lines[-1] = self.lines[-1].getvalue()
OLDNEW
« no previous file with comments | « recipe_engine/step_runner.py ('k') | recipe_modules/json/api.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698