The Gaudi Framework  v30r3 (a5ef0a68)
__init__.py
Go to the documentation of this file.
1 import os
2 import sys
3 
4 __configurables_module_fullname__ = __name__ + '.Configurables'
5 __ignore_missing_configurables__ = False
6 
7 # Small class that allows to access all the configurables as attributes of the
8 # instance.
9 # Used as module to allow code like
10 # @code
11 # from Gaudi.Configuration import Configurables
12 # Configurables.MyConf()
13 # @endcode
14 
15 
16 class _ConfigurablesModule(object):
17  # Initializes the instance
18  def __init__(self):
19  # If set to true, does not raise an AttributeError if the configurable is not found.
21  self.__name__ = __configurables_module_fullname__
22 
23  def __getattr__(self, name):
24  # trigger the load of the configurables database
25  from Gaudi.Configuration import confDbGetConfigurable, cfgDb
26  from Gaudi.CommonGaudiConfigurables import aliases
27  # return value
28  retval = None
29  # handle the special cases (needed for modules): __all__, __path__
30  if name == "__all__":
31  retval = cfgDb.keys()
32  elif name == "__path__":
33  raise AttributeError("'module' object has no attribute '__path__'")
34  elif name in cfgDb.keys(): # ignore private names
35  retval = confDbGetConfigurable(name)
36  elif name in aliases: # special case of aliases
37  retval = aliases[name]
39  import logging
40  logging.getLogger(__configurables_module_fullname__).warning(
41  'Configurable class %s not in database', name)
42  else:
43  # We raise an AttributeError exception if the configurable could not be found
44  # to respect the Python semantic.
45  raise AttributeError("module '%s' does not have attribute '%s'" % (
46  __configurables_module_fullname__, name))
47  return retval
48 
49 
50 # install the facade module instance as a module
51 Configurables = _ConfigurablesModule()
52 sys.modules[__configurables_module_fullname__] = Configurables
def __getattr__(self, name)
Definition: __init__.py:23