Commit 2466cf0e authored by Julien Muchembled's avatar Julien Muchembled

Small optimizations in accessor generation

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43570 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent cdef4993
...@@ -162,55 +162,52 @@ class PropertySheet(Folder): ...@@ -162,55 +162,52 @@ class PropertySheet(Folder):
portal_type_class.importFromFilesystemDefinition(property_sheet, portal_type_class.importFromFilesystemDefinition(property_sheet,
category) category)
# Get filesystem Constraint names to be able to map them properly constraint_list = getattr(definition_class, '_constraints', None)
# to ZODB Constraint Portal Types as some filesystem constraint if constraint_list:
# names are 'NAMEConstraint' or 'NAME' # Get filesystem Constraint names to be able to map them properly
from Products.ERP5Type import Constraint as FilesystemConstraint # to ZODB Constraint Portal Types as some filesystem constraint
filesystem_constraint_class_name_list = [ # names are 'NAMEConstraint' or 'NAME'
class_name for class_name in FilesystemConstraint.__dict__ \ from Products.ERP5Type import Constraint as FilesystemConstraint
if class_name[0] != '_' ] filesystem_constraint_class_name_set = set(class_name
for class_name in FilesystemConstraint.__dict__
# Mapping between the filesystem 'type' field and Portal Types ID if class_name[0] != '_' )
portal_type_dict = {}
# Mapping between the filesystem 'type' field and Portal Types ID
for portal_type_id in types_tool.objectIds(): portal_type_dict = {}
if not portal_type_id.endswith(' Constraint'):
continue for portal_type_id in types_tool.objectIds():
if not portal_type_id.endswith(' Constraint'):
constraint_class_name = portal_type_id.replace(' ', '')
if constraint_class_name not in filesystem_constraint_class_name_list:
constraint_class_name = constraint_class_name.replace('Constraint', '')
if constraint_class_name not in filesystem_constraint_class_name_list:
LOG("Tool.PropertySheetTool", WARNING,
"PropertySheet %s: No matching Constraint found for Portal '%s'" % \
(property_sheet_name, portal_type_id))
continue continue
portal_type_dict[constraint_class_name] = portal_type_id constraint_class_name = portal_type_id.replace(' ', '')
portal_type_dict.update(cls._merged_portal_type_dict) if constraint_class_name not in filesystem_constraint_class_name_set:
constraint_class_name = constraint_class_name.replace('Constraint', '')
if constraint_class_name not in filesystem_constraint_class_name_set:
LOG("Tool.PropertySheetTool", WARNING,
"PropertySheet %s: No matching Constraint found for Portal %r"
% (property_sheet_name, portal_type_id))
continue
for constraint in getattr(definition_class, '_constraints', ()): portal_type_dict[constraint_class_name] = portal_type_id
try:
portal_type = portal_type_dict[constraint['type']]
except KeyError:
# TODO: Constraints without Portal Type yet (e.g. Constraints
# which have not been migrated yet (within BTs or per-project
# Products)) are simply *ignored* for now
LOG("Tool.PropertySheetTool", WARNING,
"Not migrating constraint %s to portal_property_sheets" % \
constraint['type'])
continue portal_type_dict.update(cls._merged_portal_type_dict)
portal_type_class = types_tool.getPortalTypeClass(portal_type)
# Create the new constraint for constraint in constraint_list:
portal_type_class.importFromFilesystemDefinition(property_sheet, try:
constraint) portal_type = portal_type_dict[constraint['type']]
except KeyError:
# TODO: Constraints without Portal Type yet (e.g. Constraints
# which have not been migrated yet (within BTs or per-project
# Products)) are simply *ignored* for now
LOG("Tool.PropertySheetTool", WARNING,
"Not migrating constraint %s to portal_property_sheets"
% constraint['type'])
else:
portal_type_class = types_tool.getPortalTypeClass(portal_type)
# Create the new constraint
portal_type_class.importFromFilesystemDefinition(property_sheet,
constraint)
return property_sheet return property_sheet
......
...@@ -65,16 +65,15 @@ def _createAccessorHolderList(site, ...@@ -65,16 +65,15 @@ def _createAccessorHolderList(site,
""" """
Create the accessor holder list with the given ZODB Property Sheets Create the accessor holder list with the given ZODB Property Sheets
""" """
import erp5.accessor_holder from erp5 import accessor_holder
property_sheet_tool = site.portal_property_sheets getPropertySheet = site.portal_property_sheets._getOb
accessor_holder_list = [] accessor_holder_list = []
if "Base" in property_sheet_name_set: if "Base" in property_sheet_name_set:
# useless if Base Category is not yet here or if we're currently # useless if Base Category is not yet here or if we're currently
# generating accessors for Base Categories # generating accessors for Base Categories
accessor_holder_class = _generateBaseAccessorHolder(site, accessor_holder_class = _generateBaseAccessorHolder(site, accessor_holder)
erp5.accessor_holder)
if accessor_holder_class is not None: if accessor_holder_class is not None:
accessor_holder_list.append(accessor_holder_class) accessor_holder_list.append(accessor_holder_class)
...@@ -85,25 +84,22 @@ def _createAccessorHolderList(site, ...@@ -85,25 +84,22 @@ def _createAccessorHolderList(site,
try: try:
# Get the already generated accessor holder # Get the already generated accessor holder
accessor_holder_list.append(getattr(erp5.accessor_holder, accessor_holder_list.append(getattr(accessor_holder, property_sheet_name))
property_sheet_name))
except AttributeError: except AttributeError:
# Generate the accessor holder as it has not been done yet # Generate the accessor holder as it has not been done yet
try: try:
property_sheet = getattr(property_sheet_tool, property_sheet_name) property_sheet = getPropertySheet(property_sheet_name)
accessor_holder_class = property_sheet.createAccessorHolder() accessor_holder_class = property_sheet.createAccessorHolder()
except Exception: except Exception:
LOG("ERP5Type.dynamic", ERROR, LOG("ERP5Type.dynamic", ERROR,
"Ignoring missing or Invalid Property Sheet " + property_sheet_name) "Ignoring missing or Invalid Property Sheet " + property_sheet_name)
raise raise
accessor_holder_list.append(accessor_holder_class) accessor_holder_list.append(accessor_holder_class)
setattr(erp5.accessor_holder, property_sheet_name, setattr(accessor_holder, property_sheet_name, accessor_holder_class)
accessor_holder_class)
# LOG("ERP5Type.dynamic", INFO, # LOG("ERP5Type.dynamic", INFO,
# "Created accessor holder for %s" % property_sheet_name) # "Created accessor holder for %s" % property_sheet_name)
...@@ -113,7 +109,7 @@ def _createAccessorHolderList(site, ...@@ -113,7 +109,7 @@ def _createAccessorHolderList(site,
accessor_holder_class = \ accessor_holder_class = \
_generatePreferenceToolAccessorHolder(site, _generatePreferenceToolAccessorHolder(site,
accessor_holder_list, accessor_holder_list,
erp5.accessor_holder) accessor_holder)
accessor_holder_list.insert(0, accessor_holder_class) accessor_holder_list.insert(0, accessor_holder_class)
......
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