Commit 5a7887b9 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Move resetting of package to component_package as it has always should been there.

parent 8139fdd3
...@@ -348,7 +348,7 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin): ...@@ -348,7 +348,7 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
except AttributeError: except AttributeError:
reset_portal_type = False reset_portal_type = False
synchronizeDynamicModules(self, force=reset_portal_type) synchronizeDynamicModules(self, force=True)
return self return self
def manage_beforeDelete(self, item, container): def manage_beforeDelete(self, item, container):
......
...@@ -44,9 +44,9 @@ from zLOG import LOG, INFO, WARNING ...@@ -44,9 +44,9 @@ from zLOG import LOG, INFO, WARNING
last_sync = -1 last_sync = -1
class ComponentTool(BaseTool): class ComponentTool(BaseTool):
""" """
This tool provides methods to load the the different types of This tool provides methods to load the the different types of components of
components of the ERP5 framework: Document classes, interfaces, the ERP5 framework: Document classes, interfaces, mixin classes, fields,
mixin classes, fields, accessors, etc. accessors, etc.
""" """
id = "portal_components" id = "portal_components"
meta_type = "ERP5 Component Tool" meta_type = "ERP5 Component Tool"
...@@ -55,22 +55,6 @@ class ComponentTool(BaseTool): ...@@ -55,22 +55,6 @@ class ComponentTool(BaseTool):
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
def _resetModule(self, module):
for name, klass in module.__dict__.items():
if not (name[0] != '_' and isinstance(klass, ModuleType)):
continue
full_module_name = "%s.%s" % (module.__name__, name)
LOG("ERP5Type.Tool.ComponentTool", INFO, "Resetting " + full_module_name)
if name.endswith('_version'):
self._resetModule(getattr(module, name))
# The module must be deleted first
del sys.modules[full_module_name]
delattr(module, name)
security.declareProtected(Permissions.ResetDynamicClasses, 'reset') security.declareProtected(Permissions.ResetDynamicClasses, 'reset')
def reset(self, force=True, reset_portal_type=True): def reset(self, force=True, reset_portal_type=True):
""" """
...@@ -103,16 +87,15 @@ class ComponentTool(BaseTool): ...@@ -103,16 +87,15 @@ class ComponentTool(BaseTool):
with Base.aq_method_lock: with Base.aq_method_lock:
for content_type in allowed_content_type_list: for content_type in allowed_content_type_list:
module_name = content_type.split(' ')[0].lower() package_name = content_type.split(' ')[0].lower()
try: try:
module = getattr(erp5.component, module_name) package = getattr(erp5.component, package_name)
# XXX-arnau: not everything is defined yet... # XXX-arnau: not everything is defined yet...
except AttributeError: except AttributeError:
pass pass
else: else:
module._resetRegistry() package.reset()
self._resetModule(module)
if reset_portal_type: if reset_portal_type:
type_tool.resetDynamicDocumentsOnceAtTransactionBoundary() type_tool.resetDynamicDocumentsOnceAtTransactionBoundary()
......
...@@ -35,7 +35,7 @@ import threading ...@@ -35,7 +35,7 @@ import threading
from Products.ERP5.ERP5Site import getSite from Products.ERP5.ERP5Site import getSite
from types import ModuleType from types import ModuleType
from zLOG import LOG, INFO from zLOG import LOG, INFO, BLATHER
class ComponentVersionPackage(ModuleType): class ComponentVersionPackage(ModuleType):
""" """
...@@ -123,9 +123,6 @@ class ComponentDynamicPackage(ModuleType): ...@@ -123,9 +123,6 @@ class ComponentDynamicPackage(ModuleType):
return self.__registry_dict return self.__registry_dict
def _resetRegistry(self):
self.__registry_dict.clear()
def find_module(self, fullname, path=None): def find_module(self, fullname, path=None):
# Ignore imports with a path which are filesystem-only and any # Ignore imports with a path which are filesystem-only and any
# absolute imports which does not start with this package prefix, # absolute imports which does not start with this package prefix,
...@@ -264,3 +261,32 @@ class ComponentDynamicPackage(ModuleType): ...@@ -264,3 +261,32 @@ class ComponentDynamicPackage(ModuleType):
setattr(self, component_name, new_module) setattr(self, component_name, new_module)
return new_module return new_module
def reset(self, sub_package=None):
"""
Reset the content of the current package and its version package as well
recursively. This method must be called within a lock to avoid side
effects
"""
if sub_package is None:
# Clear the Component registry
self.__registry_dict.clear()
package = self
else:
package = sub_package
for name, module in package.__dict__.items():
if name[0] == '_' or not isinstance(module, ModuleType):
continue
# Reset the content of the version package before resetting it
elif isinstance(module, ComponentVersionPackage):
self.reset(sub_package=module)
module_name = "%s.%s" % (package.__name__, name)
LOG("ERP5Type.Tool.ComponentTool", BLATHER, "Resetting " + module_name)
# The module must be deleted first from sys.modules to avoid imports in
# the meantime
del sys.modules[module_name]
delattr(package, name)
...@@ -150,7 +150,7 @@ class ComponentMixin(PropertyRecordableMixin, Base): ...@@ -150,7 +150,7 @@ class ComponentMixin(PropertyRecordableMixin, Base):
_message_reference_not_set = "Reference must be set" _message_reference_not_set = "Reference must be set"
_message_invalid_reference = "Reference cannot end with '_version' or "\ _message_invalid_reference = "Reference cannot end with '_version' or "\
"start with '_' or be equal to find_module or load_module" "start with '_' or be equal to find_module, load_module or reset"
_message_version_not_set = "Version must be set" _message_version_not_set = "Version must be set"
_message_invalid_version = "Version cannot start with '_'" _message_invalid_version = "Version cannot start with '_'"
...@@ -177,7 +177,7 @@ class ComponentMixin(PropertyRecordableMixin, Base): ...@@ -177,7 +177,7 @@ class ComponentMixin(PropertyRecordableMixin, Base):
elif (reference.endswith('_version') or elif (reference.endswith('_version') or
reference[0] == '_' or reference[0] == '_' or
reference in ('find_module', 'load_module')): reference in ('find_module', 'load_module', 'reset')):
error_list.append( error_list.append(
ConsistencyMessage(self, ConsistencyMessage(self,
object_relative_url, object_relative_url,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment