source: people/peter.buschman/backup_monitoring/backmon/commands/summary/_summary.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.5 KB
Line 
1#!/usr/bin/python26
2###
3### backmon.commands.summary
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 'backups',
20]
21
22SUBCOMMAND_HELP = {
23 'backups' : 'backup summary statistics',
24}
25
26##
27## OPTIONS
28##
29usage = """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
35parser = OptionParser(usage=usage)
36
37def 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.