29 logging.VERBOSE, msg, *args, **kwargs
54 Equivalent to GaudiKernel.ConfigurableDb.loadConfigurableDb(), but does a
55 deep search and executes the '*.confdb' files instead of importing them.
57 log = GaudiKernel.ConfigurableDb.log
58 from os.path
import join
as path_join
60 from GaudiPluginService.cpluginsvc
import GAUDI_DEFAULT_PLUGIN_PATH
67 f
for f
in glob(path_join(path,
"*",
"*.confdb"))
if os.path.isfile(f)
71 for root, _, files
in os.walk(build_dir):
73 os.path.join(root, f)
for f
in files
if f.endswith(
".confdb")
76 for path
in filter(os.path.isdir, GAUDI_DEFAULT_PLUGIN_PATH):
80 path_join(path, f)
for f
in os.listdir(path)
if f.endswith(
".confdb")
84 ignored_files = set(os.environ.get(
"CONFIGURABLE_DB_IGNORE",
"").split(
","))
86 for confDb
in set(confDbFiles):
87 if confDb
in ignored_files
or (
88 project_name
and os.path.basename(confDb) == (f
"{project_name}.confdb")
91 log.debug(
"\t-ignoring [%s]", confDb)
93 ignored_files.add(confDb)
95 log.debug(
"\t-loading [%s]...", confDb)
97 cfgDb._loadModule(confDb)
98 except Exception
as err:
101 log.warning(
"Could not load file [%s] !", confDb)
102 log.warning(
"Reason: %s", err)
105 os.environ[
"CONFIGURABLE_DB_IGNORE"] =
",".join(ignored_files)
111 Find in the module 'modulename' all the classes that derive from ConfigurableUser.
112 Return the list of the names.
113 The flag mayNotExist is used to choose the level of the logging message in case
114 the requested module does not exist.
117 oldpath = list(sys.path)
119 moduleelements = modulename.split(
".")
120 if len(moduleelements) > 1:
121 moddir = os.sep.join([root] + moduleelements[:-1])
125 shortmodname = moduleelements[-1]
127 if not os.path.exists(os.path.join(moddir, shortmodname) +
".py"):
128 msg = f
"Module {modulename} does not exist"
136 sys.path.insert(0, moddir)
137 logging.verbose(
"sys.path prepended with %r", sys.path[0])
139 logging.info(
"Looking for ConfigurableUser in %r", modulename)
142 logging.verbose(
"importing %s", shortmodname)
143 exec(f
"import {shortmodname} as mod", g, l)
146 logging.verbose(
"restoring old sys.path")
149 if "__all__" in dir(mod)
and mod.__all__:
152 all = [n
for n
in dir(mod)
if not n.startswith(
"_")]
155 cfg = cfgDb.get(name)
156 if cfg
and cfg[
"module"] != modulename:
158 logging.verbose(
"Object %r already found in module %r", name, cfg[
"module"])
160 t = getattr(mod, name)
162 t, (
"ConfigurableUser",
"SuperAlgorithm")
165 logging.verbose(
"Found %r", result)
170 from optparse
import OptionParser
172 parser = OptionParser(
173 prog=os.path.basename(sys.argv[0]),
174 usage=
"%prog [options] <PackageName> [<Module1> ...]",
181 help=
"output file for confDb data [default = '../genConfDir/<PackageName>_user_confDb.py'].",
188 help=
"root directory of the python modules [default = '../python'].",
191 "-v",
"--verbose", action=
"store_true", help=
"print some debugging information"
194 "--debug", action=
"store_true", help=
"print more debugging information"
199 help=
"build directory where to look for .confdb files (search all subdirectories)",
204 help=
"name of the current project (used to exclude spurious versions of the .confdb file for the current project)",
206 parser.set_defaults(root=os.path.join(
"..",
"python"))
208 opts, args = parser.parse_args()
211 log_level = logging.DEBUG
213 log_level = logging.VERBOSE
215 log_level = logging.INFO
if os.environ.get(
"VERBOSE")
else logging.WARNING
217 format=
"%(levelname)s: %(message)s", stream=sys.stdout, level=log_level
221 parser.error(
"PackageName is required")
223 package_name = args.pop(0)
225 usingConvention =
False
228 args = [package_name +
".Configuration"]
229 usingConvention =
True
231 genConfDir = os.path.join(
"..", os.environ.get(
"CMTCONFIG",
""),
"genConfDir")
232 if not os.path.exists(genConfDir):
233 genConfDir = os.path.join(
"..",
"genConfDir")
236 outputfile = os.path.join(genConfDir, package_name +
"_user.confdb")
238 outputfile = opts.output
243 import Gaudi.Configurables
245 Gaudi.Configurables.ignoreMissingConfigurables =
True
254 sys.path.insert(0, genConfDir)
255 sys.path.insert(0, os.path.join(
"..",
"python"))
256 localConfDb = os.path.join(genConfDir, package_name, package_name +
".confdb")
257 if os.path.exists(localConfDb):
258 cfgDb._loadModule(localConfDb)
260 package_module = __import__(package_name)
261 package_module.__path__.insert(0, os.path.join(genConfDir, package_name))
275 "Cannot import module %r:\n%s", mod, traceback.format_exc().rstrip()
282 cfgDb.add(configurable=m, package=
"None", module=
"None", lib=
"None")
283 elif not usingConvention:
285 "Specified module %r does not contain ConfigurableUser specializations",
290 logging.info(
"ConfigurableUser found:\n%s", pformat(cus))
292 output = f
"""## -*- ascii -*-
293# db file automatically generated by {parser.prog} on: {time.asctime()}
298 output +=
"{} {} {}\n".
format(mod,
"None", cu)
301 output += f
"## {package_name}\n"
302 elif usingConvention:
303 logging.info(
"No ConfigurableUser found")
305 f
"# db file automatically generated by {parser.prog} on: {time.asctime()}\n"
306 f
"# No ConfigurableUser specialization in {package_name}\n"
309 logging.error(
"No ConfigurableUser specialization found")
313 output_dir = os.path.dirname(outputfile)
315 logging.info(
"Creating directory %r", output_dir)
316 os.makedirs(output_dir, 0o755)
317 except OSError
as err:
320 if err.errno == errno.EEXIST:
327 logging.verbose(
"Writing confDb data to %r", outputfile)
328 open(outputfile,
"w").write(output)