6 __author__ =
'Giacomo Govi'
8 import CondCore.Utilities.o2o
as o2olib
24 nkeys.append(
"-"+keys[1] )
25 nkeys.append(
"--"+keys[0] )
27 if 'type' not in params.keys():
28 params[
'action'] =
"store_true"
29 self.parser.add_argument(*nkeys,**params )
30 self.options.add( keys[0] )
32 def addCommand( self, command_name, help_entry, *requiredOptions ):
33 self.parser.add_argument(
"--"+command_name, action=
"store_true", help=help_entry )
34 for opt
in requiredOptions:
36 raise Exception(
"Option '%s' has not been registered." %opt )
37 self.
commands[command_name] = requiredOptions
43 self.args = self.parser.parse_args()
46 for k
in self.commands.keys():
47 if getattr(self.args,k):
49 print 'Ignoring command %s...' %k
51 required_options = self.commands[k]
52 for o
in required_options:
53 val = getattr(self.args,o)
55 raise Exception(
"Required option '%s' has not been specified." %o )
56 func = getattr(self,k)
63 CommandTool.__init__(self)
65 CommandTool.addOption(self,
"name",
"n", type=str, help=
"the o2o job name")
66 CommandTool.addOption(self,
"configFile",
"c", type=str, help=
"the JSON configuration file path")
67 CommandTool.addOption(self,
"interval",
"i", type=int, help=
"the chron job interval")
68 CommandTool.addOption(self,
"db", type=str, help=
"the target database: pro ( for prod ) or dev ( for prep ). default=pro")
69 CommandTool.addOption(self,
"auth",
"a", type=str, help=
"path of the authentication file")
70 CommandTool.addCommand( self,
"create",
"create a new O2O job",
"name",
"configFile",
"interval")
71 CommandTool.addCommand(self,
"setConfig",
"set a new configuration for the specified job",
"name",
"configFile" )
72 CommandTool.addCommand(self,
"setInterval",
"set a new execution interval for the specified job",
"name",
"interval" )
73 CommandTool.addCommand(self,
"enable",
"enable the O2O job",
"name" )
74 CommandTool.addCommand(self,
"disable",
"disable the O2O job" ,
"name")
75 CommandTool.addCommand(self,
"migrate",
"migrate the tag info for the jobs in configuration entries" )
76 CommandTool.addCommand(self,
"listJobs",
"list the registered jobs" )
77 CommandTool.addCommand(self,
"listConf",
"shows the configurations for the specified job",
"name")
80 db_service = o2olib.prod_db_service
81 if self.args.db
is not None:
82 if self.args.db ==
'dev' or self.args.db ==
'oradev' :
83 db_service = o2olib.dev_db_service
84 elif self.args.db !=
'orapro' and self.args.db !=
'onlineorapro' and self.args.db !=
'pro':
85 raise Exception(
"Database '%s' is not known." %self.args.db )
87 self.
mgr = o2olib.O2OJobMgr()
88 return self.mgr.connect( db_service, self.args.auth )
91 self.mgr.add( self.args.name, self.args.configFile, self.args.interval,
True )
94 self.mgr.setConfig( self.args.name, self.args.configFile )
97 self.mgr.setConfig( self.args.name, self.args.interval )
100 self.mgr.setConfig( self.args.name,
True )
103 self.mgr.setConfig( self.args.name,
False )
106 self.mgr.migrateConfig()
112 self.mgr.listConfig( self.args.name )
120 except Exception
as e:
124 if __name__ ==
'__main__':
126 sys.exit(
main(sys.argv))