[CMF-checkins] CVS: CMF/CMFSetup - DEPENDENCIES.txt:1.1.2.1 __init__.py:1.8.2.3 typeinfo.py:1.12.2.9 utils.py:1.13.2.8

Florent Guillaume fg at nuxeo.com
Fri Jul 1 09:28:16 EDT 2005


Update of /cvs-repository/CMF/CMFSetup
In directory cvs.zope.org:/tmp/cvs-serv32673/CMFSetup

Modified Files:
      Tag: CMF-1_5-branch
	DEPENDENCIES.txt __init__.py typeinfo.py utils.py 
Log Message:
Merge from HEAD:

Use a new XML format for import/export of types, where the properties
are generic. Now arbitrary TypeInformation objects can be used, as long
as they are configured using properties.

Split ConfiguratorBase into ImportConfiguratorBase and
ExportConfiguratorBase, as they really are unrelated.
Split typeinfo configurators and tests into Import and Export version.



=== CMF/CMFSetup/DEPENDENCIES.txt 1.1 => 1.1.2.1 ===
--- CMF/CMFSetup/DEPENDENCIES.txt:1.1	Thu Aug  5 04:15:08 2004
+++ CMF/CMFSetup/DEPENDENCIES.txt	Fri Jul  1 09:27:45 2005
@@ -1,4 +1,4 @@
 Zope >= 2.7.0
 CMFCore
 CMFDefault
-DCWorkflow
\ No newline at end of file
+DCWorkflow


=== CMF/CMFSetup/__init__.py 1.8.2.2 => 1.8.2.3 ===
--- CMF/CMFSetup/__init__.py:1.8.2.2	Tue Apr  5 11:17:16 2005
+++ CMF/CMFSetup/__init__.py	Fri Jul  1 09:27:45 2005
@@ -51,58 +51,3 @@
                          , permissions=( 'Add CMF Sites', )
                          , interfaces=None
                          )
-
-    return # XXX comment out the rest
-
-    # XXX:  This is *all* policy, and belongs in an XML file!
-
-    # Install setup steps and export scripts
-    from SetupSteps import installTools
-    from SetupSteps import configureCookieCrumbler
-
-    registerSetupStep('installTools', '2004/05/10-01',
-                    installTools)
-
-    registerSetupStep('configureCookieCrumbler', '2004/05/10-01',
-                    configureCookieCrumbler)
-
-    from CatalogIndexesConfig import configureCatalogIndexes
-    from CatalogIndexesConfig import exportCatalogIndexes
-
-    registerSetupStep('configureCatalogIndexes', '2004/05/10-01',
-                      configureCatalogIndexes, ('installTools',))
-    registerExportScript('exportCatalogIndexes', exportCatalogIndexes)
-
-    from SkeletonBuilder import buildFolderStructure
-    from SkeletonBuilder import generateSkeleton
-
-    registerSetupStep('buildFolderStructure', '2004/05/10-01',
-                      buildFolderStructure, ( 'installTypes'
-                                            , 'configureSkins'
-                                            , 'configureWorkflows'
-                                            # Because the folder buildout will
-                                            # need to know whomever is the
-                                            # author of certain content:
-                                            , 'installMembershipToolContent'
-                                            ))
-    registerExportScript('generateSkeleton', generateSkeleton)
-
-    from ActionIconsConfig import configureActionIcons, exportActionIcons
-    registerSetupStep('configureActionIcons', '2004/05/10-02',
-                      configureActionIcons, ('installTools',))
-    registerExportScript('exportActionIcons', exportActionIcons)
-
-    from MembershipConfig import installMembershipToolContent
-    from MembershipConfig import exportMembershipToolContent
-    registerSetupStep('installMembershipToolContent', '2004/05/10-01',
-                      installMembershipToolContent, ('installTools',
-                                                     'installTypes'))
-    registerExportScript('exportMembershipToolContent',
-                         exportMembershipToolContent)
-
-    from MemberDataConfig import configureMemberDataTool
-    from MemberDataConfig import exportMemberDataToolConfig
-    registerSetupStep('configureMemberDataTool', '2004/05/10-01',
-                      configureMemberDataTool, ())
-    registerExportScript('exportMemberDataToolConfig',
-                         exportMemberDataToolConfig)


=== CMF/CMFSetup/typeinfo.py 1.12.2.8 => 1.12.2.9 ===
--- CMF/CMFSetup/typeinfo.py:1.12.2.8	Wed Apr 13 09:05:01 2005
+++ CMF/CMFSetup/typeinfo.py	Fri Jul  1 09:27:45 2005
@@ -19,14 +19,12 @@
 from Globals import InitializeClass
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 
-from Products.CMFCore.TypesTool import FactoryTypeInformation
-from Products.CMFCore.TypesTool import ScriptableTypeInformation
 from Products.CMFCore.TypesTool import typeClasses
 from Products.CMFCore.utils import getToolByName
 
 from permissions import ManagePortal
 from utils import _xmldir
-from utils import ConfiguratorBase
+from utils import ImportConfiguratorBase, ExportConfiguratorBase
 from utils import CONVERTER, DEFAULT, KEY
 
 
@@ -49,13 +47,14 @@
         for type in types_tool.objectIds():
             types_tool._delObject(type)
 
-    ttc = TypesToolConfigurator( site, encoding )
+    ttc = TypesToolImportConfigurator( site, encoding )
     xml = context.readDataFile( _TOOL_FILENAME )
     if xml is None:
         return 'Types tool: Nothing to import.'
 
     tool_info = ttc.parseXML( xml )
-    tic = TypeInfoConfigurator( site, encoding )
+    tic = TypeInfoImportConfigurator( site, encoding )
+    old_tic = OldTypeInfoImportConfigurator( site, encoding )
 
     for type_info in tool_info[ 'types' ]:
 
@@ -65,7 +64,12 @@
             text = context.readDataFile( filename )
         else:
             text = context.readDataFile( filename[sep+1:], filename[:sep] )
-        info = tic.parseXML( text )
+
+        is_old = '<description>' in text
+        if is_old:
+            info = old_tic.parseXML( text )
+        else:
+            info = tic.parseXML( text )
 
         type_id = str(info['id'])
         if 'kind' in info:
@@ -87,7 +91,11 @@
         else:
             type_info = types_tool._getOb(type_id)
 
-        type_info.manage_changeProperties(**info)
+        if is_old:
+            type_info.manage_changeProperties(**info)
+        else:
+            for prop_info in info['properties']:
+                tic.initProperty(type_info, prop_info)
 
         if 'actions' in info:
             type_info._actions = info['actions']
@@ -113,8 +121,8 @@
     site = context.getSite()
     types_tool = getToolByName( site, 'portal_types' )
 
-    ttc = TypesToolConfigurator( site ).__of__( site )
-    tic = TypeInfoConfigurator( site ).__of__( site )
+    ttc = TypesToolExportConfigurator( site ).__of__( site )
+    tic = TypeInfoExportConfigurator( site ).__of__( site )
 
     tool_xml = ttc.generateXML()
     context.writeDataFile( _TOOL_FILENAME, tool_xml, 'text/xml' )
@@ -135,37 +143,7 @@
     return 'Types tool exported'
 
 
-class TypesToolConfigurator(ConfiguratorBase):
-
-    security = ClassSecurityInfo()
-
-    security.declareProtected( ManagePortal, 'listTypeInfo' )
-    def listTypeInfo( self ):
-
-        """ Return a list of mappings for each type info in the site.
-
-        o These mappings are pretty much equivalent to the stock
-          'factory_type_information' elements used everywhere in the
-          CMF.
-        """
-        result = []
-        typestool = getToolByName( self._site, 'portal_types' )
-
-        type_ids = typestool.listContentTypes()
-
-        for type_id in type_ids:
-            info = {'id': type_id}
-
-            if ' ' in type_id:
-                info['filename'] = _getTypeFilename(type_id)
-
-            result.append(info)
-
-        return result
-
-    def _getExportTemplate(self):
-
-        return PageTemplateFile('ticToolExport.xml', _xmldir)
+class TypesToolImportConfigurator(ImportConfiguratorBase):
 
     def _getImportMapping(self):
 
@@ -185,72 +163,56 @@
 
         return val
 
-InitializeClass(TypesToolConfigurator)
+InitializeClass(TypesToolImportConfigurator)
 
 
-class TypeInfoConfigurator(ConfiguratorBase):
+class TypesToolExportConfigurator(ExportConfiguratorBase):
 
     security = ClassSecurityInfo()
 
-    security.declareProtected( ManagePortal, 'getTypeInfo' )
-    def getTypeInfo( self, type_id ):
+    security.declareProtected( ManagePortal, 'listTypeInfo' )
+    def listTypeInfo( self ):
 
-        """ Return a mapping for the given type info in the site.
+        """ Return a list of mappings for each type info in the site.
 
         o These mappings are pretty much equivalent to the stock
           'factory_type_information' elements used everywhere in the
           CMF.
         """
+        result = []
         typestool = getToolByName( self._site, 'portal_types' )
-        try:
-            ti = typestool.getTypeInfo( str( type_id ) ) # gTI expects ASCII?
-        except KeyError:
-            raise ValueError, 'Unknown type: %s' % type_id
-        else:
-            return self._makeTIMapping( ti )
 
-    security.declarePrivate( '_makeTIMapping' )
-    def _makeTIMapping( self, ti ):
+        type_ids = typestool.listContentTypes()
 
-        """ Convert a TypeInformation object into the appropriate mapping.
-        """
-        result = { 'id'                     : ti.getId()
-                 , 'title'                  : ti.Title()
-                 , 'description'            : ti.Description().strip()
-                 , 'meta_type'              : ti.Metatype()
-                 , 'icon'                   : ti.getIcon()
-                 , 'immediate_view'         : ti.immediate_view
-                 , 'global_allow'           : bool(ti.global_allow)
-                 , 'filter_content_types'   : bool(ti.filter_content_types)
-                 , 'allowed_content_types'  : ti.allowed_content_types
-                 , 'allow_discussion'       : bool(ti.allow_discussion)
-                 , 'aliases'                : ti.getMethodAliases()
-                 }
-
-        if ' ' in ti.getId():
-
-            result[ 'filename' ]    = _getTypeFilename( ti.getId() )
-
-        if isinstance( ti, FactoryTypeInformation ):
-
-            result[ 'kind' ]        = FactoryTypeInformation.meta_type
-            result[ 'product' ]     = ti.product
-            result[ 'factory' ]     = ti.factory
-
-        elif isinstance( ti, ScriptableTypeInformation ):
-
-            result[ 'kind' ]             = ScriptableTypeInformation.meta_type
-            result[ 'permission' ]       = ti.permission
-            result[ 'constructor_path' ] = ti.constructor_path
+        for type_id in type_ids:
+            info = {'id': type_id}
 
-        actions = ti.listActions()
-        result['actions'] = [ ai.getMapping() for ai in actions ]
+            if ' ' in type_id:
+                info['filename'] = _getTypeFilename(type_id)
+
+            result.append(info)
 
         return result
 
     def _getExportTemplate(self):
 
-        return PageTemplateFile('ticTypeExport.xml', _xmldir)
+        return PageTemplateFile('ticToolExport.xml', _xmldir)
+
+InitializeClass(TypesToolExportConfigurator)
+
+
+# BBB: will be removed in CMF 1.7
+class TypesToolConfigurator(TypesToolImportConfigurator,
+                            TypesToolExportConfigurator):
+    def __init__(self, site, encoding=None):
+        TypesToolImportConfigurator.__init__(self, site, encoding)
+        TypesToolExportConfigurator.__init__(self, site, encoding)
+
+InitializeClass(TypesToolConfigurator)
+
+
+# BBB: will be removed in CMF 1.7
+class OldTypeInfoImportConfigurator(ImportConfiguratorBase):
 
     def _getImportMapping(self):
 
@@ -300,6 +262,109 @@
             result[ alias['from'] ] = alias['to']
 
         return result
+
+InitializeClass(OldTypeInfoImportConfigurator)
+
+
+class TypeInfoImportConfigurator(ImportConfiguratorBase):
+
+    def _getImportMapping(self):
+
+        return {
+          'type-info':
+            { 'id':                   {},
+              'kind':                 {},
+              'aliases':              {CONVERTER: self._convertAliases},
+              'action':               {KEY: 'actions'},
+              'property':             {KEY: 'properties', DEFAULT: ()},
+              },
+          'aliases':
+            { 'alias':                {KEY: None} },
+          'alias':
+            { 'from':                 {},
+              'to':                   {} },
+          'action':
+            { 'action_id':            {KEY: 'id'},
+              'title':                {},
+              'description':          {CONVERTER: self._convertToUnique},
+              'category':             {},
+              'condition_expr':       {KEY: 'condition'},
+              'permission':           {KEY: 'permissions', DEFAULT: ()},
+              'visible':              {CONVERTER: self._convertToBoolean},
+              'url_expr':             {KEY: 'action'} },
+          'permission':
+            { '#text':                {KEY: None} } }
+
+    def _convertAliases(self, val):
+
+        result = {}
+
+        for alias in val[0]:
+            result[ alias['from'] ] = alias['to']
+
+        return result
+
+InitializeClass(TypeInfoImportConfigurator)
+
+
+class TypeInfoExportConfigurator(ExportConfiguratorBase):
+
+    security = ClassSecurityInfo()
+
+    security.declareProtected( ManagePortal, 'getTypeInfo' )
+    def getTypeInfo( self, type_id ):
+
+        """ Return a mapping for the given type info in the site.
+
+        o These mappings are pretty much equivalent to the stock
+          'factory_type_information' elements used everywhere in the
+          CMF.
+        """
+        ti = self._getTI(type_id)
+        return self._makeTIMapping(ti)
+
+    security.declarePrivate('_getTI' )
+    def _getTI(self, type_id):
+        """Get the TI from its id."""
+        typestool = getToolByName(self._site, 'portal_types')
+        try:
+            return typestool.getTypeInfo(str(type_id)) # gTI expects ASCII?
+        except KeyError:
+            raise ValueError("Unknown type: %s" % type_id)
+
+    security.declarePrivate( '_makeTIMapping' )
+    def _makeTIMapping( self, ti ):
+
+        """ Convert a TypeInformation object into the appropriate mapping.
+        """
+        return {
+            'id': ti.getId(),
+            'kind': ti.meta_type,
+            'aliases': ti.getMethodAliases(),
+            'actions': [ai.getMapping() for ai in ti.listActions()],
+            }
+
+    security.declareProtected(ManagePortal, 'generateProperties')
+    def generateProperties(self, type_id):
+        """Get a sequence of mappings for properties."""
+        ti = self._getTI(type_id)
+        prop_infos = [self._extractProperty(ti, prop_map)
+                      for prop_map in ti._propertyMap()]
+        return self.generatePropertyNodes(prop_infos)
+
+    def _getExportTemplate(self):
+
+        return PageTemplateFile('ticTypeExport.xml', _xmldir)
+
+InitializeClass(TypeInfoExportConfigurator)
+
+
+# BBB: will be removed in CMF 1.7
+class TypeInfoConfigurator(TypeInfoImportConfigurator,
+                           TypeInfoExportConfigurator):
+    def __init__(self, site, encoding=None):
+        TypeInfoImportConfigurator.__init__(self, site, encoding)
+        TypeInfoExportConfigurator.__init__(self, site, encoding)
 
 InitializeClass(TypeInfoConfigurator)
 


=== CMF/CMFSetup/utils.py 1.13.2.7 => 1.13.2.8 ===
--- CMF/CMFSetup/utils.py:1.13.2.7	Sun May  8 14:58:33 2005
+++ CMF/CMFSetup/utils.py	Fri Jul  1 09:27:45 2005
@@ -134,8 +134,8 @@
         return content.encode( self._encoding )
 
 
-class ConfiguratorBase(Implicit):
-    """ Synthesize XML description.
+class ImportConfiguratorBase(Implicit):
+    """ Synthesize data from XML description.
     """
     security = ClassSecurityInfo()
     security.setDefaultAccess('allow')
@@ -144,13 +144,6 @@
 
         self._site = site
         self._encoding = encoding
-        self._template = self._getExportTemplate()
-
-    security.declareProtected(ManagePortal, 'generateXML')
-    def generateXML(self, **kw):
-        """ Pseudo API.
-        """
-        return self._template(**kw)
 
     security.declareProtected(ManagePortal, 'parseXML')
     def parseXML(self, xml):
@@ -245,26 +238,6 @@
         assert len(val) == 1
         return val[0]
 
-    #
-    #   generic object and property support
-    #
-    _o_nodes = PageTemplateFile('object_nodes.xml', _xmldir)
-    _p_nodes = PageTemplateFile('property_nodes.xml', _xmldir)
-
-    security.declareProtected(ManagePortal, 'generateObjectNodes')
-    def generateObjectNodes(self, obj_infos):
-        """ Pseudo API.
-        """
-        lines = self._o_nodes(objects=obj_infos).splitlines()
-        return '\n'.join(lines)
-
-    security.declareProtected(ManagePortal, 'generatePropertyNodes')
-    def generatePropertyNodes(self, prop_infos):
-        """ Pseudo API.
-        """
-        lines = self._p_nodes(properties=prop_infos).splitlines()
-        return '\n'.join(lines)
-
     security.declareProtected(ManagePortal, 'initObject')
     def initObject(self, parent, o_info):
 
@@ -329,6 +302,47 @@
 
         obj._updateProperty(prop_id, prop_value)
 
+InitializeClass(ImportConfiguratorBase)
+
+
+class ExportConfiguratorBase(Implicit):
+    """ Synthesize XML description.
+    """
+    security = ClassSecurityInfo()
+    security.setDefaultAccess('allow')
+
+    def __init__(self, site, encoding=None):
+
+        self._site = site
+        self._encoding = encoding
+        self._template = self._getExportTemplate()
+
+    security.declareProtected(ManagePortal, 'generateXML')
+    def generateXML(self, **kw):
+        """ Pseudo API.
+        """
+        return self._template(**kw)
+
+    #
+    #   generic object and property support
+    #
+    _o_nodes = PageTemplateFile('object_nodes.xml', _xmldir)
+    _p_nodes = PageTemplateFile('property_nodes.xml', _xmldir)
+
+    security.declareProtected(ManagePortal, 'generateObjectNodes')
+    def generateObjectNodes(self, obj_infos):
+        """ Pseudo API.
+        """
+        lines = self._o_nodes(objects=obj_infos).splitlines()
+        return '\n'.join(lines)
+
+    security.declareProtected(ManagePortal, 'generatePropertyNodes')
+    def generatePropertyNodes(self, prop_infos):
+        """ Pseudo API.
+        """
+        lines = self._p_nodes(properties=prop_infos).splitlines()
+        return '\n'.join(lines)
+
     def _extractObject(self, obj):
 
         properties = []
@@ -371,6 +385,20 @@
                  'elements': prop_elements,
                  'type': type,
                  'select_variable': select_variable }
+
+InitializeClass(ExportConfiguratorBase)
+
+
+# BBB: old class mixing the two, will be removed in CMF 1.7
+class ConfiguratorBase(ImportConfiguratorBase, ExportConfiguratorBase):
+    """ Synthesize XML description.
+    """
+    security = ClassSecurityInfo()
+    security.setDefaultAccess('allow')
+
+    def __init__(self, site, encoding=None):
+        ImportConfiguratorBase.__init__(self, site, encoding)
+        ExportConfiguratorBase.__init__(self, site, encoding)
 
 InitializeClass(ConfiguratorBase)
 



More information about the CMF-checkins mailing list