Mercurial > bitten > bitten-test
changeset 148:f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
author | cmlenz |
---|---|
date | Sun, 21 Aug 2005 20:04:33 +0000 |
parents | 395b67aa072e |
children | b2623edffb19 |
files | bitten/recipe.py bitten/slave.py bitten/tests/recipe.py bitten/util/xmlio.py scripts/build.py |
diffstat | 5 files changed, 33 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/bitten/recipe.py +++ b/bitten/recipe.py @@ -137,17 +137,10 @@ LOG = 'log' REPORT = 'report' - def __init__(self, filename='recipe.xml', basedir=os.getcwd(), - xml_elem=None): + def __init__(self, xml, basedir=os.getcwd()): + assert isinstance(xml, xmlio.ParsedElement) self.ctxt = Context(basedir) - if filename: - fd = file(self.ctxt.resolve(filename), 'r') - try: - self._root = xmlio.parse(fd) - finally: - fd.close() - elif xml_elem: - self._root = xml_elem + self._root = xml self.description = self._root.attr.get('description') def __iter__(self):
--- a/bitten/slave.py +++ b/bitten/slave.py @@ -156,7 +156,7 @@ for filename in files: os.chmod(os.path.join(root, filename), 0400) - self.execute_build(msgno, Recipe(basedir=path, xml_elem=recipe_xml)) + self.execute_build(msgno, Recipe(recipe_xml, path)) def execute_build(self, msgno, recipe): global log
--- a/bitten/tests/recipe.py +++ b/bitten/tests/recipe.py @@ -23,36 +23,27 @@ import unittest from bitten.recipe import Recipe +from bitten.util import xmlio class RecipeTestCase(unittest.TestCase): def setUp(self): self.temp_dir = os.path.realpath(tempfile.gettempdir()) - self.recipe_xml = open(os.path.join(self.temp_dir, 'recipe.xml'), 'w') - - def tearDown(self): - self.recipe_xml.close() - os.unlink(os.path.join(self.temp_dir, 'recipe.xml')) def test_empty_recipe(self): - self.recipe_xml.write('<?xml version="1.0"?>' - '<build description="test">' - '</build>') - self.recipe_xml.close() - recipe = Recipe(basedir=self.temp_dir) + xml = xmlio.parse('<build description="test"/>') + recipe = Recipe(xml, basedir=self.temp_dir) self.assertEqual('test', recipe.description) self.assertEqual(self.temp_dir, recipe.ctxt.basedir) steps = list(recipe) self.assertEqual(0, len(steps)) def test_single_step(self): - self.recipe_xml.write('<?xml version="1.0"?>' - '<build>' - ' <step id="foo" description="Bar"></step>' - '</build>') - self.recipe_xml.close() - recipe = Recipe(basedir=self.temp_dir) + xml = xmlio.parse('<build>' + ' <step id="foo" description="Bar"></step>' + '</build>') + recipe = Recipe(xml, basedir=self.temp_dir) steps = list(recipe) self.assertEqual(1, len(steps)) self.assertEqual('foo', steps[0].id)
--- a/bitten/util/xmlio.py +++ b/bitten/util/xmlio.py @@ -40,7 +40,7 @@ __slots__ = ['children'] - def __init__(self, *args, **attr): + def __init__(self): """Create an XML fragment.""" self.children = []
--- a/scripts/build.py +++ b/scripts/build.py @@ -25,6 +25,7 @@ from bitten.build import BuildError from bitten.recipe import Recipe +from bitten.util import xmlio def main(): from bitten import __version__ as VERSION @@ -32,6 +33,8 @@ parser = OptionParser(usage='usage: %prog [options] [step1] [step2] ...', version='%%prog %s' % VERSION) + parser.add_option('-f', '--recipe-file', action='store', dest='recipe_file', + metavar='FILE', help='read build recipe from FILE') parser.add_option('--print-reports', action='store_const', dest='print_reports', const=True, help='print generated reports') @@ -39,7 +42,7 @@ const=logging.DEBUG, help='print as much as possible') parser.add_option('-q', '--quiet', action='store_const', dest='loglevel', const=logging.ERROR, help='print as little as possible') - parser.set_defaults(loglevel=logging.INFO) + parser.set_defaults(loglevel=logging.INFO, recipe_file='recipe.xml') options, args = parser.parse_args() log = logging.getLogger('bitten') @@ -51,18 +54,23 @@ log.addHandler(handler) steps_to_run = dict([(step, False) for step in args]) - recipe = Recipe() - for step in recipe: - if not steps_to_run or step.id in steps_to_run: - print - print '-->', step.description or step.id - for type, function, output in step.execute(recipe.ctxt): - if type == Recipe.ERROR: - log.error('Failure in step "%s": %s', step.id, output) - elif type == Recipe.REPORT and options.print_reports: - output.write(sys.stdout, newlines=True) - if step.id in steps_to_run: - steps_to_run[step.id] = True + + recipe_file = file(options.recipe_file, 'r') + try: + recipe = Recipe(xmlio.parse(recipe_file)) + for step in recipe: + if not steps_to_run or step.id in steps_to_run: + print + print '-->', step.description or step.id + for type, function, output in step.execute(recipe.ctxt): + if type == Recipe.ERROR: + log.error('Failure in step "%s": %s', step.id, output) + elif type == Recipe.REPORT and options.print_reports: + output.write(sys.stdout, newlines=True) + if step.id in steps_to_run: + steps_to_run[step.id] = True + finally: + recipe_file.close() if __name__ == '__main__': try: