7 from optparse import OptionParser
11 XMLRPC_SERVER="https://boot.planet-lab.org/PLCAPI/"
12 def parse_bool(option, opt_str, value, parser):
13 if opt_str in ["--debug"]:
14 parser.values.debug = int(int(value))
15 elif opt_str in ["--mail"]:
16 parser.values.mail = int(int(value))
17 elif opt_str in ["--bcc"]:
18 parser.values.bcc = int(int(value))
19 elif opt_str in ["--policysavedb"]:
20 parser.values.policysavedb = int(int(value))
21 elif opt_str in ["--squeeze"]:
22 parser.values.squeeze = int(int(value))
26 def getListFromFile(file):
38 email="soltesz@cs.utk.edu"
45 def __init__(self, parser=None):
46 if os.path.exists(self.__file): # file exists, read that.
47 f = open(self.__file, 'r')
49 self.__dict__.update(o)
53 self.parser = OptionParser()
57 self.parser.set_defaults(debug = self.debug,
63 squeeze = self.squeeze,
64 policysavedb = self.policysavedb)
66 self.parser.add_option("", "--debug", dest="debug",
67 help="Enable debugging",
72 self.parser.add_option("", "--mail", dest="mail",
73 help="Enable sending email",
78 self.parser.add_option("", "--bcc", dest="bcc",
79 help="Include BCC to user",
84 self.parser.add_option("", "--squeeze", dest="squeeze",
85 help="Squeeze sites or not",
90 self.parser.add_option("", "--policysavedb", dest="policysavedb",
91 help="Save the policy event database after a run",
96 self.parser.add_option("", "--checkopt", dest="checkopt",
98 help="print current options")
99 self.parser.add_option("", "--run", dest="run",
101 help="Perform monitor or print configs")
102 self.parser.add_option("", "--email", dest="email",
103 help="Specify an email address to use for mail when "+\
104 "debug is enabled or for bcc when it is not")
106 # config_command is needed to keep subsequent loads of config() from
107 # trying to parse the arguments that have already been parsed by
109 if parser == None and config_command:
110 print "calling parse_args"
113 def parse_args(self):
114 #print "self: %s" % self
116 #print traceback.print_stack()
117 #print "Ccalling parse_args"
118 (options, args) = self.parser.parse_args()
119 #for o in options.__dict__:
120 # print "optin: %s == %s" % (o, options.__dict__[o])
121 self.__dict__.update(options.__dict__)
122 self.__dict__['args'] = args
126 # print "\nAdd --run to actually perform the command"
129 def getListFromFile(self, file):
137 def print_values(self):
139 for key in self.__dict__.keys():
140 if key not in exclude:
141 print "%20s == %s" % (key, self.__dict__[key])
143 def save(self, options=None):
144 f = open(self.__file, 'w')
146 o = {'debug': self.debug,
150 'squeeze':self.squeeze,
151 'policysavedb':self.policysavedb}
160 self.parser.print_help()
164 """ Start threads, do some housekeeping, then daemonize. """
166 global config_command
167 config_command = True
168 config = __main__.config()
171 print "acalling parse_args"
174 except Exception, err:
175 print "Error: %s " % err
182 if __name__ == '__main__':