cmlenz@0: #!/usr/bin/env python cmlenz@5: # -*- coding: iso8859-1 -*- cmlenz@5: # cmlenz@5: # Copyright (C) 2005 Christopher Lenz cmlenz@5: # cmlenz@5: # Bitten is free software; you can redistribute it and/or cmlenz@5: # modify it under the terms of the GNU General Public License as cmlenz@5: # published by the Free Software Foundation; either version 2 of the cmlenz@5: # License, or (at your option) any later version. cmlenz@5: # cmlenz@5: # Trac is distributed in the hope that it will be useful, cmlenz@5: # but WITHOUT ANY WARRANTY; without even the implied warranty of cmlenz@5: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU cmlenz@5: # General Public License for more details. cmlenz@5: # cmlenz@5: # You should have received a copy of the GNU General Public License cmlenz@5: # along with this program; if not, write to the Free Software cmlenz@5: # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. cmlenz@5: # cmlenz@5: # Author: Christopher Lenz 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@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@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@103: parser.set_defaults(loglevel=logging.INFO) 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@4: recipe = Recipe() cmlenz@4: for step in recipe: cmlenz@103: if not steps_to_run or step.id in steps_to_run: cmlenz@109: print cmlenz@4: print '-->', step.description or step.id cmlenz@109: for type, function, output in step.execute(recipe.ctxt): cmlenz@131: if type == Recipe.ERROR: cmlenz@131: log.error('Failure in step "%s": %s', step.id, output) cmlenz@103: if step.id in steps_to_run: cmlenz@103: steps_to_run[step.id] = True cmlenz@0: cmlenz@0: if __name__ == '__main__': cmlenz@4: try: cmlenz@103: main() cmlenz@4: except BuildError, e: cmlenz@8: print>>sys.stderr, 'FAILED: %s' % e cmlenz@4: sys.exit(-1) cmlenz@8: print 'SUCCESS'