7 from optparse import OptionParser
10 def parse_bool(option, opt_str, value, parser):
11 if opt_str in ["--debug"]:
12 parser.values.debug = int(int(value))
13 elif opt_str in ["--mail"]:
14 parser.values.mail = int(int(value))
15 elif opt_str in ["--bcc"]:
16 parser.values.bcc = int(int(value))
17 elif opt_str in ["--policysavedb"]:
18 parser.values.policysavedb = int(int(value))
19 elif opt_str in ["--squeeze"]:
20 parser.values.squeeze = int(int(value))
24 def parseSetDefaults(parser=None):
26 parser = OptionParser()
28 parser.set_defaults(debug = config.debug,
33 squeeze = config.squeeze,
34 policysavedb = config.policysavedb)
36 parser.add_option("", "--debug", dest="debug",
37 help="Enable debugging",
42 parser.add_option("", "--mail", dest="mail",
43 help="Enable sending email",
48 parser.add_option("", "--bcc", dest="bcc",
49 help="Include BCC to user",
54 parser.add_option("", "--squeeze", dest="squeeze",
55 help="Squeeze sites or not",
60 parser.add_option("", "--policysavedb", dest="policysavedb",
61 help="Save the policy event database after a run",
66 parser.add_option("", "--run", dest="run",
68 help="Perform monitor or print configs")
69 parser.add_option("", "--email", dest="email",
70 help="Specify an email address to use for mail when "+\
71 "debug is enabled or for bcc when it is not")
74 def parseSetNodeSets(parser=None):
76 parser = OptionParser()
78 parser.set_defaults(node=None, site=None, nodelist=None, nodeselect=None, nodegroup=None)
79 parser.add_option("", "--node", dest="node", metavar="hostname",
80 help="Provide a single node to operate on")
81 parser.add_option("", "--site", dest="site", metavar="site name",
82 help="Specify a single site to operate on")
83 parser.add_option("", "--nodegroup", dest="nodegroup", metavar="GroupName",
84 help="Provide the nodegroup for the list of nodes.")
85 parser.add_option("", "--nodelist", dest="nodelist", metavar="FILE",
86 help="Provide the input file for the list of objects")
87 parser.add_option("", "--nodeselect", dest="nodeselect", metavar="query string",
88 help="Provide a selection string to return a node list.")
92 def getParser(parsesets=[], parser=None):
98 if 'nodesets' in parsesets:
99 p = parseSetNodeSets(p)
100 if 'defaults' in parsesets:
101 p = parseSetDefaults(p)
105 def parse_args(parser):
107 (options, args) = parser.parse_args()
109 o.__dict__.update(options.__dict__)
110 o.__dict__['args'] = args
112 config.updatemodule(config, o)
115 def print_values(parser):
117 for key in parser.__dict__.keys():
118 if key not in exclude:
119 print "%20s == %s" % (key, parser.__dict__[key])