1 |
#!/usr/bin/python |
2 |
from MgaRepo import Error, plugins, config |
3 |
from MgaRepo.command import * |
4 |
import getopt |
5 |
import sys |
6 |
|
7 |
VERSION="1.9.11" |
8 |
|
9 |
HELP = """\ |
10 |
Usage: mgarepo COMMAND [COMMAND ARGUMENTS] |
11 |
|
12 |
Tool to access and manage a package repository structure. |
13 |
|
14 |
Useful commands: |
15 |
co checkout a package |
16 |
ci commit changes |
17 |
sync add-remove all file changes from the .spec |
18 |
submit submit a package for build |
19 |
putsrpm import a source package to the repository |
20 |
getspec prints the spec |
21 |
rpmlog prints the RPM changelog |
22 |
getsrpm creates the source RPM |
23 |
maintdb interact with the maintainer db |
24 |
create create the structure of a new package |
25 |
changed shows changes not submitted |
26 |
authoremail prints the e-mail of a given author |
27 |
switch relocate to mirror or upstream repository |
28 |
upload add a file to binrepo |
29 |
del remove a file from binrepo |
30 |
up update the working copy and synchronize all binaries |
31 |
|
32 |
Run "mgarepo COMMAND --help" and "man 8 mgarepo" for more information. |
33 |
|
34 |
Written by Gustavo Niemeyer <gustavo@niemeyer.net> |
35 |
""" |
36 |
|
37 |
command_aliases = {"import": "putsrpm"} |
38 |
|
39 |
def plugin_help(opt, val, parser, mode): |
40 |
if parser is None: |
41 |
prog = sys.argv[0] |
42 |
print "Use %s --help-plugin <plugin name>" % prog |
43 |
print "Available plugins:" |
44 |
print |
45 |
for name in plugins.list(): |
46 |
print name |
47 |
else: |
48 |
print plugins.help(parser) |
49 |
raise SystemExit |
50 |
|
51 |
def parse_options(): |
52 |
parser = OptionParser(help=HELP, version="%prog "+VERSION) |
53 |
parser.disable_interspersed_args() |
54 |
parser.add_option("--debug", action="store_true") |
55 |
parser.add_option("--help-plugins", action="callback", callback=plugin_help) |
56 |
parser.add_option("--help-plugin", type="string", dest="__ignore", |
57 |
action="callback", callback=plugin_help) |
58 |
opts, args = parser.parse_args() |
59 |
del opts.__ignore |
60 |
if len(args) < 1: |
61 |
parser.print_help(sys.stderr) |
62 |
sys.exit(1) |
63 |
opts.command = args[0] |
64 |
opts.argv = args |
65 |
return opts |
66 |
|
67 |
def dispatch_command(command, argv, debug=0): |
68 |
sys.argv = argv |
69 |
try: |
70 |
command = command_aliases[command] |
71 |
except KeyError: |
72 |
pass |
73 |
if debug: |
74 |
config.set("global", "verbose", "yes") |
75 |
try: |
76 |
repsys_module = __import__("MgaRepo.commands."+command) |
77 |
commands_module = getattr(repsys_module, "commands") |
78 |
command_module = getattr(commands_module, command) |
79 |
except (ImportError, AttributeError): |
80 |
etype, exc, tb = sys.exc_info() |
81 |
if tb.tb_next is None and not debug: |
82 |
raise Error, "invalid command '%s'" % command |
83 |
raise |
84 |
command_module.main() |
85 |
|
86 |
if __name__ == "__main__": |
87 |
try: |
88 |
plugins.load() |
89 |
except Error, e: |
90 |
sys.stderr.write("plugin initialization error: %s\n" % e) |
91 |
sys.exit(1) |
92 |
config.set("global", "mgarepo-cmd", sys.argv[0]) |
93 |
do_command(parse_options, dispatch_command) |
94 |
|
95 |
# vim:et:ts=4:sw=4 |