OLD | NEW |
(Empty) | |
| 1 import functools |
| 2 import os |
| 3 |
| 4 |
| 5 SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__)) |
| 6 BUILD_ROOT = os.path.dirname(os.path.dirname(SCRIPT_PATH)) |
| 7 ROOT_PATH = os.path.abspath(os.path.join( |
| 8 SCRIPT_PATH, os.pardir, os.pardir, os.pardir)) |
| 9 BASE_DIRS = [ |
| 10 SCRIPT_PATH, |
| 11 os.path.join(ROOT_PATH, 'build_internal', 'scripts', 'slave'), |
| 12 os.path.join(ROOT_PATH, 'build_internal', 'scripts', 'slave-internal') |
| 13 ] |
| 14 MODULE_DIRS = lambda: [os.path.join(x, 'recipe_modules') for x in BASE_DIRS] |
| 15 RECIPE_DIRS = lambda: [os.path.join(x, 'recipes') for x in BASE_DIRS] |
| 16 |
| 17 |
| 18 class ModuleInjectionSite(object): |
| 19 pass |
| 20 |
| 21 |
| 22 class Placeholder(object): |
| 23 """Base class for json placeholders. Do not use directly.""" |
| 24 def __init__(self, name, mod_name): |
| 25 self._name_pieces = (mod_name, name) |
| 26 self._name = "%s.%s" % self._name_pieces |
| 27 |
| 28 def render(self, test): # pragma: no cover |
| 29 """Return [cmd items]*""" |
| 30 raise NotImplementedError |
| 31 |
| 32 def result(self, presentation, test): |
| 33 """Called after step completion. |
| 34 |
| 35 Args: |
| 36 presentation (StepPresentation) - for the current step. |
| 37 test (PlaceholderTestData) - test data for this placeholder. |
| 38 |
| 39 Returns value to add to step result. |
| 40 |
| 41 May optionally modify presentation as a side-effect. |
| 42 """ |
| 43 pass |
| 44 |
| 45 @property |
| 46 def name(self): |
| 47 return self._name |
| 48 |
| 49 @property |
| 50 def name_pieces(self): |
| 51 return self._name_pieces |
| 52 |
| 53 |
| 54 def wrap_followup(kwargs, pre=False): |
| 55 """ |
| 56 Decorator for a new followup_fn. |
| 57 |
| 58 Will pop the existing fn out of kwargs (if any), and return a decorator for |
| 59 the new folloup_fn. |
| 60 |
| 61 Args: |
| 62 kwargs - dictionary possibly containing folloup_fn |
| 63 pre - If true, the old folloup_fn is called before the wrapped function. |
| 64 Otherwise, the old followup_fn is called after the wrapped function. |
| 65 """ |
| 66 null_fn = lambda _: None |
| 67 old_followup = kwargs.pop('followup_fn', null_fn) |
| 68 def decorator(f): |
| 69 @functools.wraps(f) |
| 70 def _inner(step_result): |
| 71 if pre: |
| 72 old_followup(step_result) |
| 73 f(step_result) |
| 74 else: |
| 75 f(step_result) |
| 76 old_followup(step_result) |
| 77 if old_followup is not null_fn: |
| 78 _inner.__name__ += '[%s]' % old_followup.__name__ |
| 79 return _inner |
| 80 return decorator |
| 81 |
| 82 |
OLD | NEW |