Commit f7f587d8 authored by Nicolas Dumazet's avatar Nicolas Dumazet

naming fixes


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39428 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a483495c
...@@ -967,8 +967,9 @@ def importLocalDocument(class_id, document_path = None): ...@@ -967,8 +967,9 @@ def importLocalDocument(class_id, document_path = None):
return MigrateMe return MigrateMe
else: else:
return klass return klass
from dynamic.dynamic_module import newDynamicModule from dynamic.dynamic_module import registerDynamicModule
document_module = newDynamicModule(module_name, migrate_me_document_loader) document_module = registerDynamicModule(module_name,
migrate_me_document_loader)
setattr(Products.ERP5Type.Document, class_id, document_module) setattr(Products.ERP5Type.Document, class_id, document_module)
......
...@@ -19,7 +19,7 @@ class DynamicModule(ModuleType): ...@@ -19,7 +19,7 @@ class DynamicModule(ModuleType):
setattr(self, name, obj) setattr(self, name, obj)
return obj return obj
def newDynamicModule(name, factory): def registerDynamicModule(name, factory):
d = DynamicModule(name, factory) d = DynamicModule(name, factory)
sys.modules[name] = d sys.modules[name] = d
return d return d
...@@ -3,7 +3,8 @@ from ExtensionClass import Base as ExtensionBase ...@@ -3,7 +3,8 @@ from ExtensionClass import Base as ExtensionBase
from zLOG import LOG, ERROR, BLATHER from zLOG import LOG, ERROR, BLATHER
def newLazyClass(name, portal_type_class_attr_getter): def generateLazyPortalTypeClass(portal_type_name,
portal_type_class_loader):
def load(self, attr): def load(self, attr):
klass = None klass = None
# self might be a subclass of a portal type class # self might be a subclass of a portal type class
...@@ -18,12 +19,14 @@ def newLazyClass(name, portal_type_class_attr_getter): ...@@ -18,12 +19,14 @@ def newLazyClass(name, portal_type_class_attr_getter):
portal_type = klass.__name__ portal_type = klass.__name__
try: try:
baseclasses, attributes = portal_type_class_attr_getter(portal_type) baseclasses, attributes = portal_type_class_loader(portal_type)
except AttributeError: except AttributeError:
LOG("ERP5Type.Dynamic", ERROR, LOG("ERP5Type.Dynamic", ERROR,
"Could not access Portal Type Object for type %s" % name) "Could not access Portal Type Object for type %s"
% portal_type_name)
import traceback; traceback.print_exc() import traceback; traceback.print_exc()
raise AttributeError("Could not access Portal Type Object for type %s" % name) raise AttributeError("Could not access Portal Type Object for type %s"
% portal_type_name)
# save the old bases to be able to restore a ghost state later # save the old bases to be able to restore a ghost state later
klass.__ghostbase__ = klass.__bases__ klass.__ghostbase__ = klass.__bases__
...@@ -67,4 +70,4 @@ def newLazyClass(name, portal_type_class_attr_getter): ...@@ -67,4 +70,4 @@ def newLazyClass(name, portal_type_class_attr_getter):
# "loading attribute %s.%s..." % (name, attr)) # "loading attribute %s.%s..." % (name, attr))
return load(self, attr) return load(self, attr)
return type(name, (GhostPortalType,), dict()) return type(portal_type_name, (GhostPortalType,), dict())
...@@ -32,8 +32,8 @@ import inspect ...@@ -32,8 +32,8 @@ import inspect
from types import ModuleType from types import ModuleType
from dynamic_module import newDynamicModule from dynamic_module import registerDynamicModule
from lazy_class import newLazyClass from lazy_class import generateLazyPortalTypeClass
from Products.ERP5Type.Globals import InitializeClass from Products.ERP5Type.Globals import InitializeClass
from Products.ERP5Type.Utils import setDefaultClassProperties from Products.ERP5Type.Utils import setDefaultClassProperties
...@@ -93,7 +93,7 @@ def _fillAccessorHolderList(accessor_holder_list, ...@@ -93,7 +93,7 @@ def _fillAccessorHolderList(accessor_holder_list,
"Created accessor holder for %s in %s" % (property_sheet_name, "Created accessor holder for %s in %s" % (property_sheet_name,
accessor_holder_module)) accessor_holder_module))
def portalTypeFactory(portal_type_name): def generatePortalTypeClass(portal_type_name):
""" """
Given a portal type, look up in Types Tool the corresponding Given a portal type, look up in Types Tool the corresponding
Base Type object holding the definition of this portal type, Base Type object holding the definition of this portal type,
...@@ -209,11 +209,12 @@ def initializeDynamicModules(): ...@@ -209,11 +209,12 @@ def initializeDynamicModules():
XXX: there should be only one accessor_holder once the code is XXX: there should be only one accessor_holder once the code is
stable and all the Property Sheets have been migrated stable and all the Property Sheets have been migrated
""" """
def portalTypeLoader(portal_type_name): def loadPortalTypeClass(portal_type_name):
""" """
Returns a lazily-loaded "portal-type as a class" Returns a lazily-loaded "portal-type as a class"
""" """
return newLazyClass(portal_type_name, portalTypeFactory) return generateLazyPortalTypeClass(portal_type_name,
generatePortalTypeClass)
erp5 = ModuleType("erp5") erp5 = ModuleType("erp5")
sys.modules["erp5"] = erp5 sys.modules["erp5"] = erp5
...@@ -225,12 +226,12 @@ def initializeDynamicModules(): ...@@ -225,12 +226,12 @@ def initializeDynamicModules():
erp5.filesystem_accessor_holder = ModuleType("erp5.filesystem_accessor_holder") erp5.filesystem_accessor_holder = ModuleType("erp5.filesystem_accessor_holder")
sys.modules["erp5.filesystem_accessor_holder"] = erp5.filesystem_accessor_holder sys.modules["erp5.filesystem_accessor_holder"] = erp5.filesystem_accessor_holder
portal_type_container = newDynamicModule('erp5.portal_type', portal_type_container = registerDynamicModule('erp5.portal_type',
portalTypeLoader) loadPortalTypeClass)
erp5.portal_type = portal_type_container erp5.portal_type = portal_type_container
def tempPortalTypeLoader(portal_type_name): def loadTempPortalTypeClass(portal_type_name):
""" """
Returns a class suitable for a temporary portal type Returns a class suitable for a temporary portal type
...@@ -262,8 +263,8 @@ def initializeDynamicModules(): ...@@ -262,8 +263,8 @@ def initializeDynamicModules():
setattr(TempDocument, '%s__roles__' % method_id, None) setattr(TempDocument, '%s__roles__' % method_id, None)
return TempDocument return TempDocument
erp5.temp_portal_type = newDynamicModule('erp5.temp_portal_type', erp5.temp_portal_type = registerDynamicModule('erp5.temp_portal_type',
tempPortalTypeLoader) loadTempPortalTypeClass)
def _clearAccessorHolderModule(module): def _clearAccessorHolderModule(module):
""" """
......
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