# HG changeset patch # User Sylvain Thénault # Date 1277126950 -7200 # Node ID d970049d7cfddbd3f07053f4ad3e7144c051b81e # Parent 92f00369dc3e4537750801bdff0693abdcd73f9f [dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method. diff -r 92f00369dc3e -r d970049d7cfd cwconfig.py --- a/cwconfig.py Mon Jun 21 11:54:09 2010 +0200 +++ b/cwconfig.py Mon Jun 21 15:29:10 2010 +0200 @@ -668,6 +668,7 @@ self.adjust_sys_path() self.load_defaults() self.translations = {} + self._site_loaded = set() # don't register ReStructured Text directives by simple import, avoid pb # with eg sphinx. # XXX should be done properly with a function from cw.uicfg @@ -698,8 +699,7 @@ init_log(debug, syslog, logthreshold, logfile, self.log_format, rotation_parameters={'when': 'W6', # every sunday 'interval': 1, - 'backupCount': 52, - }) + 'backupCount': 52}) else: init_log(debug, syslog, logthreshold, logfile, self.log_format) # configure simpleTal logger @@ -711,6 +711,34 @@ """ return [] + apphome = None + + def load_site_cubicweb(self, paths=None): + """load instance's specific site_cubicweb file""" + if paths is None: + paths = self.cubes_path() + if self.apphome is not None: + paths = [self.apphome] + paths + for path in reversed(paths): + sitefile = join(path, 'site_cubicweb.py') + if exists(sitefile) and not sitefile in self._site_loaded: + self._load_site_cubicweb(sitefile) + self._site_loaded.add(sitefile) + else: + sitefile = join(path, 'site_erudi.py') + if exists(sitefile) and not sitefile in self._site_loaded: + self._load_site_cubicweb(sitefile) + self._site_loaded.add(sitefile) + self.warning('[3.5] site_erudi.py is deprecated, should be ' + 'renamed to site_cubicweb.py') + + def _load_site_cubicweb(self, sitefile): + # XXX extrapath argument to load_module_from_file only in lgc > 0.50.2 + from logilab.common.modutils import load_module_from_modpath, modpath_from_file + module = load_module_from_modpath(modpath_from_file(sitefile, self.extrapath)) + self.info('%s loaded', sitefile) + return module + def eproperty_definitions(self): cfg = self.persistent_options_configuration() for section, options in cfg.options_by_section(): @@ -892,7 +920,6 @@ self.appid = appid CubicWebNoAppConfiguration.__init__(self) self._cubes = None - self._site_loaded = set() self.load_file_configuration(self.main_config_file()) def adjust_sys_path(self): @@ -967,37 +994,6 @@ infos.append('%s-%s' % (pkg, version)) return md5.new(';'.join(infos)).hexdigest() - def load_site_cubicweb(self): - """load instance's specific site_cubicweb file""" - paths = self.cubes_path() - if self.apphome is not None: - paths = [self.apphome] + paths - for path in reversed(paths): - sitefile = join(path, 'site_cubicweb.py') - if exists(sitefile) and not sitefile in self._site_loaded: - self._load_site_cubicweb(sitefile) - self._site_loaded.add(sitefile) - else: - sitefile = join(path, 'site_erudi.py') - if exists(sitefile) and not sitefile in self._site_loaded: - self._load_site_cubicweb(sitefile) - self._site_loaded.add(sitefile) - self.warning('[3.5] site_erudi.py is deprecated, should be ' - 'renamed to site_cubicweb.py') - - def _load_site_cubicweb(self, sitefile): - # XXX extrapath argument to load_module_from_file only in lgc > 0.46 - from logilab.common.modutils import load_module_from_modpath, modpath_from_file - def load_module_from_file(filepath, path=None, use_sys=1, extrapath=None): - return load_module_from_modpath(modpath_from_file(filepath, extrapath), - path, use_sys) - module = load_module_from_file(sitefile, extrapath=self.extrapath) - self.info('%s loaded', sitefile) - # cube specific options - if getattr(module, 'options', None): - self.register_options(module.options) - self.load_defaults() - def load_configuration(self): """load instance's configuration files""" super(CubicWebConfiguration, self).load_configuration() @@ -1005,6 +1001,13 @@ # init gettext self._set_language() + def _load_site_cubicweb(self, sitefile): + # overriden to register cube specific options + mod = super(CubicWebConfiguration, self)._load_site_cubicweb(sitefile) + if getattr(mod, 'options', None): + self.register_options(module.options) + self.load_defaults() + def init_log(self, logthreshold=None, debug=False, force=False): """init the log service""" if not force and hasattr(self, '_logging_initialized'): @@ -1099,7 +1102,8 @@ SMTP_LOCK.release() return True -set_log_methods(CubicWebConfiguration, logging.getLogger('cubicweb.configuration')) +set_log_methods(CubicWebNoAppConfiguration, + logging.getLogger('cubicweb.configuration')) # alias to get a configuration instance from an instance id instance_configuration = CubicWebConfiguration.config_for diff -r 92f00369dc3e -r d970049d7cfd dbapi.py --- a/dbapi.py Mon Jun 21 11:54:09 2010 +0200 +++ b/dbapi.py Mon Jun 21 15:29:10 2010 +0200 @@ -554,18 +554,12 @@ esubpath = list(subpath) esubpath.remove('views') esubpath.append(join('web', 'views')) - cubes = reversed([config.cube_dir(p) for p in cubes]) - vpath = config.build_vregistry_path(cubes, evobjpath=esubpath, + cubespath = [config.cube_dir(p) for p in cubes] + config.load_site_cubicweb(cubespath) + vpath = config.build_vregistry_path(reversed(cubespath), + evobjpath=esubpath, tvobjpath=subpath) self.vreg.register_objects(vpath) - if self._cnxtype == 'inmemory': - # should reinit hooks manager as well - hm, config = self._repo.hm, self._repo.config - hm.set_schema(hm.schema) # reset structure - hm.register_system_hooks(config) - # instance specific hooks - if self._repo.config.instance_hooks: - hm.register_hooks(config.load_hooks(self.vreg)) def use_web_compatible_requests(self, baseurl, sitetitle=None): """monkey patch DBAPIRequest to fake a cw.web.request, so you should