source: people/peter.buschman/backup_monitoring/backmon/commands/status/_status.py

Last change on this file was 976, checked in by peter, on Dec 6, 2011 at 10:19:33 AM

Raw checkin of current NetBackup / TSM parsing code.

File size: 1.6 KB
RevLine 
[976]1#!/usr/bin/python26
2###
3### backmon.commands.status
4###
5
6import sys
7import os
8import os.path
9import glob
10import re
11
12from optparse import OptionParser
13
14from ...lib import *
15
16import subcommands
17
18SUBCOMMAND_LIST = [
19 'dsu',
20 'dssu',
21]
22
23SUBCOMMAND_HELP = {
24 'dsu' : 'print disk storage unit (DSU) status',
25 'dssu' : 'print disk staging storage unit (DSSU) status',
26}
27
28##
29## OPTIONS
30##
31usage = """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
37parser = OptionParser(usage=usage)
38
39def 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.