Commit 6b765217 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Move initializeDynamicModules to dynamic_module, meaningful for components as well.

parent 59110c92
...@@ -1042,7 +1042,7 @@ def initializeProduct( context, ...@@ -1042,7 +1042,7 @@ def initializeProduct( context,
try: try:
import erp5.portal_type import erp5.portal_type
except ImportError: except ImportError:
from dynamic.portal_type_class import initializeDynamicModules from dynamic.dynamic_module import initializeDynamicModules
initializeDynamicModules() initializeDynamicModules()
import erp5.portal_type import erp5.portal_type
......
##############################################################################
#
# Copyright (c) 2010-2012 Nexedi SARL and Contributors. All Rights Reserved.
# Nicolas Dumazet <nicolas.dumazet@nexedi.com>
# Arnaud Fontaine <arnaud.fontaine@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
from types import ModuleType from types import ModuleType
import sys import sys
import threading import threading
...@@ -38,3 +67,52 @@ def registerDynamicModule(name, factory): ...@@ -38,3 +67,52 @@ def registerDynamicModule(name, factory):
d = DynamicModule(name, factory) d = DynamicModule(name, factory)
sys.modules[name] = d sys.modules[name] = d
return d return d
def initializeDynamicModules():
"""
Create erp5 module and its submodules
erp5.portal_type
holds portal type classes
erp5.temp_portal_type
holds portal type classes for temp objects
erp5.document
holds document classes that have no physical import path,
for example classes created through ClassTool that are in
$INSTANCE_HOME/Document
erp5.accessor_holder
holds accessor holders common to ZODB Property Sheets and Portal Types
erp5.accessor_holder.property_sheet
holds accessor holders of ZODB Property Sheets
erp5.accessor_holder.portal_type
holds accessors holders of Portal Types
"""
erp5 = ModuleType("erp5")
sys.modules["erp5"] = erp5
# Document classes without physical import path
erp5.document = ModuleType("erp5.document")
sys.modules["erp5.document"] = erp5.document
# Portal types as classes
from accessor_holder import AccessorHolderType, AccessorHolderModuleType
erp5.accessor_holder = AccessorHolderModuleType("erp5.accessor_holder")
sys.modules["erp5.accessor_holder"] = erp5.accessor_holder
erp5.accessor_holder.property_sheet = \
AccessorHolderModuleType("erp5.accessor_holder.property_sheet")
sys.modules["erp5.accessor_holder.property_sheet"] = \
erp5.accessor_holder.property_sheet
erp5.accessor_holder.portal_type = registerDynamicModule(
'erp5.accessor_holder.portal_type',
AccessorHolderModuleType)
from lazy_class import generateLazyPortalTypeClass
erp5.portal_type = registerDynamicModule('erp5.portal_type',
generateLazyPortalTypeClass)
from portal_type_class import loadTempPortalTypeClass
erp5.temp_portal_type = registerDynamicModule('erp5.temp_portal_type',
loadTempPortalTypeClass)
...@@ -31,16 +31,13 @@ import sys ...@@ -31,16 +31,13 @@ import sys
import os import os
import inspect import inspect
import transaction import transaction
from types import ModuleType
from Products.ERP5Type.dynamic.dynamic_module import registerDynamicModule
from Products.ERP5Type.mixin.temporary import TemporaryDocumentMixin from Products.ERP5Type.mixin.temporary import TemporaryDocumentMixin
from Products.ERP5Type.Base import Base, resetRegisteredWorkflowMethod from Products.ERP5Type.Base import Base, resetRegisteredWorkflowMethod
from Products.ERP5Type.Globals import InitializeClass from Products.ERP5Type.Globals import InitializeClass
from Products.ERP5Type.Utils import setDefaultClassProperties from Products.ERP5Type.Utils import setDefaultClassProperties
from Products.ERP5Type import document_class_registry, mixin_class_registry from Products.ERP5Type import document_class_registry, mixin_class_registry
from Products.ERP5Type.dynamic.accessor_holder import AccessorHolderModuleType, \ from Products.ERP5Type.dynamic.accessor_holder import createAllAccessorHolderList
createAllAccessorHolderList
from Products.ERP5Type.TransactionalVariable import TransactionalResource from Products.ERP5Type.TransactionalVariable import TransactionalResource
from zLOG import LOG, ERROR, INFO, WARNING, PANIC from zLOG import LOG, ERROR, INFO, WARNING, PANIC
...@@ -250,63 +247,20 @@ def generatePortalTypeClass(site, portal_type_name): ...@@ -250,63 +247,20 @@ def generatePortalTypeClass(site, portal_type_name):
interface_class_list, interface_class_list,
attribute_dict) attribute_dict)
from lazy_class import generateLazyPortalTypeClass def loadTempPortalTypeClass(portal_type_name):
def initializeDynamicModules():
""" """
Create erp5 module and its submodules Returns a class suitable for a temporary portal type
erp5.portal_type
holds portal type classes
erp5.temp_portal_type
holds portal type classes for temp objects
erp5.document
holds document classes that have no physical import path,
for example classes created through ClassTool that are in
$INSTANCE_HOME/Document
erp5.accessor_holder
holds accessor holders common to ZODB Property Sheets and Portal Types
erp5.accessor_holder.property_sheet
holds accessor holders of ZODB Property Sheets
erp5.accessor_holder.portal_type
holds accessors holders of Portal Types
"""
erp5 = ModuleType("erp5")
sys.modules["erp5"] = erp5
erp5.document = ModuleType("erp5.document")
sys.modules["erp5.document"] = erp5.document
erp5.accessor_holder = AccessorHolderModuleType("erp5.accessor_holder")
sys.modules["erp5.accessor_holder"] = erp5.accessor_holder
erp5.accessor_holder.property_sheet = \
AccessorHolderModuleType("erp5.accessor_holder.property_sheet")
sys.modules["erp5.accessor_holder.property_sheet"] = \
erp5.accessor_holder.property_sheet
erp5.accessor_holder.portal_type = registerDynamicModule(
'erp5.accessor_holder.portal_type',
AccessorHolderModuleType)
portal_type_container = registerDynamicModule('erp5.portal_type',
generateLazyPortalTypeClass)
erp5.portal_type = portal_type_container This class will in fact be a subclass of erp5.portal_type.xxx, which
means that loading an attribute on this temporary portal type loads
def loadTempPortalTypeClass(portal_type_name): the lazily-loaded parent class, and that any changes on the parent
""" class will be reflected on the temporary objects.
Returns a class suitable for a temporary portal type """
import erp5.portal_type
This class will in fact be a subclass of erp5.portal_type.xxx, which klass = getattr(erp5.portal_type, portal_type_name)
means that loading an attribute on this temporary portal type loads
the lazily-loaded parent class, and that any changes on the parent
class will be reflected on the temporary objects.
"""
klass = getattr(portal_type_container, portal_type_name)
return type("Temporary %s" % portal_type_name,
(TemporaryDocumentMixin, klass), {})
erp5.temp_portal_type = registerDynamicModule('erp5.temp_portal_type', return type("Temporary %s" % portal_type_name,
loadTempPortalTypeClass) (TemporaryDocumentMixin, klass), {})
last_sync = -1 last_sync = -1
_bootstrapped = set() _bootstrapped = set()
......
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