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 |
90 |
|
msg = '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 |
|
|
176 |
|
|
177 |
|
# read crab.cfg file and search for storage_path |
178 |
|
crab_cfg_params = loadConfig(crab_cfg,{}) |
179 |
+ |
# also USER.ui_working_dir USER.outputdir and USER.logdir need special treatment |
180 |
|
if cfg_params.has_key("COMMON"): |
181 |
|
self.user_remote_dir = cfg_params["COMMON"].get("user.user_remote_dir", crab_cfg_params.get("USER.user_remote_dir",None)) |
182 |
+ |
self.outputdir = cfg_params["COMMON"].get("user.outputdir", crab_cfg_params.get("USER.outputdir",None)) |
183 |
+ |
self.logdir = cfg_params["COMMON"].get("user.logdir", crab_cfg_params.get("USER.logdir",None)) |
184 |
+ |
self.ui_working_dir = cfg_params["COMMON"].get("user.ui_working_dir", crab_cfg_params.get("USER.ui_working_dir",None)) |
185 |
+ |
self.publish_data_name = cfg_params["COMMON"].get("user.publish_data_name", crab_cfg_params.get("USER.publish_data_name",None)) |
186 |
|
else: |
187 |
|
self.user_remote_dir = crab_cfg_params.get("USER.user_remote_dir",None) |
188 |
+ |
self.outputdir = crab_cfg_params.get("USER.outputdir",None) |
189 |
+ |
self.logdir = crab_cfg_params.get("USER.logdir",None) |
190 |
+ |
self.ui_working_dir = crab_cfg_params.get("USER.ui_working_dir",None) |
191 |
+ |
self.publish_data_name = crab_cfg_params.get("USER.publish_data_name",None) |
192 |
+ |
|
193 |
|
return |
194 |
|
|
195 |
|
def loadMultiConfig(self, file): |
210 |
|
|
211 |
|
def run(self): |
212 |
|
#run crabs |
213 |
+ |
runFileName = self.continue_dir+'/multicrab.exe' |
214 |
+ |
runFile = open(runFileName,"w") |
215 |
|
for sec in self.cfg_params_dataset: |
216 |
|
options={} |
217 |
|
if self.flag_continue: |
225 |
|
tmp="-"+string.upper(opt.split(".")[0])+"."+opt.split(".")[1] |
226 |
|
|
227 |
|
options[tmp]=self.cfg_params_dataset[sec][opt] |
228 |
+ |
|
229 |
+ |
# check if user_remote_dir is set in multicrab.cfg |
230 |
+ |
# protect against no user_remote_dir |
231 |
+ |
self.user_remote_dir =self.cfg_params_dataset[sec].get("user.user_remote_dir",self.user_remote_dir) |
232 |
+ |
if not self.user_remote_dir: |
233 |
+ |
self.user_remote_dir = "./" |
234 |
|
# add section to storage_path if exist in crab.cfg |
235 |
|
if not self.cfg_params_dataset.has_key("USER.user_remote_dir") and self.user_remote_dir: |
236 |
|
options["-USER.user_remote_dir"]=self.user_remote_dir+"/"+sec |
237 |
+ |
# print options["-USER.user_remote_dir"] |
238 |
+ |
# also for ui_working_dir |
239 |
+ |
if not self.cfg_params_dataset.has_key("USER.ui_working_dir") and self.ui_working_dir: |
240 |
+ |
options["-USER.ui_working_dir"]=self.ui_working_dir+"/"+sec |
241 |
+ |
# if ui_working_dir is set, change -c dir accordnigly |
242 |
+ |
if self.flag_continue: |
243 |
+ |
options['-c']=self.ui_working_dir+"/"+sec |
244 |
+ |
|
245 |
+ |
# also for logDir |
246 |
+ |
if not self.cfg_params_dataset.has_key("USER.logdir") and self.logdir: |
247 |
+ |
options["-USER.logdir"]=self.logdir+"/"+sec |
248 |
+ |
# also for outputdir |
249 |
+ |
if not self.cfg_params_dataset.has_key("USER.outputdir") and self.outputdir: |
250 |
+ |
options["-USER.outputdir"]=self.outputdir+"/"+sec |
251 |
+ |
# also for publish_data_name |
252 |
+ |
if not self.cfg_params_dataset.has_key("USER.publish_data_name") and self.publish_data_name: |
253 |
+ |
options["-USER.publish_data_name"]=self.publish_data_name+"_"+sec |
254 |
+ |
|
255 |
|
# Input options (command) |
256 |
|
for opt in self.opts: |
257 |
< |
options[opt]=self.opts[opt] |
258 |
< |
if self.flag_continue and options.has_key("-cfg"): |
259 |
< |
del options['-cfg'] |
260 |
< |
try: |
261 |
< |
crab = Crab(options) |
219 |
< |
crab.run() |
220 |
< |
common.apmon.free() |
221 |
< |
del crab |
222 |
< |
print '\n############################## E N D ####################################\n' |
223 |
< |
except CrabException, e: |
224 |
< |
print '\n' + common.prog_name + ': ' + str(e) + '\n' |
225 |
< |
if common.logger: |
226 |
< |
common.logger.write('ERROR: '+str(e)+'\n') |
257 |
> |
if opt != '-c': |
258 |
> |
options[opt]=self.opts[opt] |
259 |
> |
# options[opt]=self.opts[opt] |
260 |
> |
if self.flag_continue and options.has_key("-cfg"): |
261 |
> |
del options['-cfg'] |
262 |
|
pass |
263 |
+ |
|
264 |
+ |
# write crab command to be executed later... |
265 |
+ |
cmd='crab ' |
266 |
+ |
for o in options: |
267 |
+ |
if options[o]==None: |
268 |
+ |
cmd+=str(o)+' ' |
269 |
+ |
else: |
270 |
+ |
options[o] = ''.join(options[o].split()) |
271 |
+ |
cmd+=str(o)+'='+str(options[o])+' ' |
272 |
|
pass |
273 |
< |
pass |
273 |
> |
cmd+="\n" |
274 |
> |
#print cmd |
275 |
> |
|
276 |
> |
runFile.write(cmd) |
277 |
> |
|
278 |
> |
# SL this does not work for complex, multi include pset.py |
279 |
> |
|
280 |
> |
# crab = Crab() |
281 |
> |
# try: |
282 |
> |
# crab.initialize_(options) |
283 |
> |
# crab.run() |
284 |
> |
# del crab |
285 |
> |
# print 'Log file is %s%s.log'%(common.work_space.logDir(),common.prog_name) |
286 |
> |
# print '\n############################## E N D ####################################\n' |
287 |
> |
# except CrabException, e: |
288 |
> |
# del crab |
289 |
> |
# print '\n' + common.prog_name + ': ' + str(e) + '\n' |
290 |
> |
# pass |
291 |
> |
# pass |
292 |
> |
# if (common.logger): common.logger.delete() |
293 |
|
pass |
294 |
+ |
return self.continue_dir |
295 |
|
|
232 |
– |
#common.apmon.free() |
296 |
|
|
297 |
|
########################################################################### |
298 |
|
if __name__ == '__main__': |
313 |
|
# Create, initialize, and run a Crab object |
314 |
|
try: |
315 |
|
multicrab = MultiCrab(options) |
316 |
< |
multicrab.run() |
316 |
> |
continue_dir = multicrab.run() |
317 |
> |
import os |
318 |
> |
sys.exit(continue_dir) |
319 |
|
except CrabException, e: |
320 |
|
print '\n' + common.prog_name + ': ' + str(e) + '\n' |
321 |
|
|