The Gaudi Framework  master (37c0b60a)
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 _import_dict (data)
 
def _import_json (filename)
 
def _import_yaml (filename)
 
def importOptions (optsfile)
 
def importUnits (unitsfile)
 

Variables

 _log
 
 _consoleHandler
 
 _included_files
 
 _parser
 
 _import_function_mapping
 

Function Documentation

◆ _find_file()

def GaudiKernel.ProcessJobOptions._find_file (   f)
private

Definition at line 149 of file ProcessJobOptions.py.

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

◆ _import_dict()

def GaudiKernel.ProcessJobOptions._import_dict (   data)
private

Definition at line 501 of file ProcessJobOptions.py.

501 def _import_dict(data):
502  from GaudiKernel.Proxy.Configurable import Configurable, ConfigurableGeneric
503 
504  for property, value_repr in data.items():
505  component, property = property.rsplit(".", 1)
506  if component in Configurable.allConfigurables:
507  cfg = Configurable.allConfigurables[component]
508  else:
509  cfg = ConfigurableGeneric(component)
510  value = eval(value_repr)
511  setattr(cfg, property, value)
512 
513 

◆ _import_json()

def GaudiKernel.ProcessJobOptions._import_json (   filename)
private

Definition at line 514 of file ProcessJobOptions.py.

514 def _import_json(filename):
515  import json
516 
517  with open(filename) as f:
518  _import_dict(json.load(f))
519 
520 

◆ _import_opts()

def GaudiKernel.ProcessJobOptions._import_opts (   file)
private

Definition at line 497 of file ProcessJobOptions.py.

497 def _import_opts(file):
498  _parser.parse(file)
499 
500 

◆ _import_pickle()

def GaudiKernel.ProcessJobOptions._import_pickle (   file)
private

Definition at line 489 of file ProcessJobOptions.py.

489 def _import_pickle(file):
490  import pickle
491 
492  input = open(file, "rb")
493  catalog = pickle.load(input)
494  _log.info("Unpickled %d configurables", len(catalog))
495 
496 

◆ _import_python()

def GaudiKernel.ProcessJobOptions._import_python (   file)
private

Definition at line 483 of file ProcessJobOptions.py.

483 def _import_python(file):
484  with open(file) as f:
485  code = compile(f.read(), file, "exec")
486  exec(code, {"__file__": file})
487 
488 

◆ _import_yaml()

def GaudiKernel.ProcessJobOptions._import_yaml (   filename)
private

Definition at line 531 of file ProcessJobOptions.py.

531  def _import_yaml(filename):
532  with open(filename) as f:
533  _import_dict(yaml.safe_load(f))
534 

◆ _to_be_included()

def GaudiKernel.ProcessJobOptions._to_be_included (   f)
private

Definition at line 166 of file ProcessJobOptions.py.

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

◆ GetConsoleHandler()

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

Definition at line 117 of file ProcessJobOptions.py.

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

◆ importOptions()

def GaudiKernel.ProcessJobOptions.importOptions (   optsfile)

Definition at line 541 of file ProcessJobOptions.py.

541 def importOptions(optsfile):
542  # expand environment variables before checking the extension
543  optsfile = os.path.expandvars(optsfile)
544  # check the file type (extension)
545  dummy, ext = os.path.splitext(optsfile)
546  if ext in _import_function_mapping:
547  # check if the file has been already included
548  optsfile = _find_file(optsfile)
549  if _to_be_included(optsfile):
550  _log.info("--> Including file '%s'", optsfile)
551  # include the file
552  _import_function_mapping[ext](optsfile)
553  _log.info("<-- End of file '%s'", optsfile)
554  else:
555  raise ParserError("Unknown file type '%s' ('%s')" % (ext, optsfile))
556 
557 
558 # Import a file containing declaration of units.
559 # It is equivalent to:
560 #
561 # #units "unitsfile.opts"
562 #
563 
564 

◆ importUnits()

def GaudiKernel.ProcessJobOptions.importUnits (   unitsfile)

Definition at line 565 of file ProcessJobOptions.py.

565 def importUnits(unitsfile):
566  # expand environment variables
567  unitsfile = os.path.expandvars(unitsfile)
568  # we do not need to check the file type (extension) because it must be a
569  # units file
570  _parser._include(unitsfile, _parser._parse_units)

◆ InstallRootLoggingHandler()

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

Definition at line 128 of file ProcessJobOptions.py.

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

◆ PrintOff()

def GaudiKernel.ProcessJobOptions.PrintOff (   step = 1)

Definition at line 141 of file ProcessJobOptions.py.

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

◆ PrintOn()

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

Definition at line 137 of file ProcessJobOptions.py.

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

Variable Documentation

◆ _consoleHandler

GaudiKernel.ProcessJobOptions._consoleHandler
private

Definition at line 114 of file ProcessJobOptions.py.

◆ _import_function_mapping

GaudiKernel.ProcessJobOptions._import_function_mapping
private

Definition at line 521 of file ProcessJobOptions.py.

◆ _included_files

GaudiKernel.ProcessJobOptions._included_files
private

Definition at line 163 of file ProcessJobOptions.py.

◆ _log

GaudiKernel.ProcessJobOptions._log
private

Definition at line 17 of file ProcessJobOptions.py.

◆ _parser

GaudiKernel.ProcessJobOptions._parser
private

Definition at line 480 of file ProcessJobOptions.py.

GaudiKernel.ProcessJobOptions.GetConsoleHandler
def GetConsoleHandler(prefix=None, stream=None, with_time=False)
Definition: ProcessJobOptions.py:117
GaudiKernel.ProcessJobOptions._import_dict
def _import_dict(data)
Definition: ProcessJobOptions.py:501
GaudiKernel.ProcessJobOptions._import_opts
def _import_opts(file)
Definition: ProcessJobOptions.py:497
GaudiKernel.ProcessJobOptions.importUnits
def importUnits(unitsfile)
Definition: ProcessJobOptions.py:565
GaudiKernel.ProcessJobOptions._find_file
def _find_file(f)
Definition: ProcessJobOptions.py:149
GaudiKernel.ProcessJobOptions._to_be_included
def _to_be_included(f)
Definition: ProcessJobOptions.py:166
GaudiKernel.ProcessJobOptions._import_yaml
def _import_yaml(filename)
Definition: ProcessJobOptions.py:531
GaudiKernel.ProcessJobOptions._import_json
def _import_json(filename)
Definition: ProcessJobOptions.py:514
GaudiKernel.ProcessJobOptions.InstallRootLoggingHandler
def InstallRootLoggingHandler(prefix=None, level=None, stream=None, with_time=False)
Definition: ProcessJobOptions.py:128
GaudiKernel.ProcessJobOptions.importOptions
def importOptions(optsfile)
Definition: ProcessJobOptions.py:541
GaudiKernel.ProcessJobOptions._import_pickle
def _import_pickle(file)
Definition: ProcessJobOptions.py:489
GaudiKernel.ProcessJobOptions._import_python
def _import_python(file)
Definition: ProcessJobOptions.py:483
GaudiKernel.ProcessJobOptions.PrintOff
def PrintOff(step=1)
Definition: ProcessJobOptions.py:141
GaudiKernel.ProcessJobOptions.PrintOn
def PrintOn(step=1, force=False)
Definition: ProcessJobOptions.py:137