[CMF-checkins] CVS: CMF/CMFSetup - factory.py:1.1 __init__.py:1.5 actions.py:1.9 context.py:1.9 interfaces.py:1.12 registry.py:1.16 typeinfo.py:1.8 workflow.py:1.22

Tres Seaver tseaver at zope.com
Thu Jul 1 19:14:53 EDT 2004


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

Modified Files:
	__init__.py actions.py context.py interfaces.py registry.py 
	typeinfo.py workflow.py 
Added Files:
	factory.py 
Log Message:


  - __init__.py:

    o Complete setup of "configured CMF Site" factory.

    o Register our default profile, so that we can use it.

  - actions.py:

    o Ensure we pass a proper ActionInformation object to 'listActions'.

    o Ensure we *don't* call 'listActions' on an old-style provider.

  - context.py:

    o Suppress Unicode IDs in ZODB.

  - interfaces.py:

    o Note that 'product' is an optional attribute of a profile.

  - registry.py:

    o Capture 'product' when registering profiles.

  - typeinfo.py:

    o Fix buglet in writing typeinfo XML files in subdir.

  - worfklow.py:

    o Fix buglet in writing definition XML files in subdir.

    o Fix buglets when workflow tool does not yet have overrides.


=== Added File CMF/CMFSetup/factory.py ===
""" Configured site factory implementation.

$Id: factory.py,v 1.1 2004/07/01 23:14:23 tseaver Exp $
"""

from Products.PageTemplates.PageTemplateFile import PageTemplateFile

from Products.CMFCore.utils import getToolByName
from Products.CMFDefault.Portal import CMFSite

from registry import _profile_registry as profile_registry
from tool import SetupTool
from utils import _wwwdir

def addConfiguredSiteForm( dispatcher ):

    """ Wrap the PTF in 'dispatcher', including 'profile_registry' in options.
    """
    wrapped = PageTemplateFile( 'siteAddForm', _wwwdir ).__of__( dispatcher )

    return wrapped( profiles=profile_registry.listProfileInfo() )

def addConfiguredSite( dispatcher, site_id, profile_id, RESPONSE=None ):

    """ Add a CMFSite to 'dispatcher', configured according to 'profile_id'.
    """
    site = CMFSite( site_id )
    dispatcher._setObject( site_id, site )
    site = dispatcher._getOb( site_id )

    setup_tool = SetupTool()
    site._setObject( 'portal_setup', setup_tool )
    setup_tool = getToolByName( site, 'portal_setup' )

    profile_info = profile_registry.getProfileInfo( profile_id )
    setup_tool.setProfileDirectory( profile_info[ 'path' ]
                                  , profile_info.get( 'product' )
                                  )

    setup_tool.runAllImportSteps()
    setup_tool.createSnapshot( 'initial_configuration' )

    if RESPONSE is not None:
        RESPONSE.redirect( '%s/manage_main?update_menu=1'
                         % dispatcher.absolute_url() )


=== CMF/CMFSetup/__init__.py 1.4 => 1.5 ===
--- CMF/CMFSetup/__init__.py:1.4	Thu Jul  1 14:41:53 2004
+++ CMF/CMFSetup/__init__.py	Thu Jul  1 19:14:23 2004
@@ -10,45 +10,43 @@
 security = ModuleSecurityInfo( 'Products.CMFSetup' )
 security.declareProtected( ManagePortal, 'profile_registry' )
 
-def initialize(context):
+def initialize( context ):
 
     from Products.CMFCore.utils import ToolInit, registerIcon
     from tool import SetupTool
 
-    TOOLS_AND_ICONS = ( ( SetupTool, 'www/tool.png' ),)
 
     ToolInit( 'CMFSetup Tools'
-            , tools=[ x[ 0 ] for x in TOOLS_AND_ICONS ]
+            , tools=[ SetupTool ]
             , product_name='Setup'
             , icon=None
             ).initialize( context )
 
-    for tool, icon in TOOLS_AND_ICONS:
-        registerIcon( tool, icon, globals() )
+    registerIcon(  SetupTool, 'www/tool.png', globals() )
 
-    return # XXX comment out the rest
+    from factory import addConfiguredSiteForm
+    from factory import addConfiguredSite
 
-    from SiteConfiguration import addConfiguredSiteForm
-    from SiteConfiguration import addConfiguredSite
-    from SiteConfiguration import listPaths
-
-    # Add SiteConfiguration constructor.
-    # We specify meta_type and interfaces because we don't actually register a
-    # class here, only a constructor.
-    #
-    # Note that the 'listPaths' bit is a hack to get that
-    # object added to the factory dispatcher, so that it will be available
-    # within the 'addConfiguredSiteForm' template.
-    #
+    # Add factory for a site which follows a profile.  We specify
+    # meta_type and interfaces because we don't actually register a
+    # class here, only a factory.
     context.registerClass( meta_type='Configured CMF Site'
-                         , permission='Create Configured CMF Site'
                          , constructors=( addConfiguredSiteForm
                                         , addConfiguredSite
-                                        , listPaths #  WTF?
                                         )
+                         , permissions=( 'Add CMF Sites', )
                          , interfaces=None
                          )
 
+
+    profile_registry.registerProfile( 'default'
+                                    , 'CMFSetup Default'
+                                    , 'Default profile (for testing)'
+                                    , 'profiles/default'
+                                    , 'CMFSetup'
+                                    )
+
+    return # XXX comment out the rest
 
     # XXX:  This is *all* policy, and belongs in an XML file!
 


=== CMF/CMFSetup/actions.py 1.8 => 1.9 ===
--- CMF/CMFSetup/actions.py:1.8	Fri Jun 25 16:21:56 2004
+++ CMF/CMFSetup/actions.py	Thu Jul  1 19:14:23 2004
@@ -9,6 +9,9 @@
 from Globals import InitializeClass
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 
+from Products.CMFCore.ActionProviderBase import IActionProvider
+from Products.CMFCore.ActionProviderBase import IOldstyleActionProvider
+from Products.CMFCore.ActionInformation import getOAI
 from Products.CMFCore.utils import getToolByName
 
 from permissions import ManagePortal
@@ -145,6 +148,7 @@
         """
         actions_tool = getToolByName( self._site, 'portal_actions' )
         faux = _FauxContent( content=None, isAnonymous=1 )
+        info = getOAI( self._site, faux )
         result = []
 
         for provider_id in actions_tool.listActionProviders():
@@ -155,7 +159,13 @@
 
             provider = getToolByName( self._site, provider_id )
 
-            actions = provider.listActions( info=faux ) or []
+            if not IActionProvider.isImplementedBy( provider ):
+                continue
+
+            if IOldstyleActionProvider.isImplementedBy( provider ):
+                continue
+
+            actions = provider.listActions( info=info ) or []
             
             for action in actions:
 
@@ -220,6 +230,9 @@
 
     def __init__( self, **kw ):
         self.__dict__.update( kw )
+
+    def absolute_url( self ):
+        return 'http://localhost/faux_content'
 
 class _ActionProviderParser( HandlerBase ):
 


=== CMF/CMFSetup/context.py 1.8 => 1.9 ===
--- CMF/CMFSetup/context.py:1.8	Sun May 30 16:29:50 2004
+++ CMF/CMFSetup/context.py	Thu Jul  1 19:14:23 2004
@@ -250,7 +250,7 @@
 
         # TODO: switch on content_type
         ob = self._createObjectByType( filename, text, content_type )
-        folder._setObject( filename, ob )
+        folder._setObject( str( filename ), ob ) # No Unicode IDs!
 
     security.declareProtected( ManagePortal, 'getSnapshotURL' )
     def getSnapshotURL( self ):
@@ -311,7 +311,8 @@
         for element in path:
 
             if element not in current.objectIds():
-                current._setObject( element, Folder( element ) )
+                # No Unicode IDs!
+                current._setObject( str( element ), Folder( element ) )
 
             current = current._getOb( element )
 


=== CMF/CMFSetup/interfaces.py 1.11 => 1.12 ===
--- CMF/CMFSetup/interfaces.py:1.11	Thu Jul  1 14:41:53 2004
+++ CMF/CMFSetup/interfaces.py	Thu Jul  1 19:14:23 2004
@@ -327,6 +327,9 @@
           'description' -- a textual description of the profile
 
           'path' -- a path to the profile on the filesystem.
+
+          'product' -- the name of the product to which 'path' is
+             relative (None for absolute paths).
         """
 
     def listProfiles():
@@ -345,11 +348,15 @@
                        , title
                        , description
                        , path
+                       , product=None
                        ):
         """ Add a new profile to tne registry.
 
         o If an existing profile is already registered for 'profile_id',
           raise KeyError.
+
+        o If 'product' is passed, then 'path' should be interpreted as
+          relative to the corresponding product directory.
         """
 
 class ISetupTool( Interface ):


=== CMF/CMFSetup/registry.py 1.15 => 1.16 ===
--- CMF/CMFSetup/registry.py:1.15	Thu Jul  1 14:41:53 2004
+++ CMF/CMFSetup/registry.py	Thu Jul  1 19:14:23 2004
@@ -533,20 +533,7 @@
     security.declareProtected( ManagePortal, '' )
     def getProfileInfo( self, profile_id ):
 
-        """ Return a mapping describing a registered profile.
-
-        o Keys include:
-
-          'id' -- the ID of the profile
-
-          'title' -- its title
-
-          'description' -- a textual description of the profile
-
-          'type' -- 'FILESYSTEM' or 'SNAPSHOT'
-
-          'path' -- a path to the profile (either within the ZODB, for
-                    snapshots, or on the filesystem).
+        """ See IProfileRegistry.
         """
         result = self._profile_info[ profile_id ]
         return result.copy()
@@ -554,16 +541,14 @@
     security.declareProtected( ManagePortal, 'listProfiles' )
     def listProfiles( self ):
 
-        """ Return a list of IDs for registered profiles.
+        """ See IProfileRegistry.
         """
         return tuple( self._profile_ids )
 
     security.declareProtected( ManagePortal, 'listProfileInfo' )
     def listProfileInfo( self ):
 
-        """ Return a list of mappings describing registered profiles.
-
-        o See 'getProfileInfo' for a description of the mappings' keys.
+        """ See IProfileRegistry.
         """
         return [ self.getProfileInfo( id ) for id in self.listProfiles() ]
 
@@ -573,11 +558,9 @@
                        , title
                        , description
                        , path
+                       , product=None
                        ):
-        """ Add a new profile to tne registry.
-
-        o If an existing profile is already registered for 'profile_id',
-          raise KeyError.
+        """ See IProfileRegistry.
         """
         if self._profile_info.get( profile_id ) is not None:
             raise KeyError, 'Duplicate profile ID: %s' % profile_id
@@ -588,6 +571,7 @@
                , 'title' : title
                , 'description' : description
                , 'path' : path
+               , 'product' : product
                }
 
         self._profile_info[ profile_id ] = info


=== CMF/CMFSetup/typeinfo.py 1.7 => 1.8 ===
--- CMF/CMFSetup/typeinfo.py:1.7	Tue Jun  8 15:00:28 2004
+++ CMF/CMFSetup/typeinfo.py	Thu Jul  1 19:14:23 2004
@@ -76,9 +76,13 @@
 
     for type_id in types_tool.listContentTypes():
 
-        type_filename = _getTypeFilename( type_id )
+        type_filename = '%s.xml' % type_id.replace( ' ', '_' )
         type_xml = configurator.generateTypeXML( type_id )
-        context.writeDataFile( type_filename, type_xml, 'text/xml' )
+        context.writeDataFile( type_filename
+                             , type_xml
+                             , 'text/xml'
+                             , 'types'
+                             )
 
     # XXX: YAGNI?
     # exportScriptsFromContainer(types_tool, ('typestool_scripts',))


=== CMF/CMFSetup/workflow.py 1.21 => 1.22 ===
--- CMF/CMFSetup/workflow.py:1.21	Thu Jun 24 16:18:07 2004
+++ CMF/CMFSetup/workflow.py	Thu Jul  1 19:14:23 2004
@@ -63,7 +63,8 @@
     if context.shouldPurge():
 
         tool.setDefaultChain( '' )
-        tool._chains_by_type.clear()
+        if tool._chains_by_type is not None:
+            tool._chains_by_type.clear()
 
         for workflow_id in tool.getWorkflowIds():
             tool._delObject( workflow_id )
@@ -160,11 +161,15 @@
 
     for wf_id in wf_tool.getWorkflowIds():
 
-        wf_filename = _getWorkflowFilename( wf_id )
+        wf_dirname = wf_id.replace( ' ', '_' )
         wf_xml = configurator.generateWorkflowXML( wf_id )
 
         if wf_xml is not None:
-            context.writeDataFile( wf_filename, wf_xml, 'text/xml' )
+            context.writeDataFile( 'definition.xml'
+                                 , wf_xml
+                                 , 'text/xml'
+                                 , 'workflows/%s' % wf_dirname
+                                 )
 
     return 'Workflows exported.'
 
@@ -241,8 +246,11 @@
         workflow_tool = getToolByName( self._site, 'portal_workflow' )
 
         result = [ ( None, workflow_tool._default_chain ) ]
-        overrides = workflow_tool._chains_by_type.items()
-        overrides.sort()
+        if workflow_tool._chains_by_type is None:
+            overrides = []
+        else:
+            overrides = workflow_tool._chains_by_type.items()
+            overrides.sort()
 
         result.extend( overrides )
 
@@ -1282,7 +1290,9 @@
                        , props = props
                        )
 
-        w.var_matches = PersistentMapping( w_info[ 'match' ].items() )
+        w.var_matches = PersistentMapping()
+        for k, v in w_info[ 'match' ].items():
+            w.var_matches[ str( k ) ] = tuple( [ str(x) for x in v ] )
 
 def _initDCWorkflowScripts( workflow, scripts, context ):
 



More information about the CMF-checkins mailing list