359 def main(argv = None):
362 optParser = optparse.OptionParser()
363 optParser.description =
""" all-in-one alignment Validation
364 This will run various validation procedures either on batch queues or interactviely.
366 If no name is given (-N parameter) a name containing time and date is created automatically
368 To merge the outcome of all validation procedures run TkAlMerge.sh in your validation's directory.
370 optParser.add_option(
"-n",
"--dryRun", dest=
"dryRun", action=
"store_true", default=
False,
371 help=
"create all scripts and cfg File but do not start jobs (default=False)")
372 optParser.add_option(
"--getImages", dest=
"getImages", action=
"store_true", default=
False,
373 help=
"get all Images created during the process (default= False)")
374 defaultConfig =
"TkAlConfig.ini"
375 optParser.add_option(
"-c",
"--config", dest=
"config", default = defaultConfig,
376 help=
"configuration to use (default TkAlConfig.ini) this can be a comma-seperated list of all .ini file you want to merge", metavar=
"CONFIG")
377 optParser.add_option(
"-N",
"--Name", dest=
"Name",
378 help=
"Name of this validation (default: alignmentValidation_DATE_TIME)", metavar=
"NAME")
379 optParser.add_option(
"-r",
"--restrictTo", dest=
"restrictTo",
380 help=
"restrict validations to given modes (comma seperated) (default: no restriction)", metavar=
"RESTRICTTO")
381 optParser.add_option(
"-s",
"--status", dest=
"crabStatus", action=
"store_true", default =
False,
382 help=
"get the status of the crab jobs", metavar=
"STATUS")
383 optParser.add_option(
"-d",
"--debug", dest=
"debugMode", action=
"store_true",
385 help=
"Run the tool to get full traceback of errors.",
388 (options, args) = optParser.parse_args(argv)
390 if not options.restrictTo ==
None:
391 options.restrictTo = options.restrictTo.split(
",")
393 options.config = [ os.path.abspath( iniFile )
for iniFile
in \
394 options.config.split(
"," ) ]
395 config = BetterConfigParser()
396 outputIniFileSet = set( config.read( options.config ) )
397 failedIniFiles = [ iniFile
for iniFile
in options.config
if iniFile
not in outputIniFileSet ]
400 if options.config == [ os.path.abspath( defaultConfig ) ]:
401 if (
not options.crabStatus )
and \
402 (
not os.path.exists( defaultConfig ) ):
403 raise AllInOneError, (
"Default 'ini' file '%s' not found!\n"
404 "You can specify another name with the "
405 "command line option '-c'/'--config'."
408 for iniFile
in failedIniFiles:
409 if not os.path.exists( iniFile ):
410 raise AllInOneError, (
"'%s' does not exist. Please check for "
411 "typos in the filename passed to the "
412 "'-c'/'--config' option!"
415 raise AllInOneError, (
"'%s' does exist, but parsing of the "
419 if options.Name ==
None:
420 if not options.crabStatus:
421 options.Name =
"alignmentValidation_%s"%(datetime.datetime.now().strftime(
"%y%m%d_%H%M%S"))
423 existingValDirs = fnmatch.filter( os.walk(
'.' ).next()[1],
424 "alignmentValidation_*" )
425 if len( existingValDirs ) > 0:
426 options.Name = existingValDirs[-1]
428 print "Cannot guess last working directory!"
429 print (
"Please use the parameter '-N' or '--Name' to specify "
430 "the task for which you want a status report." )
434 outPath = os.path.abspath( options.Name )
437 if options.crabStatus:
439 crabLogDirs = fnmatch.filter( os.walk(
'.').next()[1],
"crab.*" )
440 if len( crabLogDirs ) == 0:
441 print "Found no crab tasks for job name '%s'"%( options.Name )
444 for crabLogDir
in crabLogDirs:
446 print "*" +
"=" * 78 +
"*"
447 print (
"| Status report and output retrieval for:"
448 +
" " * (77 - len(
"Status report and output retrieval for:" ) )
450 taskName = crabLogDir.replace(
"crab.",
"" )
451 print "| " + taskName +
" " * (77 - len( taskName ) ) +
"|"
452 print "*" +
"=" * 78 +
"*"
454 crabOptions = {
"-getoutput":
"",
457 theCrab.run( crabOptions )
458 except AllInOneError, e:
459 print "crab: No output retrieved for this task."
460 crabOptions = {
"-status":
"",
462 theCrab.run( crabOptions )
465 general = config.getGeneral()
466 config.set(
"internals",
"workdir",os.path.join(general[
"workdir"],options.Name) )
467 config.set(
"general",
"datadir",os.path.join(general[
"datadir"],options.Name) )
468 config.set(
"general",
"logdir",os.path.join(general[
"logdir"],options.Name) )
469 config.set(
"general",
"eosdir",os.path.join(
"AlignmentValidation", general[
"eosdir"], options.Name) )
473 if os.path.isdir( outPath ):
474 shutil.rmtree( outPath )
476 if not os.path.exists( outPath ):
477 os.makedirs( outPath )
478 elif not os.path.isdir( outPath ):
479 raise AllInOneError,
"the file %s is in the way rename the Job or move it away"%outPath
485 backupConfigFile = open( os.path.join( outPath,
"usedConfiguration.ini" ) ,
"w" )
486 config.write( backupConfigFile )
489 for validation
in config.items(
"validation"):
490 alignmentList = validation[1].
split(config.getSep())
491 validationsToAdd = [(validation[0],alignment) \
492 for alignment
in alignmentList]
493 validations.extend(validationsToAdd)
495 for validation
in validations ]
496 map(
lambda job: job.createJob(), jobs )
497 validations = [ job.getValidation()
for job
in jobs ]
499 if "OfflineValidationParallel" not in [val.__class__.__name__
for val
in validations]:
505 map(
lambda job: job.runJob(), jobs )