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