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 |
| 27 def render(self, test): # pragma: no cover |
| 28 """Return [cmd items]*""" |
| 29 raise NotImplementedError |
| 30 |
| 31 def result(self, presentation, test): |
| 32 """Called after step completion. |
| 33 |
| 34 Args: |
| 35 presentation (StepPresentation) - for the current step. |
| 36 test (PlaceholderTestData) - test data for this placeholder. |
| 37 |
| 38 Returns value to add to step result. |
| 39 |
| 40 May optionally modify presentation as a side-effect. |
| 41 """ |
| 42 pass |
| 43 |
| 44 @property |
| 45 def name(self): |
| 46 return "%s.%s" % self._name_pieces |
| 47 |
| 48 @property |
| 49 def name_pieces(self): |
| 50 return self._name_pieces |
| 51 |
| 52 |
| 53 def wrap_followup(kwargs, pre=False): |
| 54 """ |
| 55 Decorator for a new followup_fn. |
| 56 |
| 57 Will pop the existing fn out of kwargs (if any), and return a decorator for |
| 58 the new folloup_fn. |
| 59 |
| 60 Args: |
| 61 kwargs - dictionary possibly containing folloup_fn |
| 62 pre - If true, the old folloup_fn is called before the wrapped function. |
| 63 Otherwise, the old followup_fn is called after the wrapped function. |
| 64 """ |
| 65 null_fn = lambda _: None |
| 66 old_followup = kwargs.pop('followup_fn', null_fn) |
| 67 def decorator(f): |
| 68 @functools.wraps(f) |
| 69 def _inner(step_result): |
| 70 if pre: |
| 71 old_followup(step_result) |
| 72 f(step_result) |
| 73 else: |
| 74 f(step_result) |
| 75 old_followup(step_result) |
| 76 if old_followup is not null_fn: |
| 77 _inner.__name__ += '[%s]' % old_followup.__name__ |
| 78 return _inner |
| 79 return decorator |
| 80 |
| 81 |
OLD | NEW |