135 from optparse
import OptionParser
136 parser = OptionParser(prog=os.path.basename(sys.argv[0]),
137 usage=
"%prog [options] <PackageName> [<Module1> ...]")
138 parser.add_option(
"-o",
"--output", action=
"store", type=
"string",
139 help=
"output file for confDb data [default = '../genConf/<PackageName>_user_confDb.py'].")
140 parser.add_option(
"-r",
"--root", action=
"store", type=
"string",
141 help=
"root directory of the python modules [default = '../python'].")
142 parser.add_option(
"-v",
"--verbose", action=
"store_true",
143 help=
"print some debugging information")
144 parser.add_option(
"--debug", action=
"store_true",
145 help=
"print more debugging information")
146 parser.set_defaults(root=os.path.join(
"..",
"python"))
148 opts, args = parser.parse_args()
151 log_level = logging.DEBUG
153 log_level = logging.VERBOSE
155 log_level = logging.INFO
if os.environ.get(
156 'VERBOSE')
else logging.WARNING
157 logging.basicConfig(format=
"%(levelname)s: %(message)s",
162 parser.error(
"PackageName is required")
164 package_name = args.pop(0)
166 usingConvention =
False 169 args = [package_name +
".Configuration"]
170 usingConvention =
True 172 genConfDir = os.path.join(
"..", os.environ.get(
"CMTCONFIG",
""),
"genConf")
173 if not os.path.exists(genConfDir):
174 genConfDir = os.path.join(
"..",
"genConf")
177 outputfile = os.path.join(genConfDir, package_name +
'_user.confdb')
179 outputfile = opts.output
184 import Gaudi.Configurables
185 Gaudi.Configurables.ignoreMissingConfigurables =
True 194 sys.path.insert(0, genConfDir)
195 sys.path.insert(0, os.path.join(
"..",
"python"))
196 localConfDb = os.path.join(
197 genConfDir, package_name, package_name +
'.confdb')
198 if os.path.exists(localConfDb):
199 cfgDb._loadModule(localConfDb)
201 package_module = __import__(package_name)
202 package_module.__path__.insert(
203 0, os.path.join(genConfDir, package_name))
213 mod, root=opts.root, mayNotExist=usingConvention)
216 logging.error(
"Cannot import module %r:\n%s", mod,
217 traceback.format_exc().rstrip())
223 cfgDb.add(configurable=m,
227 elif not usingConvention:
229 "Specified module %r does not contain ConfigurableUser specializations", mod)
232 logging.info(
"ConfigurableUser found:\n%s", pformat(cus))
234 output =
"""## -*- ascii -*- 235 # db file automatically generated by %s on: %s 236 """ % (parser.prog, time.asctime())
240 output +=
"%s %s %s\n" % (mod,
'None', cu)
243 output +=
"## %s\n" % package_name
244 elif usingConvention:
245 logging.info(
"No ConfigurableUser found")
246 output = (
"# db file automatically generated by %s on: %s\n" 247 "# No ConfigurableUser specialization in %s\n") % (parser.prog, time.asctime(), package_name)
249 logging.error(
"No ConfigurableUser specialization found")
253 output_dir = os.path.dirname(outputfile)
255 logging.info(
"Creating directory %r", output_dir)
256 os.makedirs(output_dir, 0755)
259 if err.errno == errno.EEXIST:
266 logging.verbose(
"Writing confDb data to %r", outputfile)
267 open(outputfile,
"w").
write(output)
def getConfigurableUsers(modulename, root, mayNotExist=False)