[CMF-checkins] SVN: CMF/branches/jens_tools_as_utilities/CMF - checkpoint checkin so other people can look at it

Jens Vagelpohl jens at dataflake.org
Tue Nov 21 12:47:14 EST 2006


Log message for revision 71245:
  - checkpoint checkin so other people can look at it
  - the ActionsTool is used as utility throughout, except for the
    places in untrusted code that use getToolByName - a clean
    solution is still in the works for that.
  

Changed:
  U   CMF/branches/jens_tools_as_utilities/CMFCore/ActionsTool.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/actions.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/tests/test_actions.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/tests/base/dummy.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/utils.py
  A   CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/componentregistry.xml
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/export_steps.xml
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/import_steps.xml
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/setuphandlers.py

-=-
Modified: CMF/branches/jens_tools_as_utilities/CMFCore/ActionsTool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/ActionsTool.py	2006-11-21 17:31:54 UTC (rev 71244)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/ActionsTool.py	2006-11-21 17:47:12 UTC (rev 71245)
@@ -30,6 +30,7 @@
 from interfaces.portal_actions import portal_actions as z2IActionsTool
 from permissions import ManagePortal
 from utils import _dtmldir
+from utils import registerToolInterface
 from utils import UniqueObject
 
 
@@ -183,3 +184,4 @@
         return filtered_actions
 
 InitializeClass(ActionsTool)
+registerToolInterface('portal_actions', IActionsTool)

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/actions.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/actions.py	2006-11-21 17:31:54 UTC (rev 71244)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/actions.py	2006-11-21 17:47:12 UTC (rev 71245)
@@ -15,8 +15,6 @@
 $Id$
 """
 
-from zope.component import adapts
-
 from Products.GenericSetup.interfaces import ISetupEnviron
 from Products.GenericSetup.utils import exportObjects
 from Products.GenericSetup.utils import I18NURI
@@ -34,6 +32,10 @@
         import ActionProvider as z2IActionProvider
 from Products.CMFCore.utils import getToolByName
 
+from zope.component import adapts
+from zope.component import getUtility
+from zope.component import getSiteManager
+
 _SPECIAL_PROVIDERS = ('portal_actions', 'portal_types', 'portal_workflow')
 
 
@@ -246,16 +248,16 @@
 def importActionProviders(context):
     """Import actions tool.
     """
-    site = context.getSite()
-    tool = getToolByName(site, 'portal_actions')
+    sm = getSiteManager(context.getSite())
+    tool = sm.getUtility(IActionsTool)
 
     importObjects(tool, '', context)
 
 def exportActionProviders(context):
     """Export actions tool.
     """
-    site = context.getSite()
-    tool = getToolByName(site, 'portal_actions', None)
+    sm = getSiteManager(context.getSite())
+    tool = sm.getUtility(IActionsTool)
     if tool is None:
         logger = context.getLogger('actions')
         logger.info('Nothing to export.')

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/tests/test_actions.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/tests/test_actions.py	2006-11-21 17:31:54 UTC (rev 71244)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/tests/test_actions.py	2006-11-21 17:47:12 UTC (rev 71245)
@@ -330,7 +330,9 @@
         self.assertEqual(obj.action_providers[0], 'portal_actions')
 
     def setUp(self):
+        from Products.CMFCore.interfaces._tools import IActionsTool
         from Products.CMFCore.ActionsTool import ActionsTool
+        from zope.component import getGlobalSiteManager
 
         BodyAdapterTestCase.setUp(self)
         site = DummySite('site')
@@ -338,17 +340,26 @@
         self._obj = site.portal_actions
         self._BODY = _ACTIONSTOOL_BODY
 
+        # utility registration
+        gsm = getGlobalSiteManager()
+        gsm.registerUtility(self._obj, IActionsTool)
 
+
 class _ActionSetup(BaseRegistryTests):
 
     def _initSite(self, foo=2, bar=2):
-        self.root.site = Folder(id='site')
+        from zope.component import getSiteManager
+
+        self.root.site = DummySite('site')
         site = self.root.site
         site.portal_membership = DummyMembershipTool()
 
         site.portal_actions = DummyActionsTool()
         site.portal_actions.addActionProvider('portal_actions')
 
+        sm = getSiteManager(site)
+        sm.registerUtility(site.portal_actions, IActionsTool)
+
         if foo > 0:
             site.portal_foo = DummyTool()
 

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/tests/base/dummy.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/tests/base/dummy.py	2006-11-21 17:31:54 UTC (rev 71244)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/tests/base/dummy.py	2006-11-21 17:47:12 UTC (rev 71245)
@@ -29,6 +29,7 @@
 from zope.interface import implements
 
 from Products.CMFCore.interfaces import IContentish
+from Products.CMFCore.interfaces import ISiteRoot
 from Products.CMFCore.ActionProviderBase import ActionProviderBase
 from Products.CMFCore.PortalContent import PortalContent
 
@@ -269,6 +270,7 @@
     _domain = 'http://www.foobar.com'
     _path = 'bar'
     _isPortalRoot = 1
+    implements(ISiteRoot)
 
     def absolute_url(self, relative=0):
         return '/'.join( (self._domain, self._path, self._id) )

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/utils.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/utils.py	2006-11-21 17:31:54 UTC (rev 71244)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/utils.py	2006-11-21 17:47:12 UTC (rev 71245)
@@ -46,6 +46,8 @@
 from OFS.SimpleItem import SimpleItem
 from thread import allocate_lock
 from webdav.common import rfc1123_date
+from zope.component import getUtility
+from zope.component.interfaces import ComponentLookupError
 from zope.i18nmessageid import MessageFactory
 
 from exceptions import AccessControl_Unauthorized
@@ -63,6 +65,17 @@
 #
 _marker = []  # Create a new marker object.
 
+_tool_interface_registry = {}
+
+security.declarePrivate('registerToolInterface')
+def registerToolInterface(tool_id, tool_interface):
+    """ Register a tool ID for an interface
+
+    This method can go away when getToolByName is going away (CMF 2.3).
+    """
+    global  _tool_interface_registry
+    _tool_interface_registry[tool_id] = tool_interface
+
 security.declarePublic('getToolByName')
 def getToolByName(obj, name, default=_marker):
 
@@ -72,6 +85,21 @@
       acquiring the tool by name, to ease forward migration (e.g.,
       to Zope3).
     """
+    tool_interface = _tool_interface_registry.get(name)
+
+    if tool_interface is not None:
+        warn('getToolByName is deprecated and will be removed in '
+             'CMF 2.3, please use "getUtility(%s)"' % (
+               tool_interface.__name__), DeprecationWarning, stacklevel=2) 
+
+        try:
+            tool = getUtility(tool_interface)
+            return tool.__of__(obj)
+        except ComponentLookupError:
+            # behave in backwards-compatible way
+            # fall through to old implementation
+            pass
+    
     try:
         tool = aq_get(obj, name, default, 1)
     except AttributeError:

Added: CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/componentregistry.xml
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/componentregistry.xml	2006-11-21 17:31:54 UTC (rev 71244)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/componentregistry.xml	2006-11-21 17:47:12 UTC (rev 71245)
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<componentregistry>
+ <adapters/>
+ <utilities>
+  <utility
+     interface="Products.CMFCore.interfaces._tools.IActionsTool"
+     object="/portal_actions"/>
+  <utility
+     interface="Products.CMFCore.interfaces._tools.ICachingPolicyManager"
+     object="/caching_policy_manager"/>
+ </utilities>
+</componentregistry>


Property changes on: CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/componentregistry.xml
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/export_steps.xml
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/export_steps.xml	2006-11-21 17:31:54 UTC (rev 71244)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/export_steps.xml	2006-11-21 17:47:12 UTC (rev 71245)
@@ -15,6 +15,11 @@
               title="Catalog Tool">
   Export catalog tool's sub-objects, indexes and columns.
  </export-step>
+ <export-step id="componentregistry"
+              handler="Products.GenericSetup.components.exportComponentRegistry"
+    title="Local Component Registry">
+    Export local component registry configuration.
+ </export-step>
  <export-step id="content_type_registry"
               handler="Products.CMFCore.exportimport.contenttyperegistry.exportContentTypeRegistry"
               title="Content Type Registry">

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/import_steps.xml
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/import_steps.xml	2006-11-21 17:31:54 UTC (rev 71244)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/import_steps.xml	2006-11-21 17:47:12 UTC (rev 71245)
@@ -3,7 +3,7 @@
  <import-step id="actions" version="20040630-01"
               handler="Products.CMFCore.exportimport.actions.importActionProviders"
               title="Action Providers">
-  <dependency step="toolset"/>
+  <dependency step="componentregistry"/>
   Import actions tool's action providers and their actions.
  </import-step>
  <import-step id="caching_policy_mgr" version="20051011-01"
@@ -18,6 +18,13 @@
   <dependency step="toolset"/>
   Import catalog tool's sub-objects, indexes and columns.
  </import-step>
+ <import-step id="componentregistry"
+    version="20061025-01"
+    handler="Products.GenericSetup.components.importComponentRegistry"
+    title="Local Component Registry">
+    <dependency step="various"/>
+    Import local component registry configuration.
+ </import-step>
  <import-step id="content_type_registry"
               version="20051013-01"
               handler="Products.CMFCore.exportimport.contenttyperegistry.importContentTypeRegistry"

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/setuphandlers.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/setuphandlers.py	2006-11-21 17:31:54 UTC (rev 71244)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/setuphandlers.py	2006-11-21 17:47:12 UTC (rev 71245)
@@ -16,8 +16,13 @@
 """
 
 from exceptions import BadRequest
+from Products.Five.component import enableSite
+from Products.Five.component import HOOK_NAME
+from Products.Five.component.interfaces import IObjectManagerSite
+from zope.app.component.hooks import setSite
+from zope.component.globalregistry import base
+from zope.component.persistentregistry import PersistentComponents
 
-
 def importVarious(context):
     """ Import various settings.
 
@@ -26,6 +31,15 @@
     """
     site = context.getSite()
 
+    # Make the portal a Zope3 site and create a site manager.
+    # Check to see that this is not run more than once, ever
+    if not getattr(site, HOOK_NAME, None):
+        enableSite(site, iface=IObjectManagerSite)
+        components = PersistentComponents()
+        components.__bases__ = (base,)
+        site.setSiteManager(components)
+        setSite(site)
+
     try:
         site.manage_addPortalFolder('Members')
     except BadRequest:



More information about the CMF-checkins mailing list