350 optParser = optparse.OptionParser()
351 optParser.description =
"""All-in-one Alignment Validation. 352 This will run various validation procedures either on batch queues or interactively. 353 If no name is given (-N parameter) a name containing time and date is created automatically. 354 To merge the outcome of all validation procedures run TkAlMerge.sh in your validation's directory. 356 optParser.add_option(
"-n",
"--dryRun", dest=
"dryRun", action=
"store_true", default=
False,
357 help=
"create all scripts and cfg File but do not start jobs (default=False)")
358 optParser.add_option(
"--getImages", dest=
"getImages", action=
"store_true", default=
True,
359 help=
"get all Images created during the process (default= True)")
360 defaultConfig =
"TkAlConfig.ini" 361 optParser.add_option(
"-c",
"--config", dest=
"config", default = defaultConfig,
362 help=
"configuration to use (default TkAlConfig.ini) this can be a comma-seperated list of all .ini file you want to merge", metavar=
"CONFIG")
363 optParser.add_option(
"-N",
"--Name", dest=
"Name",
364 help=
"Name of this validation (default: alignmentValidation_DATE_TIME)", metavar=
"NAME")
365 optParser.add_option(
"-r",
"--restrictTo", dest=
"restrictTo",
366 help=
"restrict validations to given modes (comma seperated) (default: no restriction)", metavar=
"RESTRICTTO")
367 optParser.add_option(
"-s",
"--status", dest=
"crabStatus", action=
"store_true", default =
False,
368 help=
"get the status of the crab jobs", metavar=
"STATUS")
369 optParser.add_option(
"-d",
"--debug", dest=
"debugMode", action=
"store_true",
371 help=
"run the tool to get full traceback of errors",
373 optParser.add_option(
"-m",
"--autoMerge", dest=
"autoMerge", action=
"store_true", default =
False,
374 help=
"submit TkAlMerge.sh to run automatically when all jobs have finished (default=False)." 375 " Works only for batch jobs")
377 (options, args) = optParser.parse_args(argv)
379 if not options.restrictTo ==
None:
380 options.restrictTo = options.restrictTo.split(
",")
382 options.config = [ os.path.abspath( iniFile )
for iniFile
in \
383 options.config.split(
"," ) ]
384 config = BetterConfigParser()
385 outputIniFileSet = set( config.read( options.config ) )
386 failedIniFiles = [ iniFile
for iniFile
in options.config
if iniFile
not in outputIniFileSet ]
389 if options.config == [ os.path.abspath( defaultConfig ) ]:
390 if (
not options.crabStatus )
and \
391 (
not os.path.exists( defaultConfig ) ):
392 raise AllInOneError(
"Default 'ini' file '%s' not found!\n" 393 "You can specify another name with the " 394 "command line option '-c'/'--config'." 397 for iniFile
in failedIniFiles:
398 if not os.path.exists( iniFile ):
399 raise AllInOneError(
"'%s' does not exist. Please check for " 400 "typos in the filename passed to the " 401 "'-c'/'--config' option!" 404 raise AllInOneError((
"'%s' does exist, but parsing of the " 405 "content failed!" ) % iniFile)
408 if options.Name ==
None:
409 if not options.crabStatus:
410 options.Name =
"alignmentValidation_%s"%(datetime.datetime.now().strftime(
"%y%m%d_%H%M%S"))
412 existingValDirs = fnmatch.filter( os.walk(
'.' ).
next()[1],
413 "alignmentValidation_*" )
414 if len( existingValDirs ) > 0:
415 options.Name = existingValDirs[-1]
417 print "Cannot guess last working directory!" 418 print (
"Please use the parameter '-N' or '--Name' to specify " 419 "the task for which you want a status report." )
423 outPath = os.path.abspath( options.Name )
426 if options.crabStatus:
428 crabLogDirs = fnmatch.filter( os.walk(
'.').
next()[1],
"crab.*" )
429 if len( crabLogDirs ) == 0:
430 print "Found no crab tasks for job name '%s'"%( options.Name )
433 for crabLogDir
in crabLogDirs:
435 print "*" +
"=" * 78 +
"*" 436 print (
"| Status report and output retrieval for:" 437 +
" " * (77 - len(
"Status report and output retrieval for:" ) )
439 taskName = crabLogDir.replace(
"crab.",
"" )
440 print "| " + taskName +
" " * (77 - len( taskName ) ) +
"|" 441 print "*" +
"=" * 78 +
"*" 443 crabOptions = {
"-getoutput":
"",
446 theCrab.run( crabOptions )
447 except AllInOneError
as e:
448 print "crab: No output retrieved for this task." 449 crabOptions = {
"-status":
"",
451 theCrab.run( crabOptions )
454 general = config.getGeneral()
455 config.set(
"internals",
"workdir",os.path.join(general[
"workdir"],options.Name) )
456 config.set(
"internals",
"scriptsdir",outPath)
457 config.set(
"general",
"datadir",os.path.join(general[
"datadir"],options.Name) )
458 config.set(
"general",
"logdir",os.path.join(general[
"logdir"],options.Name) )
459 config.set(
"general",
"eosdir",os.path.join(
"AlignmentValidation", general[
"eosdir"], options.Name) )
461 if not os.path.exists( outPath ):
462 os.makedirs( outPath )
463 elif not os.path.isdir( outPath ):
464 raise AllInOneError(
"the file %s is in the way rename the Job or move it away"%outPath)
470 backupConfigFile = open( os.path.join( outPath,
"usedConfiguration.ini" ) ,
"w" )
471 config.write( backupConfigFile )
480 shutil.copyfile(
getCommandOutput2(
"voms-proxy-info --path").
strip(), os.path.join(outPath,
".user_proxy"))
483 for validation
in config.items(
"validation"):
484 alignmentList = [validation[1]]
485 validationsToAdd = [(validation[0],alignment) \
486 for alignment
in alignmentList]
487 validations.extend(validationsToAdd)
489 for validation
in validations ]
491 if job.needsproxy
and not proxyexists:
492 raise AllInOneError(
"At least one job needs a grid proxy, please init one.")
493 map(
lambda job: job.createJob(), jobs )
494 validations = [ job.getValidation()
for job
in jobs ]
499 map(
lambda job: job.runJob(), jobs )
501 if options.autoMerge:
504 if ValidationJob.jobCount == ValidationJob.batchCount
and config.getGeneral()[
"jobmode"].
split(
",")[0] ==
"lxBatch":
505 print "> Automatically merging jobs when they have ended" 507 "commands": config.getGeneral()[
"jobmode"].
split(
",")[1],
508 "jobName":
"TkAlMerge",
509 "logDir": config.getGeneral()[
"logdir"],
510 "script":
"TkAlMerge.sh",
511 "bsub":
"/afs/cern.ch/cms/caf/scripts/cmsbsub",
512 "conditions":
'"' +
" && ".
join([
"ended(" + jobId +
")" for jobId
in ValidationJob.batchJobIds]) +
'"' 514 for ext
in (
"stdout",
"stderr",
"stdout.gz",
"stderr.gz"):
515 oldlog =
"%(logDir)s/%(jobName)s."%repMap + ext
516 if os.path.exists(oldlog):
520 "-o %(logDir)s/%(jobName)s.stdout " 521 "-e %(logDir)s/%(jobName)s.stderr " 523 "%(logDir)s/%(script)s"%repMap)
— Classes —############################
def main(argv=None)
— Main —############################
def loadTemplates(config)
def createMergeScript(path, validations)
def getCommandOutput2(command)
static std::string join(char **cmd)