25 |
|
print self.prog_name + ' running on ' + time.ctime(time.time()) |
26 |
|
print ' working directory ' + self.continue_dir |
27 |
|
|
28 |
– |
crabs=[] |
28 |
|
|
29 |
|
def processContinueOption_(self,opts): |
30 |
|
|
66 |
|
|
67 |
|
def createWorkSpace(self): |
68 |
|
# create WorkingDir for Multicrab |
69 |
< |
if 'MULTICRAB.working_dir' in self.opts.keys(): |
70 |
< |
self.continue_dir = os.path.abspath(self.opts['MULTICRAB.working_dir']) |
69 |
> |
import os |
70 |
> |
if not self.continue_dir: |
71 |
> |
prefix = self.prog_name + '_' |
72 |
> |
self.continue_dir = findLastWorkDir(prefix) |
73 |
> |
pass |
74 |
> |
# if 'MULTICRAB.working_dir' in self.opts.keys(): |
75 |
> |
# self.continue_dir = os.path.abspath(self.opts['MULTICRAB.working_dir']) |
76 |
> |
if self.ui_working_dir: |
77 |
> |
self.continue_dir = os.path.abspath(self.ui_working_dir) |
78 |
|
else: |
79 |
|
current_time = time.strftime('%y%m%d_%H%M%S', time.localtime(time.time())) |
80 |
|
self.continue_dir = os.getcwd() + '/' + self.prog_name + '_' + current_time |
83 |
|
try: |
84 |
|
os.mkdir(self.continue_dir) |
85 |
|
except OSError: |
86 |
< |
msg = 'Cannot create '+str(self.continue_dir) +' directory.\n' |
86 |
> |
msg = 'ERROR: Cannot create '+str(self.continue_dir) +' directory.\n' |
87 |
|
raise CrabException(msg) |
88 |
|
pass |
89 |
|
else: |
90 |
< |
msg = 'Directory '+str(self.continue_dir) +' already exist.\n' |
90 |
> |
msg = 'ERROR: Directory '+str(self.continue_dir) +' already exist.\n' |
91 |
|
raise CrabException(msg) |
92 |
|
|
93 |
< |
shutil.copyfile('multicrab.cfg',self.continue_dir+'/multicrab.cfg') |
93 |
> |
os.putenv("MULTICRAB_WORKDIR",self.continue_dir) |
94 |
> |
shutil.copyfile(self.cfg_fname,self.continue_dir+'/multicrab.cfg') |
95 |
|
|
96 |
|
return |
97 |
|
|
131 |
|
cfg_params = self.loadMultiConfig(self.cfg_fname) |
132 |
|
pass |
133 |
|
else: |
134 |
< |
msg = 'cfg-file '+self.cfg_fname+' not found.' |
134 |
> |
msg = 'ERROR: cfg-file '+self.cfg_fname+' not found.' |
135 |
|
raise CrabException(msg) |
136 |
|
pass |
137 |
|
pass |
168 |
|
# then Dataset's specific |
169 |
|
for sec in cfg_params: |
170 |
|
if sec in ['MULTICRAB', 'COMMON']: continue |
164 |
– |
self.cfg_params_dataset[sec]=cfg_params[sec] |
171 |
|
# add common to all dataset |
172 |
+ |
self.cfg_params_dataset[sec]=cfg_params[sec] |
173 |
|
for key in common_opts: |
174 |
< |
self.cfg_params_dataset[sec][key]=common_opts[key] |
174 |
> |
if not self.cfg_params_dataset[sec].has_key(key): |
175 |
> |
self.cfg_params_dataset[sec][key]=common_opts[key] |
176 |
|
pass |
177 |
|
|
178 |
|
# read crab.cfg file and search for storage_path |
179 |
|
crab_cfg_params = loadConfig(crab_cfg,{}) |
180 |
+ |
# also USER.ui_working_dir USER.outputdir and USER.logdir need special treatment |
181 |
|
if cfg_params.has_key("COMMON"): |
182 |
|
self.user_remote_dir = cfg_params["COMMON"].get("user.user_remote_dir", crab_cfg_params.get("USER.user_remote_dir",None)) |
183 |
+ |
self.outputdir = cfg_params["COMMON"].get("user.outputdir", crab_cfg_params.get("USER.outputdir",None)) |
184 |
+ |
self.logdir = cfg_params["COMMON"].get("user.logdir", crab_cfg_params.get("USER.logdir",None)) |
185 |
+ |
self.ui_working_dir = cfg_params["COMMON"].get("user.ui_working_dir", crab_cfg_params.get("USER.ui_working_dir",None)) |
186 |
+ |
self.publish_data_name = cfg_params["COMMON"].get("user.publish_data_name", crab_cfg_params.get("USER.publish_data_name",None)) |
187 |
|
else: |
188 |
|
self.user_remote_dir = crab_cfg_params.get("USER.user_remote_dir",None) |
189 |
+ |
self.outputdir = crab_cfg_params.get("USER.outputdir",None) |
190 |
+ |
self.logdir = crab_cfg_params.get("USER.logdir",None) |
191 |
+ |
self.ui_working_dir = crab_cfg_params.get("USER.ui_working_dir",None) |
192 |
+ |
self.publish_data_name = crab_cfg_params.get("USER.publish_data_name",None) |
193 |
+ |
|
194 |
|
return |
195 |
|
|
196 |
|
def loadMultiConfig(self, file): |
211 |
|
|
212 |
|
def run(self): |
213 |
|
#run crabs |
214 |
+ |
runFileName = self.continue_dir+'/multicrab.exe' |
215 |
+ |
runFile = open(runFileName,"w") |
216 |
|
for sec in self.cfg_params_dataset: |
217 |
|
options={} |
218 |
|
if self.flag_continue: |
226 |
|
tmp="-"+string.upper(opt.split(".")[0])+"."+opt.split(".")[1] |
227 |
|
|
228 |
|
options[tmp]=self.cfg_params_dataset[sec][opt] |
229 |
+ |
|
230 |
+ |
# check if user_remote_dir is set in multicrab.cfg |
231 |
+ |
# protect against no user_remote_dir |
232 |
+ |
self.user_remote_dir =self.cfg_params_dataset[sec].get("user.user_remote_dir",self.user_remote_dir) |
233 |
+ |
if not self.user_remote_dir: |
234 |
+ |
self.user_remote_dir = "./" |
235 |
|
# add section to storage_path if exist in crab.cfg |
236 |
|
if not self.cfg_params_dataset.has_key("USER.user_remote_dir") and self.user_remote_dir: |
237 |
|
options["-USER.user_remote_dir"]=self.user_remote_dir+"/"+sec |
238 |
+ |
# print options["-USER.user_remote_dir"] |
239 |
+ |
# also for ui_working_dir |
240 |
+ |
if not self.cfg_params_dataset.has_key("USER.ui_working_dir") and self.ui_working_dir: |
241 |
+ |
options["-USER.ui_working_dir"]=self.ui_working_dir+"/"+sec |
242 |
+ |
# if ui_working_dir is set, change -c dir accordnigly |
243 |
+ |
if self.flag_continue: |
244 |
+ |
options['-c']=self.ui_working_dir+"/"+sec |
245 |
+ |
|
246 |
+ |
# also for logDir |
247 |
+ |
if not self.cfg_params_dataset.has_key("USER.logdir") and self.logdir: |
248 |
+ |
options["-USER.logdir"]=self.logdir+"/"+sec |
249 |
+ |
# also for outputdir |
250 |
+ |
if not self.cfg_params_dataset.has_key("USER.outputdir") and self.outputdir: |
251 |
+ |
options["-USER.outputdir"]=self.outputdir+"/"+sec |
252 |
+ |
# also for publish_data_name |
253 |
+ |
if not self.cfg_params_dataset.has_key("USER.publish_data_name") and self.publish_data_name: |
254 |
+ |
options["-USER.publish_data_name"]=self.publish_data_name+"_"+sec |
255 |
+ |
|
256 |
|
# Input options (command) |
257 |
|
for opt in self.opts: |
258 |
< |
options[opt]=self.opts[opt] |
259 |
< |
if self.flag_continue and options.has_key("-cfg"): |
260 |
< |
del options['-cfg'] |
261 |
< |
pass |
262 |
< |
try: |
263 |
< |
crab = Crab(options) |
264 |
< |
crab.run() |
265 |
< |
del crab |
266 |
< |
common.apmon.free() |
267 |
< |
print 'Log file is %s%s.log'%(common.work_space.logDir(),common.prog_name) |
268 |
< |
print '\n############################## E N D ####################################\n' |
269 |
< |
except CrabException, e: |
270 |
< |
print '\n' + common.prog_name + ': ' + str(e) + '\n' |
258 |
> |
if opt != '-c': |
259 |
> |
options[opt]=self.opts[opt] |
260 |
> |
# options[opt]=self.opts[opt] |
261 |
> |
if self.flag_continue and options.has_key("-cfg"): |
262 |
> |
del options['-cfg'] |
263 |
> |
pass |
264 |
> |
|
265 |
> |
# write crab command to be executed later... |
266 |
> |
cmd='crab ' |
267 |
> |
for o in options: |
268 |
> |
if options[o]==None: |
269 |
> |
cmd+=str(o)+' ' |
270 |
> |
else: |
271 |
> |
options[o] = ''.join(options[o].split()) |
272 |
> |
cmd+=str(o)+'='+str(options[o])+' ' |
273 |
|
pass |
274 |
< |
pass |
274 |
> |
cmd+="\n" |
275 |
> |
#print cmd |
276 |
> |
|
277 |
> |
runFile.write(cmd) |
278 |
> |
|
279 |
> |
# SL this does not work for complex, multi include pset.py |
280 |
> |
|
281 |
> |
# crab = Crab() |
282 |
> |
# try: |
283 |
> |
# crab.initialize_(options) |
284 |
> |
# crab.run() |
285 |
> |
# del crab |
286 |
> |
# print 'Log file is %s%s.log'%(common.work_space.logDir(),common.prog_name) |
287 |
> |
# print '\n############################## E N D ####################################\n' |
288 |
> |
# except CrabException, e: |
289 |
> |
# del crab |
290 |
> |
# print '\n' + common.prog_name + ': ' + str(e) + '\n' |
291 |
> |
# pass |
292 |
> |
# pass |
293 |
> |
# if (common.logger): common.logger.delete() |
294 |
|
pass |
295 |
+ |
return self.continue_dir |
296 |
|
|
231 |
– |
#common.apmon.free() |
297 |
|
|
298 |
|
########################################################################### |
299 |
|
if __name__ == '__main__': |
314 |
|
# Create, initialize, and run a Crab object |
315 |
|
try: |
316 |
|
multicrab = MultiCrab(options) |
317 |
< |
multicrab.run() |
317 |
> |
continue_dir = multicrab.run() |
318 |
> |
import os |
319 |
> |
sys.exit(continue_dir) |
320 |
|
except CrabException, e: |
321 |
|
print '\n' + common.prog_name + ': ' + str(e) + '\n' |
322 |
|
|