thomas@78: #! /usr/bin/python2.4 thomas@78: # Copyright (C) 2007 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: thomas@78: def parse_commandline(): thomas@78: parser = create_parser() 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.")) 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: thomas@78: packager_opts = [opts for opts in packager_opts if opts["name"] in args] thomas@78: # check whether we got all of the names in args: thomas@78: for opts in packager_opts: thomas@78: name = opts["name"] thomas@78: if name in args: thomas@78: args.remove(name) thomas@78: for name in args: thomas@78: print >>sys.stderr, "No package tracks 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], 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()