[CMF-checkins] CVS: CMF/CMFSetup - __init__.py:1.10 factory.py:1.6 interfaces.py:1.19 registry.py:1.19 tool.py:1.22

Yvo Schubbe y.2005- at wcm-solutions.de
Wed Mar 16 03:23:05 EST 2005


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

Modified Files:
	__init__.py factory.py interfaces.py registry.py tool.py 
Log Message:
Added support for extension profiles:
- added optional 'profile_type' argument to registerProfile()
- runImportStep() and runAllImportSteps() have now None as default for purge_old: None doesn't override the default purge behavior of the profile type
- by default the profile type controls the purge mode: removed checkbox for setting it manually on the 'Import' tab
- replaced _clear() by clear(): registry entries are now accumulated and only cleared by an explicit method call
- the factory and the siteAddForm now allow to specify extension profiles that are imported after the base profile
- duplicate settings no longer raise errors, the last setting always wins


=== CMF/CMFSetup/__init__.py 1.9 => 1.10 ===
--- CMF/CMFSetup/__init__.py:1.9	Thu Nov 18 13:18:53 2004
+++ CMF/CMFSetup/__init__.py	Wed Mar 16 03:22:34 2005
@@ -17,6 +17,7 @@
 
 from AccessControl import ModuleSecurityInfo
 
+from interfaces import BASE, EXTENSION
 from permissions import ManagePortal
 from registry import _profile_registry as profile_registry
 


=== CMF/CMFSetup/factory.py 1.5 => 1.6 ===
--- CMF/CMFSetup/factory.py:1.5	Mon Feb 28 16:23:56 2005
+++ CMF/CMFSetup/factory.py	Wed Mar 16 03:22:34 2005
@@ -20,6 +20,7 @@
 from Products.CMFCore.utils import getToolByName
 from Products.CMFDefault.Portal import CMFSite
 
+from interfaces import EXTENSION
 from registry import _profile_registry as profile_registry
 from tool import SetupTool
 from utils import _wwwdir
@@ -30,13 +31,24 @@
     """
     wrapped = PageTemplateFile( 'siteAddForm', _wwwdir ).__of__( dispatcher )
 
-    return wrapped( profiles=profile_registry.listProfileInfo() )
+    base_profiles = []
+    extension_profiles = []
+
+    for info in profile_registry.listProfileInfo():
+        if info.get('type') == EXTENSION:
+            extension_profiles.append(info)
+        else:
+            base_profiles.append(info)
+
+    return wrapped( base_profiles=tuple(base_profiles),
+                    extension_profiles =tuple(extension_profiles) )
 
 def addConfiguredSite( dispatcher
                      , site_id
                      , profile_id
                      , snapshot=True
                      , RESPONSE=None 
+                     , extension_ids=()
                      ):
 
     """ Add a CMFSite to 'dispatcher', configured according to 'profile_id'.
@@ -51,6 +63,10 @@
 
     setup_tool.setImportContext( 'profile-%s' % profile_id )
     setup_tool.runAllImportSteps()
+    for extension_id in extension_ids:
+        setup_tool.setImportContext( 'profile-%s' % extension_id )
+        setup_tool.runAllImportSteps()
+    setup_tool.setImportContext( 'profile-%s' % profile_id )
 
     if snapshot is True:
         setup_tool.createSnapshot( 'initial_configuration' )


=== CMF/CMFSetup/interfaces.py 1.18 => 1.19 ===
--- CMF/CMFSetup/interfaces.py:1.18	Thu Jan 20 14:00:19 2005
+++ CMF/CMFSetup/interfaces.py	Wed Mar 16 03:22:34 2005
@@ -17,6 +17,10 @@
 
 from Interface import Interface
 
+
+BASE, EXTENSION = range(2)
+
+
 class IPseudoInterface( Interface ):
 
     """ API documentation;  not testable / enforceable.
@@ -178,7 +182,7 @@
 
     def parseXML( text ):
 
-        """ Parse 'text' into a clean registry.
+        """ Parse 'text'.
         """
 
 class IImportStepRegistry( IStepRegistry ):
@@ -344,6 +348,8 @@
 
           'product' -- the name of the product to which 'path' is
              relative (None for absolute paths).
+
+          'type' -- either BASE or EXTENSION
         """
 
     def listProfiles():
@@ -363,6 +369,7 @@
                        , description
                        , path
                        , product=None
+                       , profile_type=BASE
                        ):
         """ Add a new profile to tne registry.
 
@@ -410,7 +417,7 @@
         """ Return the IToolsetRegistry for the tool.
         """
 
-    def runImportStep( step_id, purge_old=True, run_dependencies=True ):
+    def runImportStep( step_id, run_dependencies=True, purge_old=None ):
 
         """ Execute a given setup step
 
@@ -431,7 +438,7 @@
             step
         """
 
-    def runAllImportSteps( purge_old=True ):
+    def runAllImportSteps( purge_old=None ):
 
         """ Run all setup steps in dependency order.
 


=== CMF/CMFSetup/registry.py 1.18 => 1.19 ===
--- CMF/CMFSetup/registry.py:1.18	Thu Aug 12 11:07:41 2004
+++ CMF/CMFSetup/registry.py	Wed Mar 16 03:22:34 2005
@@ -22,6 +22,7 @@
 from Globals import InitializeClass
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 
+from interfaces import BASE
 from interfaces import IImportStepRegistry
 from interfaces import IExportStepRegistry
 from interfaces import IToolsetRegistry
@@ -33,6 +34,7 @@
 from utils import _resolveDottedName
 from utils import _extractDocstring
 
+
 class ImportStepRegistry( Implicit ):
 
     """ Manage knowledge about steps to create / configure site.
@@ -45,7 +47,7 @@
 
     def __init__( self ):
 
-        self._clear()
+        self.clear()
 
     security.declareProtected( ManagePortal, 'listSteps' )
     def listSteps( self ):
@@ -182,7 +184,7 @@
         """
         already = self.getStepMetadata( id )
 
-        if already and already[ 'version' ] >= version:
+        if already and already[ 'version' ] > version:
             raise KeyError( 'Existing registration for step %s, version %s'
                           % ( id, already[ 'version' ] ) )
 
@@ -206,10 +208,8 @@
     security.declarePrivate( 'parseXML' )
     def parseXML( self, text, encoding=None ):
 
-        """ Parse 'text' into a clean registry.
+        """ Parse 'text'.
         """
-        self._clear()
-
         reader = getattr( text, 'read', None )
 
         if reader is not None:
@@ -220,14 +220,14 @@
 
         return parser._parsed
 
-    #
-    #   Helper methods
-    #
-    security.declarePrivate( '_clear' )
-    def _clear( self ):
+    security.declarePrivate( 'clear' )
+    def clear( self ):
 
         self._registered = {}
 
+    #
+    #   Helper methods
+    #
     security.declarePrivate( '_computeTopologicalSort' )
     def _computeTopologicalSort( self ):
 
@@ -279,7 +279,7 @@
 
     def __init__( self ):
 
-        self._registered = {}
+        self.clear()
 
     security.declareProtected( ManagePortal, 'listSteps' )
     def listSteps( self ):
@@ -356,11 +356,6 @@
           If None, the remaining line of the documentation string of
           the step is used, or default to ''.
         """
-        already = self.getStep( id )
-
-        if already:
-            raise KeyError( 'Existing registration for step %s' % id )
-
         if title is None or description is None:
 
             t, d = _extractDocstring( handler, id, '' )
@@ -379,10 +374,8 @@
     security.declarePrivate( 'parseXML' )
     def parseXML( self, text, encoding=None ):
 
-        """ Parse 'text' into a clean registry.
+        """ Parse 'text'.
         """
-        self._clear()
-
         reader = getattr( text, 'read', None )
 
         if reader is not None:
@@ -393,14 +386,14 @@
 
         return parser._parsed
 
-    #
-    #   Helper methods
-    #
-    security.declarePrivate( '_clear' )
-    def _clear( self ):
+    security.declarePrivate( 'clear' )
+    def clear( self ):
 
         self._registered = {}
 
+    #
+    #   Helper methods
+    #
     security.declarePrivate( '_exportTemplate' )
     _exportTemplate = PageTemplateFile( 'esrExport.xml', _xmldir )
 
@@ -417,7 +410,7 @@
 
     def __init__( self ):
 
-        self._clear()
+        self.clear()
 
     #
     #   Toolset API
@@ -437,7 +430,7 @@
         """ See IToolsetRegistry.
         """
         if tool_id in self._forbidden:
-            raise KeyError, 'Duplicate forbidden tool: %s' % tool_id
+            return
 
         if self._required.get( tool_id ) is not None:
             raise ValueError, 'Tool %s is required!' % tool_id
@@ -473,9 +466,6 @@
 
         """ See IToolsetRegistry.
         """
-        if self._required.get( tool_id ) is not None:
-            raise KeyError, "Duplicate required tool: %s" % tool_id
-
         if tool_id in self._forbidden:
             raise ValueError, "Forbidden tool ID: %s" % tool_id
 
@@ -503,23 +493,21 @@
         parser = _ToolsetParser( encoding )
         parseString( text, parser )
 
-        self._clear()
-
         for tool_id in parser._forbidden:
             self.addForbiddenTool( tool_id )
 
         for tool_id, dotted_name in parser._required.items():
             self.addRequiredTool( tool_id, dotted_name )
 
-    #
-    #   Helper methods.
-    #
-    security.declarePrivate( '_clear' )
-    def _clear( self ):
+    security.declarePrivate( 'clear' )
+    def clear( self ):
 
         self._forbidden = []
         self._required = {}
 
+    #
+    #   Helper methods.
+    #
     security.declarePrivate( '_toolsetConfig' )
     _toolsetConfig = PageTemplateFile( 'tscExport.xml'
                                      , _xmldir
@@ -539,7 +527,7 @@
 
     def __init__( self ):
 
-        self._clear()
+        self.clear()
 
     security.declareProtected( ManagePortal, '' )
     def getProfileInfo( self, profile_id ):
@@ -570,6 +558,7 @@
                        , description
                        , path
                        , product=None
+                       , profile_type=BASE
                        ):
         """ See IProfileRegistry.
         """
@@ -583,13 +572,13 @@
                , 'description' : description
                , 'path' : path
                , 'product' : product
+               , 'type': profile_type
                }
 
         self._profile_info[ profile_id ] = info
 
-    #   Helper methods
-    security.declarePrivate( '_clear' )
-    def _clear( self ):
+    security.declarePrivate( 'clear' )
+    def clear( self ):
 
         self._profile_info = {}
         self._profile_ids = []


=== CMF/CMFSetup/tool.py 1.21 => 1.22 ===
--- CMF/CMFSetup/tool.py:1.21	Thu Jan 20 14:00:19 2005
+++ CMF/CMFSetup/tool.py	Wed Mar 16 03:22:34 2005
@@ -28,6 +28,7 @@
 from Products.CMFCore.utils import UniqueObject
 from Products.CMFCore.utils import getToolByName
 
+from interfaces import EXTENSION
 from interfaces import ISetupTool
 from permissions import ManagePortal
 from context import DirectoryImportContext
@@ -188,7 +189,7 @@
         return self._toolset_registry
 
     security.declareProtected( ManagePortal, 'executeStep' )
-    def runImportStep( self, step_id, run_dependencies=True, purge_old=True ):
+    def runImportStep( self, step_id, run_dependencies=True, purge_old=None ):
 
         """ See ISetupTool.
         """
@@ -218,7 +219,7 @@
         return { 'steps' : steps, 'messages' : messages }
 
     security.declareProtected( ManagePortal, 'runAllSetupSteps')
-    def runAllImportSteps( self, purge_old=True ):
+    def runAllImportSteps( self, purge_old=None ):
 
         """ See ISetupTool.
         """
@@ -382,7 +383,6 @@
     def manage_importSelectedSteps( self
                                   , ids
                                   , run_dependencies
-                                  , purge_old
                                   , RESPONSE
                                   ):
         """ Import the steps selected by the user.
@@ -393,10 +393,7 @@
         else:
             steps_run = []
             for step_id in ids:
-                result = self.runImportStep( step_id
-                                           , run_dependencies
-                                           , purge_old
-                                           )
+                result = self.runImportStep( step_id, run_dependencies )
                 steps_run.extend( result[ 'steps' ] )
 
             message = 'Steps+run:%s' % '+,'.join( steps_run )
@@ -406,11 +403,11 @@
                          )
 
     security.declareProtected( ManagePortal, 'manage_importSelectedSteps' )
-    def manage_importAllSteps( self, purge_old, RESPONSE ):
+    def manage_importAllSteps( self, RESPONSE ):
 
         """ Import all steps.
         """
-        result = self.runAllImportSteps( purge_old )
+        result = self.runAllImportSteps()
         message = 'Steps+run:%s' % '+,'.join( result[ 'steps' ] )
 
         RESPONSE.redirect( '%s/manage_importSteps?manage_tabs_message=%s'
@@ -586,7 +583,7 @@
         return product.__path__[0]
 
     security.declarePrivate( '_getImportContext' )
-    def _getImportContext( self, context_id, should_purge=False ):
+    def _getImportContext( self, context_id, should_purge=None ):
 
         """ Crack ID and generate appropriate import context.
         """
@@ -602,11 +599,14 @@
                                    , info[ 'path' ] )
             else:
                 path = info[ 'path' ]
-
+            if should_purge is None:
+                should_purge = (info.get('type') != EXTENSION)
             return DirectoryImportContext(self, path, should_purge, encoding)
 
         # else snapshot
         context_id = context_id[ len( 'snapshot-' ): ]
+        if should_purge is None:
+            should_purge = True
         return SnapshotImportContext(self, context_id, should_purge, encoding)
 
     security.declarePrivate( '_updateImportStepsRegistry' )
@@ -616,6 +616,8 @@
         """
         context = self._getImportContext(self._import_context_id)
         xml = context.readDataFile(IMPORT_STEPS_XML)
+        if xml is None:
+            return
 
         info_list = self._import_registry.parseXML( xml, encoding )
 
@@ -644,6 +646,8 @@
         """
         context = self._getImportContext(self._import_context_id)
         xml = context.readDataFile(EXPORT_STEPS_XML)
+        if xml is None:
+            return
 
         info_list = self._export_registry.parseXML( xml, encoding )
 
@@ -668,6 +672,8 @@
         """
         context = self._getImportContext(self._import_context_id)
         xml = context.readDataFile(TOOLSET_XML)
+        if xml is None:
+            return
 
         self._toolset_registry.parseXML( xml, encoding )
 



More information about the CMF-checkins mailing list