Commit dca6727d authored by Arnaud Fontaine's avatar Arnaud Fontaine

WIP: ZODB Components: Products import compatibility.

parent daafd0e6
......@@ -61,8 +61,8 @@ class ToolComponent(DocumentComponent):
# Should we really use ERP5 Product and not ERP5Type considering that ERP5
# may be gone at some point? Or the other way around? For now, all tools
# have meta_type='ERP5 ...' so just use ERP5 Product.
import Products.ERP5
toolinit = Products.ERP5.__FactoryDispatcher__.toolinit
import Products.ERP5Type
toolinit = Products.ERP5Type.__FactoryDispatcher__.toolinit
# Products.CMFCore.utils.ToolInit.initialize()
tool_class.__factory_meta_type__ = toolinit.meta_type
tool_class.icon = 'misc_/%s/%s' % ('ERP5', toolinit.icon)
......
......@@ -226,7 +226,7 @@ class _site(threading.local):
self.site = [x for x in self.site if x[0] is not app]
getSite, setSite = _site()
all_product_installed_portal_id_set = set()
class ERP5Site(ResponseHeaderGenerator, FolderMixIn, CMFSite, CacheCookieMixin):
"""
......@@ -403,6 +403,44 @@ class ERP5Site(ResponseHeaderGenerator, FolderMixIn, CMFSite, CacheCookieMixin):
# This should only happen before erp5_core is installed
synchronizeDynamicModules(self)
else:
global all_product_installed_portal_id_set
from Products.ERP5Type.dynamic import aq_method_lock
if self.id not in all_product_installed_portal_id_set:
with aq_method_lock:
all_product_installed_portal_id_set.add(self.id)
LOG('ERP5Site', INFO, '===> Creating mapping of old FS to new ZODB Components imports')
import erp5.component
if not getattr(erp5.component, 'filesystem_import_dict', None):
filesystem_import_dict = {}
for component in component_tool.objectValues():
if (component.getValidationState() == 'validated' and
component.getSourceReference() is not None):
if component.getReference() == 'CompositionMixin':
continue
filesystem_import_dict[component.getSourceReference()] = '%s.%s' % (
component._getDynamicModuleNamespace(),
component.getReference())
erp5.component.filesystem_import_dict = filesystem_import_dict
LOG('ERP5Site', INFO, '===> Importing all Products')
from OFS.Application import import_products
import_products(everything=True)
LOG('ERP5Site', INFO, '===> Installing all Products')
from OFS.Application import install_products
install_products(self.aq_parent, everything=True)
# TODO-BEFORE-MERGE: Fill document_class_registry to load
# classes. It should probably be done in initializeProduct()....
from Products.ERP5Type.InitGenerator import initializeProductDocumentRegistry
initializeProductDocumentRegistry()
LOG('ERP5Site', INFO, '===> Reset all ZODB Components and Portal Type classes')
component_tool.reset(force=True)
LOG('ERP5Site', INFO, '===> All Products installed')
if not component_tool.reset():
# Portal Types may have been reset even if Components haven't
# (change of Interaction Workflow...)
......
......@@ -34,6 +34,7 @@ import sys
import imp
import collections
from Products.ERP5Type import product_path as ERP5Type_product_path
from Products.ERP5Type.ERP5Site import getSite
from . import aq_method_lock
from types import ModuleType
......@@ -109,11 +110,27 @@ class ComponentDynamicPackage(ModuleType):
perhaps because the Finder of another Component Package could do it or
because this is a filesystem module...
"""
# Ignore imports with a path which are filesystem-only and any
# absolute imports which does not start with this package prefix,
# None there means that "normal" sys.path will be used
if path or not fullname.startswith(self._namespace_prefix):
return None
# ZODB Components
if not path:
if not fullname.startswith(self._namespace_prefix):
return None
# FS import backward compatibility
else:
if not [p for p in path
if (not p.startswith(ERP5Type_product_path)
# TODO-BEFORE-MERGE: Would not work for customer Products...
# and p.startswith(os.path.realpath(ERP5Type_product_path + '/..'))
)]:
return None
import erp5.component
try:
fullname = erp5.component.filesystem_import_dict[fullname]
except Exception:
return None
else:
if not fullname.startswith(self._namespace_prefix):
return None
import_lock_held = True
try:
......@@ -219,6 +236,14 @@ class ComponentDynamicPackage(ModuleType):
module for any reason...
"""
site = getSite()
if fullname.startswith('Products.'):
module_fullname_filesystem = fullname
import erp5.component
fullname = erp5.component.filesystem_import_dict[module_fullname_filesystem]
else:
module_fullname_filesystem = None
name = fullname[len(self._namespace_prefix):]
# if only Version package (erp5.component.XXX.VERSION_version) is
......@@ -288,6 +313,8 @@ class ComponentDynamicPackage(ModuleType):
sys.modules[module_fullname] = module
if module_fullname_alias:
sys.modules[module_fullname_alias] = module
if module_fullname_filesystem:
sys.modules[module_fullname_filesystem] = module
# This must be set for imports at least (see PEP 302)
module.__file__ = '<' + relative_url + '>'
......@@ -308,6 +335,8 @@ class ComponentDynamicPackage(ModuleType):
del sys.modules[module_fullname]
if module_fullname_alias:
del sys.modules[module_fullname_alias]
if module_fullname_filesystem:
del sys.modules[module_fullname_filesystem]
raise ImportError(
"%s: cannot load Component %s (%s)" % (fullname, name, error)), \
......@@ -442,8 +471,8 @@ class ToolComponentDynamicPackage(ComponentDynamicPackage):
"""
Reset CMFCore list of Tools (manage_addToolForm)
"""
import Products.ERP5
toolinit = Products.ERP5.__FactoryDispatcher__.toolinit
import Products.ERP5Type
toolinit = Products.ERP5Type.__FactoryDispatcher__.toolinit
reset_tool_set = set()
for tool in toolinit.tools:
if not tool.__module__.startswith(self._namespace_prefix):
......
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