13 """A singleton holding informations on the whereabouts of all the automatically
14 generated Configurables.
15 This repository of (informations on) Configurables is used by the PropertyProxy
16 class to locate Configurables and feed the JobOptionsSvc. It could also be used
17 to feed the AthenaEmacs module..."""
19 __all__ = [
'CfgDb',
'cfgDb',
'loadConfigurableDb',
'getConfigurable']
23 _transtable = str.maketrans(
'<>&*,: ().',
'__rp__s___')
24 except AttributeError:
26 _transtable = string.maketrans(
'<>&*,: ().',
'__rp__s___')
29 log = logging.getLogger(
'ConfigurableDb')
34 A singleton class holding informations about automatically generated
36 --> package holding that Configurable
37 --> library holding the components related to that Configurable
38 --> python module holding the Configurable
39 --> a dictionary of duplicates
50 def add(self, configurable, package, module, lib):
51 """Method to populate the Db.
52 It is called from the auto-generated Xyz_confDb.py files (genconf.cpp)
53 @param configurable: the name of the configurable being added
54 @param package: the name of the package which holds this Configurable
55 @param module: the name of the python module holding the Configurable
56 @param lib: the name of the library holding the component(s) (ie: the
57 C++ Gaudi component which is mapped by the Configurable)
59 cfg = {
'package': package,
'module': module,
'lib': lib}
60 if configurable
in self:
62 if cfg[
'lib'] != self[configurable][
'lib']:
63 log.debug(
"dup!! [%s] p=%s m=%s lib=%s", configurable, package,
70 log.debug(
"added [%s] p=%s m=%s lib=%s", configurable, package,
72 self[configurable] = cfg
79 for i, ll
in enumerate(f):
81 if l.startswith(
'#')
or len(l) <= 0:
86 pkg = line[0].split(
'.')[0]
89 self.
add(cname, pkg, module, lib)
93 "invalid line format: %s:%d: %r" % (fname, i + 1, ll))
120 """Helper function to load all ConfigurableDb files (modules) holding
121 informations about Configurables
125 from glob
import glob
126 from os.path
import join
as path_join
127 log.debug(
"loading confDb files...")
129 pathlist = os.getenv(
"LD_LIBRARY_PATH",
"").split(os.pathsep)
130 for path
in pathlist:
131 if not os.path.isdir(path):
133 log.debug(
"walking in [%s]...", path)
136 path_join(path, f)
for f
in os.listdir(path)
137 if f.endswith(
'.confdb')
138 ]
if os.path.isfile(f)
141 mergedConfDbFiles = [
142 f
for f
in confDbFiles
if f.endswith(
'_merged.confdb')
144 if mergedConfDbFiles:
146 confDbFiles = mergedConfDbFiles
148 for confDb
in confDbFiles:
149 log.debug(
"\t-loading [%s]...", confDb)
151 cfgDb._loadModule(confDb)
152 except Exception
as err:
153 log.warning(
"Could not load file [%s] !", confDb)
154 log.warning(
"Reason: %s", err)
156 log.debug(
"loading confDb files... [DONE]")
157 nPkgs = len(set([k[
'package']
for k
in cfgDb.values()]))
158 log.debug(
"loaded %i confDb packages", nPkgs)
163 confClass = className
167 confClass = str.translate(confClass, _transtable)
168 except AttributeError:
170 confClass = string.translate(confClass, _transtable)
172 confClassInfo = cfgDb.get(confClass)
173 if not confClassInfo:
174 confClassInfo = cfgDb.get(confClass)
176 confMod = confClassInfo
and confClassInfo.get(
'module')
178 log.warning(
"%s: Class %s not in database", requester, className)
182 mod = __import__(confMod, globals(), locals(), confClass)
184 log.warning(
"%s: Module %s not found (needed for configurable %s)",
185 requester, confMod, className)
189 confClass = getattr(mod, confClass)
190 except AttributeError:
191 log.warning(
"%s: Configurable %s not found in module %s", requester,
195 log.debug(
"%s: Found configurable %s in module %s", requester, confClass,