cmlenz@0: #!/usr/bin/env python cmlenz@5: # -*- coding: iso8859-1 -*- cmlenz@5: # cmlenz@5: # Copyright (C) 2005 Christopher Lenz cmlenz@163: # All rights reserved. cmlenz@5: # cmlenz@163: # This software is licensed as described in the file COPYING, which cmlenz@163: # you should have received as part of this distribution. The terms cmlenz@163: # are also available at http://bitten.cmlenz.net/wiki/License. cmlenz@0: cmlenz@103: import itertools cmlenz@103: import logging cmlenz@4: import sys cmlenz@0: cmlenz@61: from bitten.build import BuildError cmlenz@4: from bitten.recipe import Recipe cmlenz@148: from bitten.util import xmlio cmlenz@4: cmlenz@103: def main(): cmlenz@103: from bitten import __version__ as VERSION cmlenz@103: from optparse import OptionParser cmlenz@4: cmlenz@103: parser = OptionParser(usage='usage: %prog [options] [step1] [step2] ...', cmlenz@103: version='%%prog %s' % VERSION) cmlenz@148: parser.add_option('-f', '--recipe-file', action='store', dest='recipe_file', cmlenz@148: metavar='FILE', help='read build recipe from FILE') cmlenz@240: parser.add_option('--print-logs', action='store_const', cmlenz@240: dest='print_logs', const=True, cmlenz@240: help='print build logs') cmlenz@144: parser.add_option('--print-reports', action='store_const', cmlenz@144: dest='print_reports', const=True, cmlenz@144: help='print generated reports') cmlenz@103: parser.add_option('-v', '--verbose', action='store_const', dest='loglevel', cmlenz@103: const=logging.DEBUG, help='print as much as possible') cmlenz@103: parser.add_option('-q', '--quiet', action='store_const', dest='loglevel', cmlenz@103: const=logging.ERROR, help='print as little as possible') cmlenz@148: parser.set_defaults(loglevel=logging.INFO, recipe_file='recipe.xml') cmlenz@103: options, args = parser.parse_args() cmlenz@103: cmlenz@103: log = logging.getLogger('bitten') cmlenz@103: log.setLevel(options.loglevel) cmlenz@103: handler = logging.StreamHandler() cmlenz@103: handler.setLevel(options.loglevel) cmlenz@109: formatter = logging.Formatter('%(message)s') cmlenz@103: handler.setFormatter(formatter) cmlenz@103: log.addHandler(handler) cmlenz@103: cmlenz@103: steps_to_run = dict([(step, False) for step in args]) cmlenz@148: cmlenz@148: recipe_file = file(options.recipe_file, 'r') cmlenz@148: try: cmlenz@148: recipe = Recipe(xmlio.parse(recipe_file)) cmlenz@148: for step in recipe: cmlenz@148: if not steps_to_run or step.id in steps_to_run: cmlenz@148: print cmlenz@153: print '-->', step.id cmlenz@203: for type, category, generator, output in step.execute(recipe.ctxt): cmlenz@148: if type == Recipe.ERROR: cmlenz@245: log.error(output) cmlenz@240: elif type == Recipe.LOG and options.print_logs: cmlenz@240: output.write(sys.stdout, newlines=True) cmlenz@148: elif type == Recipe.REPORT and options.print_reports: cmlenz@148: output.write(sys.stdout, newlines=True) cmlenz@148: if step.id in steps_to_run: cmlenz@148: steps_to_run[step.id] = True cmlenz@148: finally: cmlenz@148: recipe_file.close() cmlenz@0: cmlenz@0: if __name__ == '__main__': cmlenz@4: try: cmlenz@103: main() cmlenz@4: except BuildError, e: cmlenz@153: print cmlenz@8: print>>sys.stderr, 'FAILED: %s' % e cmlenz@4: sys.exit(-1) cmlenz@153: print cmlenz@8: print 'SUCCESS'