# HG changeset patch # User cmlenz # Date 1120216152 0 # Node ID b2d371dac2702419b7524c1ec22b995f330ecef8 # Parent 2c71450a923800a076a7beeef5a514e84ef7a6dd Allow individual steps of a recipe to be marked as optional, i.e. that an error in such a step should not mean that the build failed. diff --git a/bitten/recipe.py b/bitten/recipe.py --- a/bitten/recipe.py +++ b/bitten/recipe.py @@ -18,8 +18,10 @@ # # Author: Christopher Lenz +import logging import os.path +from bitten.build import BuildError from bitten.util import xmlio __all__ = ['Recipe'] @@ -50,6 +52,7 @@ self._elem = elem self.id = elem.attr['id'] self.description = elem.attr.get('description') + self.onerror = elem.attr.get('onerror', 'fail') def __iter__(self): for child in self._elem: @@ -61,6 +64,16 @@ else: raise InvalidRecipeError, "Unknown element <%s>" % child.name + def execute(self, ctxt): + try: + for function, args in self: + function(ctxt, **args) + except BuildError, e: + if self.onerror == 'fail': + raise BuildError, e + logging.warning('Ignoring error in step %s (%s)', self.id, e) + return None + def _args(self, elem): return dict([(name.replace('-', '_'), value) for name, value in elem.attr.items()]) diff --git a/bitten/slave.py b/bitten/slave.py --- a/bitten/slave.py +++ b/bitten/slave.py @@ -140,9 +140,7 @@ for step in recipe: logging.info('Executing build step "%s"', step.id) try: - for function, args in step: - logging.debug('Executing command "%s"', function) - function(recipe.ctxt, **args) + step.execute(recipe.ctxt) xml = xmlio.Element('step', id=step.id, result='success', description=step.description) self.channel.send_ans(msgno, beep.MIMEMessage(xml)) diff --git a/recipe.xml b/recipe.xml --- a/recipe.xml +++ b/recipe.xml @@ -17,7 +17,7 @@ - diff --git a/scripts/build.py b/scripts/build.py --- a/scripts/build.py +++ b/scripts/build.py @@ -34,8 +34,7 @@ for step in recipe: if not step_id or step.id == step_id: print '-->', step.description or step.id - for function, kw in step: - function(recipe.ctxt, **kw) + step.execute(recipe.ctxt) print steps_run.append(step.id)