388 def main(argv = None):
391 optParser = optparse.OptionParser()
392 optParser.description =
""" all-in-one alignment Validation
393 This will run various validation procedures either on batch queues or interactviely.
395 If no name is given (-N parameter) a name containing time and date is created automatically
397 To merge the outcome of all validation procedures run TkAlMerge.sh in your validation's directory.
399 optParser.add_option(
"-n",
"--dryRun", dest=
"dryRun", action=
"store_true", default=
False,
400 help=
"create all scripts and cfg File but do not start jobs (default=False)")
401 optParser.add_option(
"--getImages", dest=
"getImages", action=
"store_true", default=
False,
402 help=
"get all Images created during the process (default= False)")
403 defaultConfig =
"TkAlConfig.ini"
404 optParser.add_option(
"-c",
"--config", dest=
"config", default = defaultConfig,
405 help=
"configuration to use (default TkAlConfig.ini) this can be a comma-seperated list of all .ini file you want to merge", metavar=
"CONFIG")
406 optParser.add_option(
"-N",
"--Name", dest=
"Name",
407 help=
"Name of this validation (default: alignmentValidation_DATE_TIME)", metavar=
"NAME")
408 optParser.add_option(
"-r",
"--restrictTo", dest=
"restrictTo",
409 help=
"restrict validations to given modes (comma seperated) (default: no restriction)", metavar=
"RESTRICTTO")
410 optParser.add_option(
"-s",
"--status", dest=
"crabStatus", action=
"store_true", default =
False,
411 help=
"get the status of the crab jobs", metavar=
"STATUS")
412 optParser.add_option(
"-d",
"--debug", dest=
"debugMode", action=
"store_true",
414 help=
"Run the tool to get full traceback of errors.",
417 (options, args) = optParser.parse_args(argv)
419 if not options.restrictTo ==
None:
420 options.restrictTo = options.restrictTo.split(
",")
422 options.config = [ os.path.abspath( iniFile )
for iniFile
in \
423 options.config.split(
"," ) ]
424 config = BetterConfigParser()
425 outputIniFileSet = set( config.read( options.config ) )
426 failedIniFiles = [ iniFile
for iniFile
in options.config
if iniFile
not in outputIniFileSet ]
429 if options.config == [ os.path.abspath( defaultConfig ) ]:
430 if (
not options.crabStatus )
and \
431 (
not os.path.exists( defaultConfig ) ):
432 raise AllInOneError, (
"Default 'ini' file '%s' not found!\n"
433 "You can specify another name with the "
434 "command line option '-c'/'--config'."
437 for iniFile
in failedIniFiles:
438 if not os.path.exists( iniFile ):
439 raise AllInOneError, (
"'%s' does not exist. Please check for "
440 "typos in the filename passed to the "
441 "'-c'/'--config' option!"
444 raise AllInOneError, (
"'%s' does exist, but parsing of the "
448 if options.Name ==
None:
449 if not options.crabStatus:
450 options.Name =
"alignmentValidation_%s"%(datetime.datetime.now().strftime(
"%y%m%d_%H%M%S"))
452 existingValDirs = fnmatch.filter( os.walk(
'.' ).
next()[1],
453 "alignmentValidation_*" )
454 if len( existingValDirs ) > 0:
455 options.Name = existingValDirs[-1]
457 print "Cannot guess last working directory!"
458 print (
"Please use the parameter '-N' or '--Name' to specify "
459 "the task for which you want a status report." )
463 outPath = os.path.abspath( options.Name )
466 if options.crabStatus:
468 crabLogDirs = fnmatch.filter( os.walk(
'.').
next()[1],
"crab.*" )
469 if len( crabLogDirs ) == 0:
470 print "Found no crab tasks for job name '%s'"%( options.Name )
473 for crabLogDir
in crabLogDirs:
475 print "*" +
"=" * 78 +
"*"
476 print (
"| Status report and output retrieval for:"
477 +
" " * (77 - len(
"Status report and output retrieval for:" ) )
479 taskName = crabLogDir.replace(
"crab.",
"" )
480 print "| " + taskName +
" " * (77 - len( taskName ) ) +
"|"
481 print "*" +
"=" * 78 +
"*"
483 crabOptions = {
"-getoutput":
"",
486 theCrab.run( crabOptions )
487 except AllInOneError, e:
488 print "crab: No output retrieved for this task."
489 crabOptions = {
"-status":
"",
491 theCrab.run( crabOptions )
494 general = config.getGeneral()
495 config.set(
"internals",
"workdir",os.path.join(general[
"workdir"],options.Name) )
496 config.set(
"general",
"datadir",os.path.join(general[
"datadir"],options.Name) )
497 config.set(
"general",
"logdir",os.path.join(general[
"logdir"],options.Name) )
498 config.set(
"general",
"eosdir",os.path.join(
"AlignmentValidation", general[
"eosdir"], options.Name) )
502 if os.path.isdir( outPath ):
503 shutil.rmtree( outPath )
505 if not os.path.exists( outPath ):
506 os.makedirs( outPath )
507 elif not os.path.isdir( outPath ):
508 raise AllInOneError,
"the file %s is in the way rename the Job or move it away"%outPath
514 backupConfigFile = open( os.path.join( outPath,
"usedConfiguration.ini" ) ,
"w" )
515 config.write( backupConfigFile )
518 for validation
in config.items(
"validation"):
519 alignmentList = validation[1].
split(config.getSep())
520 validationsToAdd = [(validation[0],alignment) \
521 for alignment
in alignmentList]
522 validations.extend(validationsToAdd)
524 for validation
in validations ]
525 map(
lambda job: job.createJob(), jobs )
526 validations = [ job.getValidation()
for job
in jobs ]
528 if "OfflineValidationParallel" not in [val.__class__.__name__
for val
in validations]:
534 map(
lambda job: job.runJob(), jobs )