bh@0: #! /usr/bin/python2.4 bh@0: # Copyright (C) 2007 by Intevation GmbH bh@0: # Authors: bh@0: # Bernhard Herzog bh@0: # bh@0: # This program is free software under the GPL (>=v2) bh@0: # Read the file COPYING coming with the software for details. bh@0: bh@0: """Starts the tree packager""" bh@0: bh@27: import sys bh@0: import os bh@0: import logging bh@0: from optparse import OptionParser bh@0: bh@8: from treepkg.packager import create_package_line, PackagerGroup bh@0: from treepkg.readconfig import read_config bh@0: bh@0: def initialize_logging(): bh@0: """Initializes the logging system""" bh@0: root = logging.getLogger() bh@0: root.setLevel(logging.DEBUG) bh@0: hdlr = logging.StreamHandler() bh@0: fmt = logging.Formatter("%(asctime)s %(levelname)s %(message)s") bh@0: hdlr.setFormatter(fmt) bh@0: root.addHandler(hdlr) bh@0: bh@0: def parse_commandline(): bh@0: parser = OptionParser() bh@0: parser.set_defaults(config_file=os.path.join(os.path.dirname(__file__), bh@0: "treepkg.cfg")) bh@25: parser.add_option("--config-file", bh@25: help=("The tree packager config file." bh@25: " Default treepkg.cfg")) bh@25: parser.add_option("--once", action="store_true", bh@25: help=("Check the packagers only once and exit afterwards." bh@25: " Without this option, the tree packager will" bh@25: " check periodically.")) bh@0: return parser.parse_args() bh@0: bh@0: def main(): bh@0: options, args = parse_commandline() bh@0: bh@0: initialize_logging() bh@0: bh@4: treepkg_opts, packager_opts = read_config(options.config_file) bh@27: bh@25: if args: bh@25: packager_opts = [opts for opts in packager_opts if opts["name"] in args] bh@25: # check whether we got all of the names in args: bh@25: for opts in packager_opts: bh@25: name = opts["name"] bh@25: if name in args: bh@25: args.remove(name) bh@25: for name in args: bh@25: print >>sys.stderr, "No package lines found named %r" % name bh@27: bh@27: if packager_opts: bh@27: group = PackagerGroup([create_package_line(**opts) bh@27: for opts in packager_opts], bh@27: **treepkg_opts) bh@27: if options.once: bh@27: group.check_package_lines() bh@27: else: bh@27: group.run() bh@0: bh@0: main()