## autoconfiguration is (attempted to be) performed ## @author Sebastien Binet <*****@*****.**> __version__ = "$Revision$" __author__ = "Sebastien Binet <*****@*****.**>" __doc__ = """take a bunch of input pool files and produce a single one. autoconfiguration is (attempted to be) performed """ import sys import os if __name__ == "__main__": from PyUtils.Logging import logging msg = logging.getLogger('pool-merge') msg.setLevel(logging.INFO) from optparse import OptionParser parser = OptionParser( usage="usage: %prog [-o] out.merged.pool f1.pool f2.pool [...]") p = parser.add_option p("-o", "--output", dest="outfname", default=None, help="Name of the merged output POOL file") p("--evts", dest="evts", default=-1, help="Number of events to process (default: %default)")
cfg.has_option('summary', 'AtlasProject')): try: v = cfg.get('summary', 'AtlasProject') v = v.lower() if v.startswith('atlas'): v = v[len('atlas'):] runTimePkg = v log.info('taking runtime package [%s] from .asetup.save', runTimePkg) except Exception, err: log.info('got this non-fatal parsing error:\n%s' % err) log.info('taking runtime package [AtlasOffline] by default') runTimePkg = None # offline else: # take it from env-var AtlasProject runTimePkg = None # 'offline' return workAreas, installDir, runTimePkg, suppressList if __name__ == "__main__": msg = logging.getLogger('WorkAreaMgr') msg.setLevel(logging.INFO) ## process user options workAreas, installDir, \ runTimePkg, suppressList = _processOptions( _useropts, _userlongopts ) createWorkArea( workAreas, installDir, runTimePkg, suppressList ) pass
def _processOptions( useropts, userlongopts ): log = logging.getLogger("WorkAreaMgr") runTimePkgAllowedValues = [ "core", "event", "conditions", "simulation", "reconstruction", "trigger", "analysis", "production", "point1", "tier0", "hlt", "offline", "manacore", ] # defaults workAreas = [] installDir = None runTimePkg = None # --> "offline" or what is in .asetup.save's [summary:AtlasProject] suppressList = [] lvl = logging.INFO try: optlist,args = getopt.getopt( sys.argv[1:], useropts, userlongopts ) except getopt.error: log.error( "%s" % sys.exc_value ) _usage() sys.exit(2) for opt, arg in optlist: if opt in ('-h', '--help' ): _usage() sys.exit() elif opt in ('-v', '--version'): print WORKAREA_VERSION print "By Sebastien Binet" sys.exit() elif opt in ('-i', '--install-dir'): installDir = os.path.expanduser( os.path.expandvars(arg) ) elif opt in ('-s', '--suppress-list'): exec( 'suppressList += %s' % arg ) #suppressList = arg elif opt in ('-S', '--suppress-file'): suppressFileName = os.path.expanduser( os.path.expandvars(arg) ) if os.path.exists( suppressFileName ): suppressFile = open( suppressFileName, 'r' ) for line in suppressFile.readlines(): for l in line.splitlines(): suppressList.append( l.strip() ) pass pass pass else: log.error("Could NOT access this file [%s]" % suppressFileName) pass elif opt in ('-w', '--work-area'): workAreaDirs = os.path.expanduser( os.path.expandvars(arg) ) if workAreaDirs.count(os.pathsep) > 0: workAreaDirs = workAreaDirs.split(os.pathsep) pass for workAreaDir in workAreaDirs: if os.path.exists( workAreaDir ): if os.access(workAreaDir, os.R_OK): workAreas.append( os.path.abspath(workAreaDir) ) pass else: log.error( "Can't read from [%s] !!" % workAreaDir ) pass pass else: log.error("Directory does NOT exists [%s] !" % workAreaDir) pass pass elif opt in ('-g', '--group-area'): if len(arg) == 0: arg = os.environ.get("GroupArea") or "" pass groupAreaDirs = os.path.expanduser( os.path.expandvars(arg) ) if groupAreaDirs.count(os.pathsep) > 0: groupAreaDirs = groupAreaDirs.split(os.pathsep) pass for groupAreaDir in groupAreaDirs: if os.path.exists( groupAreaDir ): if os.access(groupAreaDir, os.R_OK): workAreas.append( groupAreaDir ) pass else: log.error( "Can't read from [%s] !!" % groupAreaDir ) pass pass else: log.error("Directory does NOT exists [%s] !" % groupAreaDir) pass pass elif opt in ('-r', '--runtime'): if arg.lower() in runTimePkgAllowedValues: runTimePkg = arg else: log.error( "Unknown runtime package [%s]" % arg ) log.error( "Must be one of: %s" % str(runTimePkgAllowedValues) ) pass elif opt in ('-l', '--loglevel'): lvl = string.upper( arg ) logLevel = getattr(logging, lvl) log.setLevel(logLevel) del lvl,logLevel pass else: pass pass if runTimePkg is None: # try to get it from .asetup.save if os.path.exists('.asetup.save'): import ConfigParser as _cp cfg = _cp.SafeConfigParser() try: cfg.read(['.asetup.save']) except _cp.ParsingError, err: log.info('got these non-fatal parsing errors:\n%s' % err) if (cfg.has_section('summary') and cfg.has_option('summary', 'AtlasProject')): try: v = cfg.get('summary', 'AtlasProject') v = v.lower() if v.startswith('atlas'): v = v[len('atlas'):] runTimePkg = v log.info('taking runtime package [%s] from .asetup.save', runTimePkg) except Exception, err: log.info('got this non-fatal parsing error:\n%s' % err) log.info('taking runtime package [AtlasOffline] by default') runTimePkg = None # offline
def _processOptions(useropts, userlongopts): log = logging.getLogger("WorkAreaMgr") runTimePkgAllowedValues = [ "core", "event", "conditions", "simulation", "reconstruction", "trigger", "analysis", "production", "point1", "tier0", "hlt", "offline", ] # defaults workAreas = [] installDir = None runTimePkg = "offline" suppressList = [] lvl = logging.INFO try: optlist, args = getopt.getopt(sys.argv[1:], useropts, userlongopts) except getopt.error: log.error("%s" % sys.exc_value) _usage() sys.exit(2) for opt, arg in optlist: if opt in ('-h', '--help'): _usage() sys.exit() elif opt in ('-v', '--version'): print WORKAREA_VERSION print "By Sebastien Binet" sys.exit() elif opt in ('-i', '--install-dir'): installDir = os.path.expanduser(os.path.expandvars(arg)) elif opt in ('-s', '--suppress-list'): exec('suppressList += %s' % arg) #suppressList = arg elif opt in ('-S', '--suppress-file'): suppressFileName = os.path.expanduser(os.path.expandvars(arg)) if os.path.exists(suppressFileName): suppressFile = open(suppressFileName, 'r') for line in suppressFile.readlines(): for l in line.splitlines(): suppressList.append(l.strip()) pass pass pass else: log.error("Could NOT access this file [%s]" % suppressFileName) pass elif opt in ('-w', '--work-area'): workAreaDirs = os.path.expanduser(os.path.expandvars(arg)) if workAreaDirs.count(os.pathsep) > 0: workAreaDirs = workAreaDirs.split(os.pathsep) pass for workAreaDir in workAreaDirs: if os.path.exists(workAreaDir): if os.access(workAreaDir, os.R_OK): workAreas.append(os.path.abspath(workAreaDir)) pass else: log.error("Can't read from [%s] !!" % workAreaDir) pass pass else: log.error("Directory does NOT exists [%s] !" % workAreaDir) pass pass elif opt in ('-g', '--group-area'): if len(arg) == 0: arg = os.environ.get("GroupArea") or "" pass groupAreaDirs = os.path.expanduser(os.path.expandvars(arg)) if groupAreaDirs.count(os.pathsep) > 0: groupAreaDirs = groupAreaDirs.split(os.pathsep) pass for groupAreaDir in groupAreaDirs: if os.path.exists(groupAreaDir): if os.access(groupAreaDir, os.R_OK): workAreas.append(groupAreaDir) pass else: log.error("Can't read from [%s] !!" % groupAreaDir) pass pass else: log.error("Directory does NOT exists [%s] !" % groupAreaDir) pass pass elif opt in ('-r', '--runtime'): if arg.lower() in runTimePkgAllowedValues: runTimePkg = arg else: log.error("Unknown runtime package [%s]" % arg) log.error("Must be one of: %s" % str(runTimePkgAllowedValues)) pass elif opt in ('-l', '--loglevel'): lvl = string.upper(arg) logLevel = getattr(logging, lvl) log.setLevel(logLevel) del lvl, logLevel pass else: pass pass return workAreas, installDir, runTimePkg, suppressList