[Erp5-report] r43570 jm - in /erp5/trunk/products/ERP5Type: Core/ dynamic/

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Feb 22 17:59:38 CET 2011


Author: jm
Date: Tue Feb 22 17:59:38 2011
New Revision: 43570

URL: http://svn.erp5.org?rev=43570&view=rev
Log:
Small optimizations in accessor generation

Modified:
    erp5/trunk/products/ERP5Type/Core/PropertySheet.py
    erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py

Modified: erp5/trunk/products/ERP5Type/Core/PropertySheet.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Core/PropertySheet.py?rev=43570&r1=43569&r2=43570&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Core/PropertySheet.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Core/PropertySheet.py [utf8] Tue Feb 22 17:59:38 2011
@@ -162,55 +162,52 @@ class PropertySheet(Folder):
       portal_type_class.importFromFilesystemDefinition(property_sheet,
                                                        category)
 
-    # Get filesystem Constraint names to be able to map them properly
-    # to ZODB Constraint Portal Types as some filesystem constraint
-    # names are 'NAMEConstraint' or 'NAME'
-    from Products.ERP5Type import Constraint as FilesystemConstraint
-    filesystem_constraint_class_name_list = [
-      class_name for class_name in FilesystemConstraint.__dict__ \
-      if class_name[0] != '_' ]
-
-    # Mapping between the filesystem 'type' field and Portal Types ID
-    portal_type_dict = {}
-
-    for portal_type_id in types_tool.objectIds():
-      if not portal_type_id.endswith(' Constraint'):
-        continue
+    constraint_list = getattr(definition_class, '_constraints', None)
+    if constraint_list:
+      # Get filesystem Constraint names to be able to map them properly
+      # to ZODB Constraint Portal Types as some filesystem constraint
+      # names are 'NAMEConstraint' or 'NAME'
+      from Products.ERP5Type import Constraint as FilesystemConstraint
+      filesystem_constraint_class_name_set = set(class_name
+        for class_name in FilesystemConstraint.__dict__
+        if class_name[0] != '_' )
 
-      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))
+      # Mapping between the filesystem 'type' field and Portal Types ID
+      portal_type_dict = {}
 
+      for portal_type_id in types_tool.objectIds():
+        if not portal_type_id.endswith(' Constraint'):
           continue
 
-      portal_type_dict[constraint_class_name] = portal_type_id
-
-    portal_type_dict.update(cls._merged_portal_type_dict)
-
-    for constraint in getattr(definition_class, '_constraints', ()):
-      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'])
+        constraint_class_name = portal_type_id.replace(' ', '')
 
-        continue
-
-      portal_type_class = types_tool.getPortalTypeClass(portal_type)
-
-      # Create the new constraint
-      portal_type_class.importFromFilesystemDefinition(property_sheet,
-                                                       constraint)
+        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
+
+        portal_type_dict[constraint_class_name] = portal_type_id
+
+      portal_type_dict.update(cls._merged_portal_type_dict)
+
+      for constraint in constraint_list:
+        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'])
+        else:
+          portal_type_class = types_tool.getPortalTypeClass(portal_type)
+          # Create the new constraint
+          portal_type_class.importFromFilesystemDefinition(property_sheet,
+                                                           constraint)
 
     return property_sheet
 

Modified: erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py?rev=43570&r1=43569&r2=43570&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py [utf8] Tue Feb 22 17:59:38 2011
@@ -65,16 +65,15 @@ def _createAccessorHolderList(site,
   """
   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 = []
 
   if "Base" in property_sheet_name_set:
     # useless if Base Category is not yet here or if we're currently
     # generating accessors for Base Categories
-    accessor_holder_class = _generateBaseAccessorHolder(site,
-                                                        erp5.accessor_holder)
+    accessor_holder_class = _generateBaseAccessorHolder(site, accessor_holder)
 
     if accessor_holder_class is not None:
       accessor_holder_list.append(accessor_holder_class)
@@ -85,25 +84,22 @@ def _createAccessorHolderList(site,
 
     try:
       # Get the already generated accessor holder
-      accessor_holder_list.append(getattr(erp5.accessor_holder,
-                                          property_sheet_name))
+      accessor_holder_list.append(getattr(accessor_holder, property_sheet_name))
 
     except AttributeError:
       # Generate the accessor holder as it has not been done yet
       try:
-        property_sheet = getattr(property_sheet_tool, property_sheet_name)
+        property_sheet = getPropertySheet(property_sheet_name)
         accessor_holder_class = property_sheet.createAccessorHolder()
 
       except Exception:
         LOG("ERP5Type.dynamic", ERROR,
             "Ignoring missing or Invalid Property Sheet " + property_sheet_name)
-
         raise
 
       accessor_holder_list.append(accessor_holder_class)
 
-      setattr(erp5.accessor_holder, property_sheet_name,
-              accessor_holder_class)
+      setattr(accessor_holder, property_sheet_name, accessor_holder_class)
 
       # LOG("ERP5Type.dynamic", INFO,
       #     "Created accessor holder for %s" % property_sheet_name)
@@ -113,7 +109,7 @@ def _createAccessorHolderList(site,
     accessor_holder_class = \
         _generatePreferenceToolAccessorHolder(site,
                                               accessor_holder_list,
-                                              erp5.accessor_holder)
+                                              accessor_holder)
 
     accessor_holder_list.insert(0, accessor_holder_class)
 



More information about the Erp5-report mailing list