#!/usr/bin/python from RepSys import Error, plugins from RepSys.command import * import getopt import sys VERSION="1.6.19.1" HELP = """\ Usage: repsys COMMAND [COMMAND ARGUMENTS] Useful commands: co ci sync submit create getspec getsrpm rpmlog changed authoremail putsrpm switch Run "repsys COMMAND --help" for more information. Run "repsys --help-plugins" for help on loaded plugins. Written by Gustavo Niemeyer """ def plugin_help(opt, val, parser, mode): if parser is None: prog = sys.argv[0] print "Use %s --help-plugin " % prog print "Available plugins:" print for name in plugins.list(): print name else: print plugins.help(parser) raise SystemExit def parse_options(): parser = OptionParser(help=HELP, version="%prog "+VERSION) parser.disable_interspersed_args() parser.add_option("--debug", action="store_true") parser.add_option("--help-plugins", action="callback", callback=plugin_help) parser.add_option("--help-plugin", type="string", dest="__ignore", action="callback", callback=plugin_help) opts, args = parser.parse_args() del opts.__ignore if len(args) < 1: parser.print_help(sys.stderr) sys.exit(1) opts.command = args[0] opts.argv = args return opts def dispatch_command(command, argv, debug=0): sys.argv = argv try: repsys_module = __import__("RepSys.commands."+command) commands_module = getattr(repsys_module, "commands") command_module = getattr(commands_module, command) except (ImportError, AttributeError): if debug: import traceback traceback.print_exc() sys.exit(1) raise Error, "invalid command '%s'" % command command_module.main() if __name__ == "__main__": try: plugins.load() except Error, e: sys.stderr.write("plugin initialization error: %s\n" % e) sys.exit(1) do_command(parse_options, dispatch_command) # vim:et:ts=4:sw=4