The Gaudi Framework  v36r1 (3e2fb5a8)
GaudiKernel.ProcessJobOptions Namespace Reference

Classes

class  _TempSysPath
 
class  ConsoleHandler
 
class  JobOptsParser
 
class  LogFilter
 
class  LogFormatter
 
class  ParserError
 

Functions

def GetConsoleHandler (prefix=None, stream=None, with_time=False)
 
def InstallRootLoggingHandler (prefix=None, level=None, stream=None, with_time=False)
 
def PrintOn (step=1, force=False)
 
def PrintOff (step=1)
 
def _find_file (f)
 
def _to_be_included (f)
 
def _import_python (file)
 
def _import_pickle (file)
 
def _import_opts (file)
 
def importOptions (optsfile)
 
def importUnits (unitsfile)
 

Variables

 _log = logging.getLogger(__name__)
 
 _consoleHandler = None
 
 _included_files = set()
 
 _parser = JobOptsParser()
 
dictionary _import_function_mapping
 

Function Documentation

◆ _find_file()

def GaudiKernel.ProcessJobOptions._find_file (   f)
private

Definition at line 150 of file ProcessJobOptions.py.

150 def _find_file(f):
151  # expand environment variables in the filename
152  f = os.path.expandvars(f)
153  if os.path.isfile(f):
154  return os.path.realpath(f)
155 
156  path = os.environ.get('JOBOPTSEARCHPATH', '').split(os.pathsep)
157  # find the full path to the option file
158  candidates = [d for d in path if os.path.isfile(os.path.join(d, f))]
159  if not candidates:
160  raise ParserError("Cannot find '%s' in %s" % (f, path))
161  return os.path.realpath(os.path.join(candidates[0], f))
162 
163 

◆ _import_opts()

def GaudiKernel.ProcessJobOptions._import_opts (   file)
private

Definition at line 480 of file ProcessJobOptions.py.

480 def _import_opts(file):
481  _parser.parse(file)
482 
483 

◆ _import_pickle()

def GaudiKernel.ProcessJobOptions._import_pickle (   file)
private

Definition at line 473 of file ProcessJobOptions.py.

473 def _import_pickle(file):
474  import pickle
475  input = open(file, 'rb')
476  catalog = pickle.load(input)
477  _log.info('Unpickled %d configurables', len(catalog))
478 
479 

◆ _import_python()

def GaudiKernel.ProcessJobOptions._import_python (   file)
private

Definition at line 467 of file ProcessJobOptions.py.

467 def _import_python(file):
468  with open(file) as f:
469  code = compile(f.read(), file, 'exec')
470  exec(code, {})
471 
472 

◆ _to_be_included()

def GaudiKernel.ProcessJobOptions._to_be_included (   f)
private

Definition at line 167 of file ProcessJobOptions.py.

167 def _to_be_included(f):
168  if f in _included_files:
169  _log.warning("file '%s' already included, ignored.", f)
170  return False
171  _included_files.add(f)
172  return True
173 
174 

◆ GetConsoleHandler()

def GaudiKernel.ProcessJobOptions.GetConsoleHandler (   prefix = None,
  stream = None,
  with_time = False 
)

Definition at line 116 of file ProcessJobOptions.py.

116 def GetConsoleHandler(prefix=None, stream=None, with_time=False):
117  global _consoleHandler
118  if _consoleHandler is None:
119  _consoleHandler = ConsoleHandler(
120  prefix=prefix, stream=stream, with_time=with_time)
121  elif prefix is not None:
122  _consoleHandler.setPrefix(prefix)
123  return _consoleHandler
124 
125 

◆ importOptions()

def GaudiKernel.ProcessJobOptions.importOptions (   optsfile)

Definition at line 491 of file ProcessJobOptions.py.

491 def importOptions(optsfile):
492  # expand environment variables before checking the extension
493  optsfile = os.path.expandvars(optsfile)
494  # check the file type (extension)
495  dummy, ext = os.path.splitext(optsfile)
496  if ext in _import_function_mapping:
497  # check if the file has been already included
498  optsfile = _find_file(optsfile)
499  if _to_be_included(optsfile):
500  _log.info("--> Including file '%s'", optsfile)
501  # include the file
502  _import_function_mapping[ext](optsfile)
503  _log.info("<-- End of file '%s'", optsfile)
504  else:
505  raise ParserError("Unknown file type '%s' ('%s')" % (ext, optsfile))
506 
507 
508 # Import a file containing declaration of units.
509 # It is equivalent to:
510 #
511 # #units "unitsfile.opts"
512 #
513 
514 

◆ importUnits()

def GaudiKernel.ProcessJobOptions.importUnits (   unitsfile)

Definition at line 515 of file ProcessJobOptions.py.

515 def importUnits(unitsfile):
516  # expand environment variables
517  unitsfile = os.path.expandvars(unitsfile)
518  # we do not need to check the file type (extension) because it must be a
519  # units file
520  _parser._include(unitsfile, _parser._parse_units)

◆ InstallRootLoggingHandler()

def GaudiKernel.ProcessJobOptions.InstallRootLoggingHandler (   prefix = None,
  level = None,
  stream = None,
  with_time = False 
)

Definition at line 126 of file ProcessJobOptions.py.

126 def InstallRootLoggingHandler(prefix=None,
127  level=None,
128  stream=None,
129  with_time=False):
130  root_logger = logging.getLogger()
131  if not root_logger.handlers:
132  root_logger.addHandler(GetConsoleHandler(prefix, stream, with_time))
133  root_logger.setLevel(logging.WARNING)
134  if level is not None:
135  root_logger.setLevel(level)
136 
137 

◆ PrintOff()

def GaudiKernel.ProcessJobOptions.PrintOff (   step = 1)

Definition at line 142 of file ProcessJobOptions.py.

142 def PrintOff(step=1):
143  GetConsoleHandler().printOff(step)
144 
145 

◆ PrintOn()

def GaudiKernel.ProcessJobOptions.PrintOn (   step = 1,
  force = False 
)

Definition at line 138 of file ProcessJobOptions.py.

138 def PrintOn(step=1, force=False):
139  GetConsoleHandler().printOn(step, force)
140 
141 

Variable Documentation

◆ _consoleHandler

GaudiKernel.ProcessJobOptions._consoleHandler = None
private

Definition at line 113 of file ProcessJobOptions.py.

◆ _import_function_mapping

dictionary GaudiKernel.ProcessJobOptions._import_function_mapping
private
Initial value:
1 = {
2  ".py": _import_python,
3  ".pkl": _import_pickle,
4  ".opts": _import_opts,
5 }

Definition at line 484 of file ProcessJobOptions.py.

◆ _included_files

GaudiKernel.ProcessJobOptions._included_files = set()
private

Definition at line 164 of file ProcessJobOptions.py.

◆ _log

GaudiKernel.ProcessJobOptions._log = logging.getLogger(__name__)
private

Definition at line 17 of file ProcessJobOptions.py.

◆ _parser

GaudiKernel.ProcessJobOptions._parser = JobOptsParser()
private

Definition at line 464 of file ProcessJobOptions.py.

GaudiKernel.ProcessJobOptions.GetConsoleHandler
def GetConsoleHandler(prefix=None, stream=None, with_time=False)
Definition: ProcessJobOptions.py:116
GaudiKernel.ProcessJobOptions._import_opts
def _import_opts(file)
Definition: ProcessJobOptions.py:480
GaudiKernel.ProcessJobOptions.importUnits
def importUnits(unitsfile)
Definition: ProcessJobOptions.py:515
GaudiKernel.ProcessJobOptions._find_file
def _find_file(f)
Definition: ProcessJobOptions.py:150
GaudiKernel.ProcessJobOptions._to_be_included
def _to_be_included(f)
Definition: ProcessJobOptions.py:167
GaudiKernel.ProcessJobOptions.InstallRootLoggingHandler
def InstallRootLoggingHandler(prefix=None, level=None, stream=None, with_time=False)
Definition: ProcessJobOptions.py:126
GaudiKernel.ProcessJobOptions.importOptions
def importOptions(optsfile)
Definition: ProcessJobOptions.py:491
GaudiKernel.ProcessJobOptions._import_pickle
def _import_pickle(file)
Definition: ProcessJobOptions.py:473
GaudiKernel.ProcessJobOptions._import_python
def _import_python(file)
Definition: ProcessJobOptions.py:467
GaudiKernel.ProcessJobOptions.PrintOff
def PrintOff(step=1)
Definition: ProcessJobOptions.py:142
GaudiKernel.ProcessJobOptions.PrintOn
def PrintOn(step=1, force=False)
Definition: ProcessJobOptions.py:138