113 from optparse
import OptionParser
114 parser = OptionParser(prog = os.path.basename(sys.argv[0]),
115 usage =
"%prog [options] <PackageName> [<Module1> ...]")
116 parser.add_option(
"-o",
"--output", action=
"store", type=
"string",
117 help=
"output file for confDb data [default = '../genConf/<PackageName>_user_confDb.py'].")
118 parser.add_option(
"-r",
"--root", action=
"store", type=
"string",
119 help=
"root directory of the python modules [default = '../python'].")
120 parser.add_option(
"-v",
"--verbose", action=
"store_true",
121 help=
"print some debugging information")
122 parser.add_option(
"--debug", action=
"store_true",
123 help=
"print more debugging information")
124 parser.add_option(
"--lockerpath", action=
"store",
126 help=
"directory where to find the module 'locker'")
127 parser.set_defaults(root = os.path.join(
"..",
"python"))
129 opts, args = parser.parse_args()
132 log_level = logging.DEBUG
134 log_level = logging.VERBOSE
136 log_level = logging.INFO
137 logging.basicConfig(format =
"%(levelname)s: %(message)s",
142 parser.error(
"PackageName is required")
144 package_name = args.pop(0)
146 usingConvention =
False
149 args = [package_name +
".Configuration"]
150 usingConvention =
True
152 genConfDir = os.path.join(
"..", os.environ.get(
"CMTCONFIG",
""),
"genConf")
153 if not os.path.exists(genConfDir):
154 genConfDir = os.path.join(
"..",
"genConf")
157 outputfile = os.path.join(genConfDir, package_name +
'_user_confDb.py')
159 outputfile = opts.output
165 if "GAUDI_BUILD_LOCK" in os.environ:
167 sys.path.append(opts.lockerpath)
171 from locker
import LockFile
173 def LockFile(*args, **kwargs):
176 dbLock = LockFile(os.environ[
"GAUDI_BUILD_LOCK"], temporary =
True)
181 import Gaudi.Configurables
182 Gaudi.Configurables.ignoreMissingConfigurables =
True
191 sys.path.insert(0, genConfDir)
192 sys.path.insert(0, os.path.join(
"..",
"python"))
193 localConfDb = os.path.join(genConfDir, package_name, package_name +
'_confDb.py')
194 if os.path.exists(localConfDb):
195 execfile(localConfDb, {}, {})
197 package_module = __import__(package_name)
198 package_module.__path__.insert(0, os.path.join(genConfDir, package_name))
211 logging.error(
"Cannot import module %r:\n%s", mod,
212 traceback.format_exc().rstrip())
218 cfgDb.add(configurable = m,
222 elif not usingConvention:
223 logging.warning(
"Specified module %r does not contain ConfigurableUser specializations", mod)
226 logging.info(
"ConfigurableUser found:\n%s", pformat(cus))
228 output =
"""## -*- python -*-
229 # db file automatically generated by %s on: %s
230 ## insulates outside world against anything bad that could happen
231 ## also prevents global scope pollution
233 from GaudiKernel.Proxy.ConfigurableDb import CfgDb
235 # get a handle on the repository of Configurables
238 # populate the repository with informations on Configurables
239 """ % (parser.prog, time.asctime())
244 cfgDb.add( configurable = '%s',
247 lib = 'None' )""" % (cu, package_name, mod)
254 # fill cfgDb at module import...
259 except Exception,err:
260 print "Py:ConfigurableDb ERROR Problem with [%%s] content!" %% __name__
261 print "Py:ConfigurableDb ERROR",err
262 print "Py:ConfigurableDb ERROR ==> culprit is package [%s] !"
264 elif usingConvention:
265 logging.info(
"No ConfigurableUser found")
266 output = (
"# db file automatically generated by %s on: %s\n"
267 "# No ConfigurableUser specialization in %s\n") % (parser.prog, time.asctime(), package_name)
269 logging.error(
"No ConfigurableUser specialization found")
273 output_dir = os.path.dirname(outputfile)
274 if not os.path.exists(output_dir):
275 logging.info(
"Creating directory %r", output_dir)
276 os.makedirs(output_dir, 0755)
279 logging.verbose(
"Writing confDb data to %r", outputfile)
280 open(outputfile,
"w").write(output)