| Index: scripts/slave/recipe_util.py
|
| diff --git a/scripts/slave/recipe_util.py b/scripts/slave/recipe_util.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..df694e3273b54ed54fe3776c6e0e69ed5ac26bfb
|
| --- /dev/null
|
| +++ b/scripts/slave/recipe_util.py
|
| @@ -0,0 +1,81 @@
|
| +import functools
|
| +import os
|
| +
|
| +
|
| +SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__))
|
| +BUILD_ROOT = os.path.dirname(os.path.dirname(SCRIPT_PATH))
|
| +ROOT_PATH = os.path.abspath(os.path.join(
|
| + SCRIPT_PATH, os.pardir, os.pardir, os.pardir))
|
| +BASE_DIRS = [
|
| + SCRIPT_PATH,
|
| + os.path.join(ROOT_PATH, 'build_internal', 'scripts', 'slave'),
|
| + os.path.join(ROOT_PATH, 'build_internal', 'scripts', 'slave-internal')
|
| +]
|
| +MODULE_DIRS = lambda: [os.path.join(x, 'recipe_modules') for x in BASE_DIRS]
|
| +RECIPE_DIRS = lambda: [os.path.join(x, 'recipes') for x in BASE_DIRS]
|
| +
|
| +
|
| +class ModuleInjectionSite(object):
|
| + pass
|
| +
|
| +
|
| +class Placeholder(object):
|
| + """Base class for json placeholders. Do not use directly."""
|
| + def __init__(self, name, mod_name):
|
| + self._name_pieces = (mod_name, name)
|
| +
|
| + def render(self, test): # pragma: no cover
|
| + """Return [cmd items]*"""
|
| + raise NotImplementedError
|
| +
|
| + def result(self, presentation, test):
|
| + """Called after step completion.
|
| +
|
| + Args:
|
| + presentation (StepPresentation) - for the current step.
|
| + test (PlaceholderTestData) - test data for this placeholder.
|
| +
|
| + Returns value to add to step result.
|
| +
|
| + May optionally modify presentation as a side-effect.
|
| + """
|
| + pass
|
| +
|
| + @property
|
| + def name(self):
|
| + return "%s.%s" % self._name_pieces
|
| +
|
| + @property
|
| + def name_pieces(self):
|
| + return self._name_pieces
|
| +
|
| +
|
| +def wrap_followup(kwargs, pre=False):
|
| + """
|
| + Decorator for a new followup_fn.
|
| +
|
| + Will pop the existing fn out of kwargs (if any), and return a decorator for
|
| + the new folloup_fn.
|
| +
|
| + Args:
|
| + kwargs - dictionary possibly containing folloup_fn
|
| + pre - If true, the old folloup_fn is called before the wrapped function.
|
| + Otherwise, the old followup_fn is called after the wrapped function.
|
| + """
|
| + null_fn = lambda _: None
|
| + old_followup = kwargs.pop('followup_fn', null_fn)
|
| + def decorator(f):
|
| + @functools.wraps(f)
|
| + def _inner(step_result):
|
| + if pre:
|
| + old_followup(step_result)
|
| + f(step_result)
|
| + else:
|
| + f(step_result)
|
| + old_followup(step_result)
|
| + if old_followup is not null_fn:
|
| + _inner.__name__ += '[%s]' % old_followup.__name__
|
| + return _inner
|
| + return decorator
|
| +
|
| +
|
|
|