>     I am experimenting with that right now, but my z3/Five-Fu ran low  
>     again ;)  My problem: calls to zope.component.getUtility
>     (interface_class) never return anything. Here's the top part (the  
>     bottom is just the old way) of my CMFCore.utils.getToolByName:


>     def getToolByName(obj, name, default=_marker):
>          """ Get the tool, 'toolname', by acquiring it.
>          """
>          tool_iface = _tool_iface_registry.get(name)
>          if tool_iface is not None:
>              warn('getToolByName is deprecated, please use "getUtility(%
>     s)"' % (
>                     tool_iface.__name__), DeprecationWarning,
> stacklevel=2)
>              try:
>                  tool = getUtility(tool_iface, context=obj)
>                  return tool
>              except ComponentLookupError:
>                  # behave in backwards-compatible way
>                  if default is _marker:
>                      raise AttributeError, name

The 'context' argument *should* be superfluous, because Zope's thread-local
should know what the local site is, and a utility is registered with exactly
one local site.

>     I have a simple registration going and have one ID -> interface  
>     registered (in "_tool_iface_registry"), 'portal_actions' is mapped to  
>     interface class CMFCore.interfaces._tools.IActionsTool. No matter how  
>     I try to call getUtility, I always get a ComponentLookupError.
>     I am probably missing some kind of component registration - I have  
>     not made any ZCML changes or changes to the code in  
>     CMFCore.ActionsTool, except for one line that causes the tool to be  
>     registered in the internal "_tool_iface_registry".

You'll need to actually register the utility with the local component
registry. I assume we're on Zope 2.10 here? This needs to happen wehn the
CMF site is set up.

Take a look at

In particular:

    def enableSite(self, portal):
        Make the portal a Zope3 site and create a site manager.
        enableSite(portal, iface=IObjectManagerSite)

        components = PersistentComponents()
        components.__bases__ = (base,)

After this is done, you can do:

from zope.component import getSiteManager

site = <CMF site>
actionsTool = site.portal_actions # get the actual object from the ZODB

sm = getSiteManager(site)
sm.registerUtility(provides=IActionTool, component=actionsTool)

Now, you can do this with GenericSetup as well, thanks to Hanno.  See

The test is informative:

Hanno said he was interested in factoring GSLocalAddOns into CMF itself, so
maybe now's a good time to do so.


View this message in context: 
Sent from the Zope - CMF list2 mailing list archive at Nabble.com.

Zope-CMF maillist  -  Zope-CMF@lists.zope.org

See http://collector.zope.org/CMF for bug reports and feature requests

Reply via email to