00087 :
00088 from optparse import OptionParser
00089 parser = OptionParser(prog = os.path.basename(sys.argv[0]),
00090 usage = "%prog [options] <PackageName> [<Module1> ...]")
00091 parser.add_option("-o", "--output", action="store", type="string",
00092 help="output file for confDb data [default = '../genConf/<PackageName>_user_confDb.py'].")
00093 parser.add_option("-r", "--root", action="store", type="string",
00094 help="root directory of the python modules [default = '../python'].")
00095 parser.add_option("-v", "--verbose", action="store_true",
00096 help="print some debugging information")
00097 parser.add_option("--lockerpath", action="store",
00098 metavar = "DIRNAME",
00099 help="directory where to find the module 'locker'")
00100 parser.set_defaults(root = os.path.join("..","python"))
00101
00102 opts, args = parser.parse_args()
00103
00104 if opts.verbose:
00105 log_level = logging.VERBOSE
00106 else:
00107 log_level = logging.INFO
00108 logging.basicConfig(format = "%(levelname)s: %(message)s",
00109 stream = sys.stdout,
00110 level = log_level)
00111
00112 if len(args) < 1:
00113 parser.error("PackageName is required")
00114
00115 package_name = args.pop(0)
00116
00117 usingConvention = False
00118 if not args:
00119
00120 args = [package_name + ".Configuration"]
00121 usingConvention = True
00122
00123 genConfDir = os.path.join("..", os.environ.get("CMTCONFIG", ""), "genConf")
00124 if not os.path.exists(genConfDir):
00125 genConfDir = os.path.join("..", "genConf")
00126
00127 if not opts.output:
00128 outputfile = os.path.join(genConfDir, package_name + '_user_confDb.py')
00129 else:
00130 outputfile = opts.output
00131
00132
00133
00134
00135 dbLock = None
00136 if "GAUDI_BUILD_LOCK" in os.environ:
00137 if opts.lockerpath:
00138 sys.path.append(opts.lockerpath)
00139
00140
00141 try:
00142 from locker import LockFile
00143 except ImportError:
00144 def LockFile(*args, **kwargs):
00145 return None
00146
00147 dbLock = LockFile(os.environ["GAUDI_BUILD_LOCK"], temporary = True)
00148
00149
00150
00151 try:
00152 import Gaudi.Configurables
00153 Gaudi.Configurables.ignoreMissingConfigurables = True
00154 except:
00155 pass
00156
00157 loadConfigurableDb()
00158
00159 try:
00160
00161
00162 sys.path.insert(0, genConfDir)
00163 sys.path.insert(0, os.path.join("..", "python"))
00164 localConfDb = os.path.join(genConfDir, package_name, package_name + '_confDb.py')
00165 if os.path.exists(localConfDb):
00166 execfile(localConfDb, {}, {})
00167 except:
00168 pass
00169 del dbLock
00170
00171
00172 cus = {}
00173 for mod in args:
00174 lst = None
00175 try:
00176 lst = getConfigurableUsers(mod, root = opts.root, mayNotExist = usingConvention)
00177 except ImportError:
00178 import traceback
00179 logging.error("Cannot import module %r:\n%s", mod,
00180 traceback.format_exc().rstrip())
00181 return 2
00182 if lst:
00183 cus[mod] = lst
00184
00185 for m in lst:
00186 cfgDb.add(configurable = m,
00187 package = 'None',
00188 module = 'None',
00189 lib = 'None')
00190 elif not usingConvention:
00191 logging.warning("Specified module %r does not contain ConfigurableUser specializations", mod)
00192
00193 if cus:
00194 logging.info("ConfigurableUser found:\n%s", pformat(cus))
00195
00196 output = """## -*- python -*-
00197 # db file automatically generated by %s on: %s
00198 ## insulates outside world against anything bad that could happen
00199 ## also prevents global scope pollution
00200 def _fillCfgDb():
00201 from GaudiKernel.Proxy.ConfigurableDb import CfgDb
00202
00203 # get a handle on the repository of Configurables
00204 cfgDb = CfgDb()
00205
00206 # populate the repository with informations on Configurables
00207 """ % (parser.prog, time.asctime())
00208
00209 for mod in cus:
00210 for cu in cus[mod]:
00211 output += """
00212 cfgDb.add( configurable = '%s',
00213 package = '%s',
00214 module = '%s',
00215 lib = 'None' )""" % (cu, package_name, mod)
00216
00217
00218 output += """
00219
00220 return #_fillCfgDb
00221
00222 # fill cfgDb at module import...
00223 try:
00224 _fillCfgDb()
00225 #house cleaning...
00226 del _fillCfgDb
00227 except Exception,err:
00228 print "Py:ConfigurableDb ERROR Problem with [%%s] content!" %% __name__
00229 print "Py:ConfigurableDb ERROR",err
00230 print "Py:ConfigurableDb ERROR ==> culprit is package [%s] !"
00231 """ % package_name
00232 elif usingConvention:
00233 logging.info("No ConfigurableUser found")
00234 output = "# No ConfigurableUser specialization\n"
00235 else:
00236 logging.error("No ConfigurableUser specialization found")
00237 return 1
00238
00239
00240 output_dir = os.path.dirname(outputfile)
00241 if not os.path.exists(output_dir):
00242 logging.info("Creating directory %r", output_dir)
00243 os.makedirs(output_dir, 0755)
00244
00245
00246 logging.verbose("Writing confDb data to %r", outputfile)
00247 open(outputfile, "w").write(output)
00248 return 0