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___")
25 log = logging.getLogger(
"ConfigurableDb")
30 A singleton class holding informations about automatically generated
32 --> package holding that Configurable
33 --> library holding the components related to that Configurable
34 --> python module holding the Configurable
35 --> a dictionary of duplicates
46 def add(self, configurable, package, module, lib):
47 """Method to populate the Db.
48 It is called from the auto-generated Xyz_confDb.py files (genconf.cpp)
49 @param configurable: the name of the configurable being added
50 @param package: the name of the package which holds this Configurable
51 @param module: the name of the python module holding the Configurable
52 @param lib: the name of the library holding the component(s) (ie: the
53 C++ Gaudi component which is mapped by the Configurable)
55 cfg = {
"package": package,
"module": module,
"lib": lib}
56 if configurable
in self:
58 if cfg[
"lib"] != self[configurable][
"lib"]:
60 "dup!! [%s] p=%s m=%s lib=%s", configurable, package, module, lib
67 log.debug(
"added [%s] p=%s m=%s lib=%s", configurable, package, module, lib)
68 self[configurable] = cfg
75 for i, ll
in enumerate(f):
77 if l.startswith(
"#")
or len(l) <= 0:
82 pkg = line[0].split(
".")[0]
85 self.
add(cname, pkg, module, lib)
88 raise Exception(
"invalid line format: %s:%d: %r" % (fname, i + 1, ll))
114 """Helper function to load all ConfigurableDb files (modules) holding
115 informations about Configurables
118 from os.path
import join
as path_join
120 log.debug(
"loading confDb files...")
122 pathlist = os.getenv(
"LD_LIBRARY_PATH",
"").split(os.pathsep)
123 ignored_files = set(os.environ.get(
"CONFIGURABLE_DB_IGNORE",
"").split(
","))
124 for path
in pathlist:
125 if not os.path.isdir(path):
127 log.debug(
"walking in [%s]...", path)
131 path_join(path, f)
for f
in os.listdir(path)
if f.endswith(
".confdb")
133 if os.path.isfile(f)
and f
not in ignored_files
136 mergedConfDbFiles = [f
for f
in confDbFiles
if f.endswith(
"_merged.confdb")]
137 if mergedConfDbFiles:
139 confDbFiles = mergedConfDbFiles
141 for confDb
in confDbFiles:
142 log.debug(
"\t-loading [%s]...", confDb)
144 cfgDb._loadModule(confDb)
145 except Exception
as err:
146 log.warning(
"Could not load file [%s] !", confDb)
147 log.warning(
"Reason: %s", err)
149 log.debug(
"loading confDb files... [DONE]")
150 nPkgs = len(set([k[
"package"]
for k
in cfgDb.values()]))
151 log.debug(
"loaded %i confDb packages", nPkgs)
156 confClass = className
159 confClass = str.translate(confClass, _transtable)
162 confClassInfo = cfgDb.get(confClass)
163 if not confClassInfo:
164 confClassInfo = cfgDb.get(confClass)
166 confMod = confClassInfo
and confClassInfo.get(
"module")
168 log.warning(
"%s: Class %s not in database", requester, className)
172 mod = __import__(confMod, globals(), locals(), confClass)
175 "%s: Module %s not found (needed for configurable %s)",
183 confClass = getattr(mod, confClass)
184 except AttributeError:
186 "%s: Configurable %s not found in module %s", requester, confClass, confMod
190 log.debug(
"%s: Found configurable %s in module %s", requester, confClass, confMod)