| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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