4 Generate _confDb.py files for ConfigurableUser classes. 13 from pprint
import pformat
17 logging.VERBOSE = (logging.INFO + logging.DEBUG) / 2
18 logging.addLevelName(logging.VERBOSE,
"VERBOSE")
19 logging.verbose =
lambda msg, *args, **kwargs: \
20 apply(logging.log, (logging.VERBOSE, msg) + args, kwargs)
25 Check if any of the class names in 'basenames' is anywhere in the base 26 classes of the class 'derived'. 27 If 'derived' _is_ one in 'basenames', returns False. 29 'basenames' can be a string or an iterable (of strings). 31 if isinstance(basenames, basestring):
32 basenames = (basenames, )
33 for b
in derived.__bases__:
34 if b.__name__
in basenames:
44 Equivalent to GaudiKernel.ConfigurableDb.loadConfigurableDb(), but does a 45 deep search and executes the '*.confdb' files instead of importing them. 47 log = GaudiKernel.ConfigurableDb.log
48 from os.path
import join
as path_join
54 f
for f
in glob(path_join(path,
'*',
'*.confdb'))
58 pathlist = os.getenv(
"LD_LIBRARY_PATH",
"").split(os.pathsep)
59 for path
in filter(os.path.isdir, pathlist):
62 path_join(path, f)
for f
in os.listdir(path)
63 if f.endswith(
'.confdb')
67 for confDb
in confDbFiles:
68 log.debug(
"\t-loading [%s]..." % confDb)
70 cfgDb._loadModule(confDb)
71 except Exception, err:
74 log.warning(
"Could not load file [%s] !", confDb)
75 log.warning(
"Reason: %s", err)
82 Find in the module 'modulename' all the classes that derive from ConfigurableUser. 83 Return the list of the names. 84 The flag mayNotExist is used to choose the level of the logging message in case 85 the requested module does not exist. 88 oldpath = list(sys.path)
90 moduleelements = modulename.split(
'.')
91 if len(moduleelements) > 1:
92 moddir = os.sep.join([root] + moduleelements[:-1])
96 shortmodname = moduleelements[-1]
98 if not os.path.exists(os.path.join(moddir, shortmodname) +
".py"):
99 msg =
"Module %s does not exist" % modulename
107 sys.path.insert(0, moddir)
108 logging.verbose(
"sys.path prepended with %r", sys.path[0])
110 logging.info(
"Looking for ConfigurableUser in %r", modulename)
113 logging.verbose(
"importing %s", shortmodname)
114 exec
"import %s as mod" % shortmodname
in g, l
117 logging.verbose(
"restoring old sys.path")
120 if "__all__" in dir(mod)
and mod.__all__:
123 all = [n
for n
in dir(mod)
if not n.startswith(
"_")]
126 cfg = cfgDb.get(name)
127 if cfg
and cfg[
"module"] != modulename:
129 logging.verbose(
"Object %r already found in module %r", name,
132 t = getattr(mod, name)
134 t, (
'ConfigurableUser',
'SuperAlgorithm')):
136 logging.verbose(
"Found %r", result)
141 from optparse
import OptionParser
142 parser = OptionParser(
143 prog=os.path.basename(sys.argv[0]),
144 usage=
"%prog [options] <PackageName> [<Module1> ...]")
151 "output file for confDb data [default = '../genConf/<PackageName>_user_confDb.py']." 158 help=
"root directory of the python modules [default = '../python'].")
163 help=
"print some debugging information")
167 help=
"print more debugging information")
168 parser.set_defaults(root=os.path.join(
"..",
"python"))
170 opts, args = parser.parse_args()
173 log_level = logging.DEBUG
175 log_level = logging.VERBOSE
177 log_level = logging.INFO
if os.environ.get(
178 'VERBOSE')
else logging.WARNING
180 format=
"%(levelname)s: %(message)s",
185 parser.error(
"PackageName is required")
187 package_name = args.pop(0)
189 usingConvention =
False 192 args = [package_name +
".Configuration"]
193 usingConvention =
True 195 genConfDir = os.path.join(
"..", os.environ.get(
"CMTCONFIG",
""),
"genConf")
196 if not os.path.exists(genConfDir):
197 genConfDir = os.path.join(
"..",
"genConf")
200 outputfile = os.path.join(genConfDir, package_name +
'_user.confdb')
202 outputfile = opts.output
207 import Gaudi.Configurables
208 Gaudi.Configurables.ignoreMissingConfigurables =
True 217 sys.path.insert(0, genConfDir)
218 sys.path.insert(0, os.path.join(
"..",
"python"))
219 localConfDb = os.path.join(genConfDir, package_name,
220 package_name +
'.confdb')
221 if os.path.exists(localConfDb):
222 cfgDb._loadModule(localConfDb)
224 package_module = __import__(package_name)
225 package_module.__path__.insert(
226 0, os.path.join(genConfDir, package_name))
236 mod, root=opts.root, mayNotExist=usingConvention)
240 "Cannot import module %r:\n%s", mod,
241 traceback.format_exc().rstrip())
248 configurable=m, package=
'None', module=
'None', lib=
'None')
249 elif not usingConvention:
251 "Specified module %r does not contain ConfigurableUser specializations",
255 logging.info(
"ConfigurableUser found:\n%s", pformat(cus))
257 output =
"""## -*- ascii -*- 258 # db file automatically generated by %s on: %s 259 """ % (parser.prog, time.asctime())
263 output +=
"%s %s %s\n" % (mod,
'None', cu)
266 output +=
"## %s\n" % package_name
267 elif usingConvention:
268 logging.info(
"No ConfigurableUser found")
269 output = (
"# db file automatically generated by %s on: %s\n" 270 "# No ConfigurableUser specialization in %s\n") % (
271 parser.prog, time.asctime(), package_name)
273 logging.error(
"No ConfigurableUser specialization found")
277 output_dir = os.path.dirname(outputfile)
279 logging.info(
"Creating directory %r", output_dir)
280 os.makedirs(output_dir, 0755)
283 if err.errno == errno.EEXIST:
290 logging.verbose(
"Writing confDb data to %r", outputfile)
291 open(outputfile,
"w").write(output)
295 if __name__ ==
'__main__':
decltype(auto) constexpr apply(F &&f, Tuple &&t) noexcept(noexcept( detail::apply_impl(std::forward< F >(f), std::forward< Tuple >(t), std::make_index_sequence< std::tuple_size< std::remove_reference_t< Tuple >>::value >{})))
def getConfigurableUsers(modulename, root, mayNotExist=False)
def _inheritsfrom(derived, basenames)