Line | |
---|
1 | #!/usr/bin/python26
|
---|
2 | ###
|
---|
3 | ### backmon.commands.summary
|
---|
4 | ###
|
---|
5 |
|
---|
6 | import sys
|
---|
7 | import os
|
---|
8 | import os.path
|
---|
9 | import glob
|
---|
10 | import re
|
---|
11 |
|
---|
12 | from optparse import OptionParser
|
---|
13 |
|
---|
14 | from ...lib import *
|
---|
15 |
|
---|
16 | import subcommands
|
---|
17 |
|
---|
18 | SUBCOMMAND_LIST = [
|
---|
19 | 'backups',
|
---|
20 | ]
|
---|
21 |
|
---|
22 | SUBCOMMAND_HELP = {
|
---|
23 | 'backups' : 'backup summary statistics',
|
---|
24 | }
|
---|
25 |
|
---|
26 | ##
|
---|
27 | ## OPTIONS
|
---|
28 | ##
|
---|
29 | usage = """Usage: %prog [options] -e [ENVIRONMENT] summary [subcommand] [options] [arguments]'
|
---|
30 |
|
---|
31 | available subcommands:
|
---|
32 |
|
---|
33 | """ + '\n'.join([' %-10s %s' % (cmd, SUBCOMMAND_HELP[cmd]) for cmd in SUBCOMMAND_LIST])
|
---|
34 |
|
---|
35 | parser = OptionParser(usage=usage)
|
---|
36 |
|
---|
37 | def run(args, kwargs):
|
---|
38 |
|
---|
39 | #
|
---|
40 | # add kwargs to local namespace
|
---|
41 | #
|
---|
42 | for key in kwargs.keys():
|
---|
43 |
|
---|
44 | if re.compile('^[A-Z][A-Z_]+$').match(key):
|
---|
45 | exec(key + ' = kwargs[\'' + key + '\']')
|
---|
46 |
|
---|
47 | SUBCOMMAND=None
|
---|
48 | subcommand_pos = 0
|
---|
49 |
|
---|
50 | i = 0
|
---|
51 |
|
---|
52 | for arg in args:
|
---|
53 |
|
---|
54 | i += 1
|
---|
55 |
|
---|
56 | if arg in SUBCOMMAND_LIST:
|
---|
57 | SUBCOMMAND = arg
|
---|
58 | subcommand_pos = i
|
---|
59 | break
|
---|
60 |
|
---|
61 | subcommand_args = args[subcommand_pos:]
|
---|
62 |
|
---|
63 | if SUBCOMMAND:
|
---|
64 | (options, args) = parser.parse_args(args[:subcommand_pos])
|
---|
65 |
|
---|
66 | #
|
---|
67 | # SUBCOMMAND
|
---|
68 | #
|
---|
69 | if( not SUBCOMMAND ):
|
---|
70 | parser.print_help()
|
---|
71 | sys.exit(1)
|
---|
72 |
|
---|
73 | DEBUG('SUBCOMMAND=%s' % (SUBCOMMAND))
|
---|
74 |
|
---|
75 | if hasattr(subcommands, SUBCOMMAND):
|
---|
76 | exec 'subcommands.' + SUBCOMMAND + '.run(subcommand_args, locals())'
|
---|
77 | else:
|
---|
78 | ERROR('Invalid subcommand \'%s\'.' % (SUBCOMMAND))
|
---|
79 |
|
---|
80 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.