+ if parser == None:
+ self.parser = OptionParser()
+ else:
+ self.parser = parser
+
+ self.parser.set_defaults(debug = self.debug,
+ mail = self.mail,
+ bcc = self.bcc,
+ email = self.email,
+ run = self.run,
+ checkopt = False,
+ squeeze = self.squeeze,
+ policysavedb = self.policysavedb)
+
+ self.parser.add_option("", "--debug", dest="debug",
+ help="Enable debugging",
+ type="int",
+ metavar="[0|1]",
+ action="callback",
+ callback=parse_bool)
+ self.parser.add_option("", "--mail", dest="mail",
+ help="Enable sending email",
+ type="int",
+ metavar="[0|1]",
+ action="callback",
+ callback=parse_bool)
+ self.parser.add_option("", "--bcc", dest="bcc",
+ help="Include BCC to user",
+ type="int",
+ metavar="[0|1]",
+ action="callback",
+ callback=parse_bool)
+ self.parser.add_option("", "--squeeze", dest="squeeze",
+ help="Squeeze sites or not",
+ type="int",
+ metavar="[0|1]",
+ action="callback",
+ callback=parse_bool)
+ self.parser.add_option("", "--policysavedb", dest="policysavedb",
+ help="Save the policy event database after a run",
+ type="int",
+ metavar="[0|1]",
+ action="callback",
+ callback=parse_bool)
+ self.parser.add_option("", "--checkopt", dest="checkopt",
+ action="store_true",
+ help="print current options")
+ self.parser.add_option("", "--run", dest="run",
+ action="store_true",
+ help="Perform monitor or print configs")
+ self.parser.add_option("", "--email", dest="email",
+ help="Specify an email address to use for mail when "+\
+ "debug is enabled or for bcc when it is not")
+
+ # config_command is needed to keep subsequent loads of config() from
+ # trying to parse the arguments that have already been parsed by
+ # the new main().
+ if parser == None and config_command:
+ print "calling parse_args"
+ self.parse_args()
+
+ def parse_args(self):
+ #print "self: %s" % self
+ #import traceback
+ #print traceback.print_stack()
+ #print "Ccalling parse_args"
+ (options, args) = self.parser.parse_args()
+ #for o in options.__dict__:
+ # print "optin: %s == %s" % (o, options.__dict__[o])
+ self.__dict__.update(options.__dict__)
+ self.__dict__['args'] = args
+ self.save(options)
+ if options.checkopt:
+ self.usage()
+ # print "\nAdd --run to actually perform the command"
+ sys.exit(1)
+