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 =
"""## -*- ascii -*-
293 # db file automatically generated by %s on: %s
301 output +=
"%s %s %s\n" % (mod,
"None", cu)
304 output +=
"## %s\n" % package_name
305 elif usingConvention:
306 logging.info(
"No ConfigurableUser found")
308 "# db file automatically generated by %s on: %s\n"
309 "# No ConfigurableUser specialization in %s\n"
310 ) % (parser.prog, time.asctime(), package_name)
312 logging.error(
"No ConfigurableUser specialization found")
316 output_dir = os.path.dirname(outputfile)
318 logging.info(
"Creating directory %r", output_dir)
319 os.makedirs(output_dir, 0o755)
320 except OSError
as err:
323 if err.errno == errno.EEXIST:
330 logging.verbose(
"Writing confDb data to %r", outputfile)
331 open(outputfile,
"w").write(output)