fix reloading, new .reset prototype
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 11 Aug 2009 12:20:13 +0200
changeset 2760 30063071aee0
parent 2758 8a54f91a43e1
child 2761 7c583d02917b
fix reloading, new .reset prototype
cwvreg.py
vregistry.py
--- a/cwvreg.py	Mon Aug 10 18:01:46 2009 +0200
+++ b/cwvreg.py	Tue Aug 11 12:20:13 2009 +0200
@@ -250,8 +250,8 @@
     def itervalues(self):
         return (value for key, value in self.items())
 
-    def reset(self):
-        super(CubicWebVRegistry, self).reset()
+    def reset(self, path=None, force_reload=None):
+        super(CubicWebVRegistry, self).reset(path, force_reload)
         self._needs_iface = {}
         # two special registries, propertydefs which care all the property
         # definitions, and propertyvals which contains values for those
@@ -260,6 +260,17 @@
         self['propertyvalues'] = self.eprop_values = {}
         for key, propdef in self.config.eproperty_definitions():
             self.register_property(key, **propdef)
+        if path is not None and force_reload:
+            cleanup_sys_modules(path)
+            cubes = self.config.cubes()
+            # if the fs code use some cubes not yet registered into the instance
+            # we should cleanup sys.modules for those as well to avoid potential
+            # bad class reference pb after reloading
+            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)])
+                    cleanup_sys_modules(cpath)
 
     def set_schema(self, schema):
         """set instance'schema and load application objects"""
@@ -302,13 +313,14 @@
 
     def register_objects(self, path, force_reload=None):
         """overriden to remove objects requiring a missing interface"""
+        if force_reload is None:
+            force_reload = self.config.mode == 'dev'
         try:
             self._register_objects(path, force_reload)
         except RegistryOutOfDate:
             CW_EVENT_MANAGER.emit('before-registry-reload')
             # modification detected, reset and reload
-            self.reset()
-            cleanup_sys_modules(path)
+            self.reset(path, force_reload)
             self._register_objects(path, force_reload)
             CW_EVENT_MANAGER.emit('after-registry-reload')
 
--- a/vregistry.py	Mon Aug 10 18:01:46 2009 +0200
+++ b/vregistry.py	Tue Aug 11 12:20:13 2009 +0200
@@ -206,7 +206,7 @@
         super(VRegistry, self).__init__()
         self.config = config
 
-    def reset(self, force_reload=None):
+    def reset(self, path=None, force_reload=None):
         self.clear()
         self._lastmodifs = {}
 
@@ -318,14 +318,7 @@
         self._loadedmods = {}
         return filemods
 
-    def register_objects(self, path, force_reload=None, extrapath=None):
-        if force_reload is None:
-            force_reload = self.config.mode == 'dev'
-        elif not force_reload:
-            # force_reload == False usually mean modules have been reloaded
-            # by another connection, so we want to update the registry
-            # content even if there has been no module content modification
-            self.reset()
+    def register_objects(self, path, force_reload, extrapath=None):
         # need to clean sys.path this to avoid import confusion pb (i.e.
         # having the same module loaded as 'cubicweb.web.views' subpackage and
         # as views'  or 'web.views' subpackage