bh@287: #! /usr/bin/python bh@287: # Copyright (C) 2007, 2008, 2009 by Intevation GmbH thomas@78: # Authors: thomas@78: # Bernhard Herzog thomas@78: # thomas@78: # This program is free software under the GPL (>=v2) thomas@78: # Read the file COPYING coming with the software for details. thomas@78: thomas@78: """Starts the tree packager""" thomas@78: thomas@78: import sys thomas@78: import os thomas@78: import logging thomas@78: from optparse import OptionParser thomas@78: thomas@78: import treepkgcmd thomas@78: from treepkg.options import create_parser thomas@78: from treepkg.packager import create_package_track, PackagerGroup thomas@78: from treepkg.readconfig import read_config thomas@78: thomas@78: def initialize_logging(): thomas@78: """Initializes the logging system""" thomas@78: root = logging.getLogger() thomas@78: root.setLevel(logging.DEBUG) thomas@78: hdlr = logging.StreamHandler() thomas@78: fmt = logging.Formatter("%(asctime)s %(levelname)s %(message)s") thomas@78: hdlr.setFormatter(fmt) thomas@78: root.addHandler(hdlr) thomas@78: bh@290: def handle_track_option(option, opt_str, value, parser): bh@290: parsed_options = parser.values.track_options bh@290: track_optname, value = value.split("=", 1) bh@290: trackname, optname = track_optname.split(".") bh@290: track_options = parsed_options.setdefault(trackname, dict()) bh@290: track_options[optname] = value bh@290: thomas@78: def parse_commandline(): thomas@78: parser = create_parser() bh@290: parser.set_defaults(track_options=dict()) thomas@78: parser.add_option("--once", action="store_true", thomas@78: help=("Check the packagers only once and exit afterwards." thomas@78: " Without this option, the tree packager will" thomas@78: " check periodically.")) bh@307: parser.add_option("--stop-on-error", action="store_true", bh@307: help=("Stop the tree packager when a packaging" bh@307: " attempt fails.")) bh@81: parser.add_option("--revision", bh@81: help=("SVN revision to update to before attempting" bh@81: " to package.")) bricks@517: parser.add_option("--no-update", action="store_true", bricks@517: help=("Do not update the scm workingcopy before" bh@190: " attempting to package.")) bh@290: parser.add_option("--track-option", action="callback", type="string", bh@290: callback=handle_track_option, bh@290: help=("Sets a track-specific option." bh@290: " The argument should be of the form" bh@290: " TRACKNAME.OPTION=VALUE")) thomas@78: return parser.parse_args() thomas@78: thomas@78: def main(): thomas@78: options, args = parse_commandline() thomas@78: thomas@78: initialize_logging() thomas@78: thomas@78: treepkg_opts, packager_opts = read_config(options.config_file) thomas@78: thomas@78: if args: bh@191: selected_tracks = set(args) bh@191: else: bh@191: selected_tracks = set(opts["name"] for opts in packager_opts) bh@191: bh@191: for opts in packager_opts: bh@191: name = opts["name"] bh@191: opts["do_build"] = name in selected_tracks bh@191: selected_tracks.discard(name) bh@290: if name in options.track_options: bh@290: opts.update(options.track_options[name]) bh@191: for name in selected_tracks: bh@191: print >>sys.stderr, "No package track found named %r" % name thomas@78: thomas@78: if packager_opts: thomas@78: group = PackagerGroup([create_package_track(**opts) thomas@78: for opts in packager_opts], bh@81: revision=options.revision, bricks@517: do_update=not options.no_update, bh@307: stop_on_error=options.stop_on_error, thomas@78: **treepkg_opts) thomas@78: if options.once: thomas@78: group.check_package_tracks() thomas@78: else: thomas@78: group.run() thomas@78: thomas@78: main()