source: soft/build_system/build_system/repsys/branches/V1_6_17/repsys @ 1

Last change on this file since 1 was 1, checked in by fasma, 12 years ago

Initial Import from Mandriva's soft revision 224062 and package revision 45733

File size: 2.1 KB
Line 
1#!/usr/bin/python
2from RepSys import Error, plugins
3from RepSys.command import *
4import getopt
5import sys
6
7VERSION="1.6.17.1"
8
9HELP = """\
10Usage: repsys COMMAND [COMMAND ARGUMENTS]
11
12Useful commands:
13    co
14    ci
15    sync
16    submit
17    create
18    getspec
19    getsrpm
20    rpmlog
21    changed
22    authoremail
23    putsrpm
24
25Run "repsys COMMAND --help" for more information.
26
27Run "repsys --help-plugins" for help on loaded plugins.
28
29Written by Gustavo Niemeyer <gustavo@niemeyer.net>
30"""
31
32def plugin_help(opt, val, parser, mode):
33    if parser is None:
34        prog = sys.argv[0]
35        print "Use %s --help-plugin <plugin name>" % prog
36        print "Available plugins:"
37        print
38        for name in plugins.list():
39            print name
40    else:
41        print plugins.help(parser)
42    raise SystemExit
43
44def parse_options():
45    parser = OptionParser(help=HELP, version="%prog "+VERSION)
46    parser.disable_interspersed_args()
47    parser.add_option("--debug", action="store_true")
48    parser.add_option("--help-plugins", action="callback", callback=plugin_help)
49    parser.add_option("--help-plugin", type="string", dest="__ignore",
50            action="callback", callback=plugin_help)
51    opts, args = parser.parse_args()
52    del opts.__ignore
53    if len(args) < 1:
54        parser.print_help(sys.stderr)
55        sys.exit(1)
56    opts.command = args[0]
57    opts.argv = args
58    return opts
59
60def dispatch_command(command, argv, debug=0):
61    sys.argv = argv
62    try:
63        repsys_module = __import__("RepSys.commands."+command)
64        commands_module = getattr(repsys_module, "commands")
65        command_module = getattr(commands_module, command)
66    except (ImportError, AttributeError):
67        if debug:
68            import traceback
69            traceback.print_exc()
70            sys.exit(1)
71        raise Error, "invalid command '%s'" % command
72    command_module.main()
73   
74if __name__ == "__main__":
75    try:
76        plugins.load()
77    except Error, e:
78        sys.stderr.write("plugin initialization error: %s\n" % e)
79        sys.exit(1)
80    do_command(parse_options, dispatch_command)
81
82# vim:et:ts=4:sw=4
Note: See TracBrowser for help on using the repository browser.