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 setFileFromList(file, list):
33 def getListFromFile(file):
45 email="soltesz@cs.utk.edu"
52 def __init__(self, parser=None):
53 if os.path.exists(self.__file): # file exists, read that.
54 f = open(self.__file, 'r')
56 self.__dict__.update(o)
60 self.parser = OptionParser()
64 self.parser.set_defaults(debug = self.debug,
70 squeeze = self.squeeze,
71 policysavedb = self.policysavedb)
73 self.parser.add_option("", "--debug", dest="debug",
74 help="Enable debugging",
79 self.parser.add_option("", "--mail", dest="mail",
80 help="Enable sending email",
85 self.parser.add_option("", "--bcc", dest="bcc",
86 help="Include BCC to user",
91 self.parser.add_option("", "--squeeze", dest="squeeze",
92 help="Squeeze sites or not",
97 self.parser.add_option("", "--policysavedb", dest="policysavedb",
98 help="Save the policy event database after a run",
103 self.parser.add_option("", "--checkopt", dest="checkopt",
105 help="print current options")
106 self.parser.add_option("", "--run", dest="run",
108 help="Perform monitor or print configs")
109 self.parser.add_option("", "--email", dest="email",
110 help="Specify an email address to use for mail when "+\
111 "debug is enabled or for bcc when it is not")
113 # config_command is needed to keep subsequent loads of config() from
114 # trying to parse the arguments that have already been parsed by
116 if parser == None and config_command:
117 print "calling parse_args"
120 def parse_args(self):
121 #print "self: %s" % self
123 #print traceback.print_stack()
124 #print "Ccalling parse_args"
125 (options, args) = self.parser.parse_args()
126 #for o in options.__dict__:
127 # print "optin: %s == %s" % (o, options.__dict__[o])
128 self.__dict__.update(options.__dict__)
129 self.__dict__['args'] = args
133 # print "\nAdd --run to actually perform the command"
136 def getListFromFile(self, file):
144 def print_values(self):
146 for key in self.__dict__.keys():
147 if key not in exclude:
148 print "%20s == %s" % (key, self.__dict__[key])
150 def save(self, options=None):
151 f = open(self.__file, 'w')
153 o = {'debug': self.debug,
157 'squeeze':self.squeeze,
158 'policysavedb':self.policysavedb}
167 self.parser.print_help()
171 """ Start threads, do some housekeeping, then daemonize. """
173 global config_command
174 config_command = True
175 config = __main__.config()
178 print "acalling parse_args"
181 except Exception, err:
182 print "Error: %s " % err
189 if __name__ == '__main__':