diff scripts/build.py @ 148:f3f5895e373c

Fixes to problems in recipe handling introduced in [155].
author cmlenz
date Sun, 21 Aug 2005 20:04:33 +0000
parents 76dea27af878
children 3ab91c56d7bc
line wrap: on
line diff
--- 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:
Copyright (C) 2012-2017 Edgewall Software