[config] turn internal configuration methods building appobjects search path into normal method rather than class method
as this is useless and make path filters difficult to override (we had to
override the class attribute, as instance attributes were not seen).
Also rename related methods for consistency with current vocabulary
--- a/cwconfig.py Fri Sep 07 14:01:59 2012 +0200
+++ b/cwconfig.py Mon Sep 10 14:00:09 2012 +0200
@@ -671,54 +671,6 @@
cubicweb_appobject_path = set(['entities'])
cube_appobject_path = set(['entities'])
- @classmethod
- def build_vregistry_path(cls, templpath, evobjpath=None, tvobjpath=None):
- """given a list of directories, return a list of sub files and
- directories that should be loaded by the instance objects registry.
-
- :param evobjpath:
- optional list of sub-directories (or files without the .py ext) of
- the cubicweb library that should be tested and added to the output list
- if they exists. If not give, default to `cubicweb_appobject_path` class
- attribute.
- :param tvobjpath:
- optional list of sub-directories (or files without the .py ext) of
- directories given in `templpath` that should be tested and added to
- the output list if they exists. If not give, default to
- `cube_appobject_path` class attribute.
- """
- vregpath = cls.build_vregistry_cubicweb_path(evobjpath)
- vregpath += cls.build_vregistry_cube_path(templpath, tvobjpath)
- return vregpath
-
- @classmethod
- def build_vregistry_cubicweb_path(cls, evobjpath=None):
- vregpath = []
- if evobjpath is None:
- evobjpath = cls.cubicweb_appobject_path
- # NOTE: for the order, see http://www.cubicweb.org/ticket/2330799
- # it is clearly a workaround
- for subdir in sorted(evobjpath, key=lambda x:x != 'entities'):
- path = join(CW_SOFTWARE_ROOT, subdir)
- if exists(path):
- vregpath.append(path)
- return vregpath
-
- @classmethod
- def build_vregistry_cube_path(cls, templpath, tvobjpath=None):
- vregpath = []
- if tvobjpath is None:
- tvobjpath = cls.cube_appobject_path
- for directory in templpath:
- # NOTE: for the order, see http://www.cubicweb.org/ticket/2330799
- for subdir in sorted(tvobjpath, key=lambda x:x != 'entities'):
- path = join(directory, subdir)
- if exists(path):
- vregpath.append(path)
- elif exists(path + '.py'):
- vregpath.append(path + '.py')
- return vregpath
-
def __init__(self, debugmode=False):
if debugmode:
# in python 2.7, DeprecationWarning are not shown anymore by default
@@ -766,12 +718,57 @@
# configure simpleTal logger
logging.getLogger('simpleTAL').setLevel(logging.ERROR)
- def vregistry_path(self):
+ def appobjects_path(self):
"""return a list of files or directories where the registry will look
for application objects. By default return nothing in NoApp config.
"""
return []
+ def build_appobjects_path(self, templpath, evobjpath=None, tvobjpath=None):
+ """given a list of directories, return a list of sub files and
+ directories that should be loaded by the instance objects registry.
+
+ :param evobjpath:
+ optional list of sub-directories (or files without the .py ext) of
+ the cubicweb library that should be tested and added to the output list
+ if they exists. If not give, default to `cubicweb_appobject_path` class
+ attribute.
+ :param tvobjpath:
+ optional list of sub-directories (or files without the .py ext) of
+ directories given in `templpath` that should be tested and added to
+ the output list if they exists. If not give, default to
+ `cube_appobject_path` class attribute.
+ """
+ vregpath = self.build_appobjects_cubicweb_path(evobjpath)
+ vregpath += self.build_appobjects_cube_path(templpath, tvobjpath)
+ return vregpath
+
+ def build_appobjects_cubicweb_path(self, evobjpath=None):
+ vregpath = []
+ if evobjpath is None:
+ evobjpath = self.cubicweb_appobject_path
+ # NOTE: for the order, see http://www.cubicweb.org/ticket/2330799
+ # it is clearly a workaround
+ for subdir in sorted(evobjpath, key=lambda x:x != 'entities'):
+ path = join(CW_SOFTWARE_ROOT, subdir)
+ if exists(path):
+ vregpath.append(path)
+ return vregpath
+
+ def build_appobjects_cube_path(self, templpath, tvobjpath=None):
+ vregpath = []
+ if tvobjpath is None:
+ tvobjpath = self.cube_appobject_path
+ for directory in templpath:
+ # NOTE: for the order, see http://www.cubicweb.org/ticket/2330799
+ for subdir in sorted(tvobjpath, key=lambda x:x != 'entities'):
+ path = join(directory, subdir)
+ if exists(path):
+ vregpath.append(path)
+ elif exists(path + '.py'):
+ vregpath.append(path + '.py')
+ return vregpath
+
apphome = None
def load_site_cubicweb(self, paths=None):
@@ -1177,14 +1174,14 @@
self.exception('localisation support error for language %s',
language)
- def vregistry_path(self):
+ def appobjects_path(self):
"""return a list of files or directories where the registry will look
for application objects
"""
templpath = list(reversed(self.cubes_path()))
if self.apphome: # may be unset in tests
templpath.append(self.apphome)
- return self.build_vregistry_path(templpath)
+ return self.build_appobjects_path(templpath)
def set_sources_mode(self, sources):
if not 'all' in sources:
--- a/cwvreg.py Fri Sep 07 14:01:59 2012 +0200
+++ b/cwvreg.py Mon Sep 10 14:00:09 2012 +0200
@@ -588,7 +588,7 @@
"""set instance'schema and load application objects"""
self._set_schema(schema)
# now we can load application's web objects
- self.reload(self.config.vregistry_path(), force_reload=False)
+ self.reload(self.config.appobjects_path(), force_reload=False)
# map lowered entity type names to their actual name
self.case_insensitive_etypes = {}
for eschema in self.schema.entities():
@@ -598,7 +598,7 @@
clear_cache(eschema, 'meta_attributes')
def reload_if_needed(self):
- path = self.config.vregistry_path()
+ path = self.config.appobjects_path()
if self.is_reload_needed(path):
self.reload(path)
@@ -614,7 +614,7 @@
cfg = self.config
for cube in cfg.expand_cubes(cubes, with_recommends=True):
if not cube in cubes:
- cpath = cfg.build_vregistry_cube_path([cfg.cube_dir(cube)])
+ cpath = cfg.build_appobjects_cube_path([cfg.cube_dir(cube)])
cleanup_sys_modules(cpath)
self.register_objects(path)
CW_EVENT_MANAGER.emit('after-registry-reload')
--- a/dbapi.py Fri Sep 07 14:01:59 2012 +0200
+++ b/dbapi.py Mon Sep 10 14:00:09 2012 +0200
@@ -598,9 +598,9 @@
esubpath.remove('views')
esubpath.append(join('web', 'views'))
config.init_cubes(cubes)
- vpath = config.build_vregistry_path(reversed(config.cubes_path()),
- evobjpath=esubpath,
- tvobjpath=subpath)
+ vpath = config.build_appobjects_path(reversed(config.cubes_path()),
+ evobjpath=esubpath,
+ tvobjpath=subpath)
self.vreg.register_objects(vpath)
def use_web_compatible_requests(self, baseurl, sitetitle=None):
--- a/devtools/devctl.py Fri Sep 07 14:01:59 2012 +0200
+++ b/devtools/devctl.py Mon Sep 10 14:00:09 2012 +0200
@@ -91,7 +91,7 @@
if mod.__file__ is None:
# odd/rare but real
continue
- for path in config.vregistry_path():
+ for path in config.appobjects_path():
if mod.__file__.startswith(path):
del sys.modules[name]
break
--- a/ext/tal.py Fri Sep 07 14:01:59 2012 +0200
+++ b/ext/tal.py Mon Sep 10 14:00:09 2012 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
@@ -261,7 +261,7 @@
return wrapped
def _compiled_template(self, instance):
- for fileordirectory in instance.config.vregistry_path():
+ for fileordirectory in instance.config.appobjects_path():
filepath = join(fileordirectory, self.filename)
if isdir(fileordirectory) and exists(filepath):
return compile_template_file(filepath)
--- a/server/repository.py Fri Sep 07 14:01:59 2012 +0200
+++ b/server/repository.py Mon Sep 10 14:00:09 2012 +0200
@@ -198,8 +198,8 @@
# information (eg dump/restore/...)
config._cubes = ()
# only load hooks and entity classes in the registry
- config.__class__.cube_appobject_path = set(('hooks', 'entities'))
- config.__class__.cubicweb_appobject_path = set(('hooks', 'entities'))
+ config.cube_appobject_path = set(('hooks', 'entities'))
+ config.cubicweb_appobject_path = set(('hooks', 'entities'))
self.set_schema(config.load_schema())
config['connections-pool-size'] = 1
# will be reinitialized later from cubes found in the database
--- a/test/unittest_cwconfig.py Fri Sep 07 14:01:59 2012 +0200
+++ b/test/unittest_cwconfig.py Mon Sep 10 14:00:09 2012 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
@@ -101,10 +101,10 @@
self.assertEqual(self.config.expand_cubes(('email', 'comment')),
['email', 'comment', 'file'])
- def test_vregistry_path(self):
+ def test_appobjects_path(self):
self.config.__class__.CUBES_PATH = [CUSTOM_CUBES_DIR]
self.config.adjust_sys_path()
- self.assertEqual([unabsolutize(p) for p in self.config.vregistry_path()],
+ self.assertEqual([unabsolutize(p) for p in self.config.appobjects_path()],
['entities', 'web/views', 'sobjects', 'hooks',
'file/entities', 'file/views.py', 'file/hooks',
'email/entities.py', 'email/views', 'email/hooks.py',