Line | |
---|
1 | #!/usr/bin/python26
|
---|
2 | ###
|
---|
3 | ### backmon.commands.status
|
---|
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 | 'dsu',
|
---|
20 | 'dssu',
|
---|
21 | ]
|
---|
22 |
|
---|
23 | SUBCOMMAND_HELP = {
|
---|
24 | 'dsu' : 'print disk storage unit (DSU) status',
|
---|
25 | 'dssu' : 'print disk staging storage unit (DSSU) status',
|
---|
26 | }
|
---|
27 |
|
---|
28 | ##
|
---|
29 | ## OPTIONS
|
---|
30 | ##
|
---|
31 | usage = """Usage: %prog [options] -e [ENVIRONMENT] status [subcommand] [options] [arguments]'
|
---|
32 |
|
---|
33 | available subcommands:
|
---|
34 |
|
---|
35 | """ + '\n'.join([' %-10s %s' % (cmd, SUBCOMMAND_HELP[cmd]) for cmd in SUBCOMMAND_LIST])
|
---|
36 |
|
---|
37 | parser = OptionParser(usage=usage)
|
---|
38 |
|
---|
39 | def run(args, kwargs):
|
---|
40 |
|
---|
41 | #
|
---|
42 | # add kwargs to local namespace
|
---|
43 | #
|
---|
44 | for key in kwargs.keys():
|
---|
45 |
|
---|
46 | if re.compile('^[A-Z][A-Z_]+$').match(key):
|
---|
47 | exec(key + ' = kwargs[\'' + key + '\']')
|
---|
48 |
|
---|
49 | SUBCOMMAND=None
|
---|
50 | subcommand_pos = 0
|
---|
51 |
|
---|
52 | i = 0
|
---|
53 |
|
---|
54 | for arg in args:
|
---|
55 |
|
---|
56 | i += 1
|
---|
57 |
|
---|
58 | if arg in SUBCOMMAND_LIST:
|
---|
59 | SUBCOMMAND = arg
|
---|
60 | subcommand_pos = i
|
---|
61 | break
|
---|
62 |
|
---|
63 | subcommand_args = args[subcommand_pos:]
|
---|
64 |
|
---|
65 | if SUBCOMMAND:
|
---|
66 | (options, args) = parser.parse_args(args[:subcommand_pos])
|
---|
67 |
|
---|
68 | #
|
---|
69 | # SUBCOMMAND
|
---|
70 | #
|
---|
71 | if( not SUBCOMMAND ):
|
---|
72 | parser.print_help()
|
---|
73 | sys.exit(1)
|
---|
74 |
|
---|
75 | DEBUG('SUBCOMMAND=%s' % (SUBCOMMAND))
|
---|
76 |
|
---|
77 | if hasattr(subcommands, SUBCOMMAND):
|
---|
78 | exec 'subcommands.' + SUBCOMMAND + '.run(subcommand_args, locals())'
|
---|
79 | else:
|
---|
80 | ERROR('Invalid subcommand \'%s\'.' % (SUBCOMMAND))
|
---|
81 |
|
---|
82 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.