346 def main(argv = None):
349 optParser = optparse.OptionParser()
350 optParser.description =
""" all-in-one alignment Validation
351 This will run various validation procedures either on batch queues or interactviely.
353 If no name is given (-N parameter) a name containing time and date is created automatically
355 To merge the outcome of all validation procedures run TkAlMerge.sh in your validation's directory.
357 optParser.add_option(
"-n",
"--dryRun", dest=
"dryRun", action=
"store_true", default=
False,
358 help=
"create all scripts and cfg File but do not start jobs (default=False)")
359 optParser.add_option(
"--getImages", dest=
"getImages", action=
"store_true", default=
False,
360 help=
"get all Images created during the process (default= False)")
361 defaultConfig =
"TkAlConfig.ini"
362 optParser.add_option(
"-c",
"--config", dest=
"config", default = defaultConfig,
363 help=
"configuration to use (default TkAlConfig.ini) this can be a comma-seperated list of all .ini file you want to merge", metavar=
"CONFIG")
364 optParser.add_option(
"-N",
"--Name", dest=
"Name",
365 help=
"Name of this validation (default: alignmentValidation_DATE_TIME)", metavar=
"NAME")
366 optParser.add_option(
"-r",
"--restrictTo", dest=
"restrictTo",
367 help=
"restrict validations to given modes (comma seperated) (default: no restriction)", metavar=
"RESTRICTTO")
368 optParser.add_option(
"-s",
"--status", dest=
"crabStatus", action=
"store_true", default =
False,
369 help=
"get the status of the crab jobs", metavar=
"STATUS")
370 optParser.add_option(
"-d",
"--debug", dest=
"debugMode", action=
"store_true",
372 help=
"Run the tool to get full traceback of errors.",
375 (options, args) = optParser.parse_args(argv)
377 if not options.restrictTo ==
None:
378 options.restrictTo = options.restrictTo.split(
",")
380 options.config = [ os.path.abspath( iniFile )
for iniFile
in \
381 options.config.split(
"," ) ]
382 config = BetterConfigParser()
383 outputIniFileSet = set( config.read( options.config ) )
384 failedIniFiles = [ iniFile
for iniFile
in options.config
if iniFile
not in outputIniFileSet ]
387 if options.config == [ os.path.abspath( defaultConfig ) ]:
388 if (
not options.crabStatus )
and \
389 (
not os.path.exists( defaultConfig ) ):
390 raise AllInOneError, (
"Default 'ini' file '%s' not found!\n"
391 "You can specify another name with the "
392 "command line option '-c'/'--config'."
395 for iniFile
in failedIniFiles:
396 if not os.path.exists( iniFile ):
397 raise AllInOneError, (
"'%s' does not exist. Please check for "
398 "typos in the filename passed to the "
399 "'-c'/'--config' option!"
402 raise AllInOneError, (
"'%s' does exist, but parsing of the "
406 if options.Name ==
None:
407 if not options.crabStatus:
408 options.Name =
"alignmentValidation_%s"%(datetime.datetime.now().strftime(
"%y%m%d_%H%M%S"))
410 existingValDirs = fnmatch.filter( os.walk(
'.' ).next()[1],
411 "alignmentValidation_*" )
412 if len( existingValDirs ) > 0:
413 options.Name = existingValDirs[-1]
415 print "Cannot guess last working directory!"
416 print (
"Please use the parameter '-N' or '--Name' to specify "
417 "the task for which you want a status report." )
421 outPath = os.path.abspath( options.Name )
424 if options.crabStatus:
426 crabLogDirs = fnmatch.filter( os.walk(
'.').next()[1],
"crab.*" )
427 if len( crabLogDirs ) == 0:
428 print "Found no crab tasks for job name '%s'"%( options.Name )
431 for crabLogDir
in crabLogDirs:
433 print "*" +
"=" * 78 +
"*"
434 print (
"| Status report and output retrieval for:"
435 +
" " * (77 - len(
"Status report and output retrieval for:" ) )
437 taskName = crabLogDir.replace(
"crab.",
"" )
438 print "| " + taskName +
" " * (77 - len( taskName ) ) +
"|"
439 print "*" +
"=" * 78 +
"*"
441 crabOptions = {
"-getoutput":
"",
444 theCrab.run( crabOptions )
445 except AllInOneError, e:
446 print "crab: No output retrieved for this task."
447 crabOptions = {
"-status":
"",
449 theCrab.run( crabOptions )
452 general = config.getGeneral()
453 config.set(
"internals",
"workdir",os.path.join(general[
"workdir"],options.Name) )
454 config.set(
"general",
"datadir",os.path.join(general[
"datadir"],options.Name) )
455 config.set(
"general",
"logdir",os.path.join(general[
"logdir"],options.Name) )
456 config.set(
"general",
"eosdir",os.path.join(
"AlignmentValidation", general[
"eosdir"], options.Name) )
460 if os.path.isdir( outPath ):
461 shutil.rmtree( outPath )
463 if not os.path.exists( outPath ):
464 os.makedirs( outPath )
465 elif not os.path.isdir( outPath ):
466 raise AllInOneError,
"the file %s is in the way rename the Job or move it away"%outPath
472 backupConfigFile = open( os.path.join( outPath,
"usedConfiguration.ini" ) ,
"w" )
473 config.write( backupConfigFile )
476 for validation
in config.items(
"validation"):
477 alignmentList = validation[1].
split(config.getSep())
478 validationsToAdd = [(validation[0],alignment) \
479 for alignment
in alignmentList]
480 validations.extend(validationsToAdd)
482 for validation
in validations ]
483 map(
lambda job: job.createJob(), jobs )
484 validations = [ job.getValidation()
for job
in jobs ]
486 if "OfflineValidationParallel" not in [val.__class__.__name__
for val
in validations]:
492 map(
lambda job: job.runJob(), jobs )