aboutsummaryrefslogtreecommitdiffstats
path: root/repsys
blob: 8f3fd401f872e9770f00197633929093c679e854 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python
from RepSys import Error
from RepSys.command import *
import getopt
import sys

VERSION="1.6.1"

HELP = """\
Usage: repsys COMMAND [COMMAND ARGUMENTS]

Useful commands:
    co
    submit
    create
    getspec
    getsrpm
    changed
    authoremail

Run "repsys COMMAND --help" for more information.

Written by Gustavo Niemeyer <gustavo@niemeyer.net>
"""

def parse_options():
    parser = OptionParser(help=HELP, version="%prog "+VERSION)
    parser.disable_interspersed_args()
    parser.add_option("--debug", action="store_true")
    opts, args = parser.parse_args()
    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__":
    do_command(parse_options, dispatch_command)

# vim:et:ts=4:sw=4