[Zope-CMF] GenericSetup and PluggableAuthService

Hanno Schlichting hanno at hannosch.eu
Wed Dec 30 10:39:42 EST 2009


On Wed, Dec 30, 2009 at 4:19 PM, Jens Vagelpohl <jens at dataflake.org> wrote:
> In the debugger I see that the object in question is a absolute_url
> adapter residing in the base component registry in the site root. IMHO
> the components exporter should not look at the base registry at all,
> only a local registry if one exists in the folder the tool sits in. Correct?

Right. As you noticed nobody ever tried to use GS outside a CMF/Plone context :)

The code in question does a:

sm = getSiteManager(context.getSite())

That will get the nearest site manager, which in case of CMF will
always be the one in the CMF site root.

What you want is probably something like this:

from zope.component.interfaces import ComponentLookupError
from zope.component.interfaces import IComponentRegistry
from zope.location.interfaces import IPossibleSite

def importComponentRegistry(context):
    """Import local components.
    """
    # context is the portal_setup tool
    # getSite is GS API to get the parent
    site = context.getSite()
    sm = None
    if IPossibleSite.providedBy(site):
        # All object managers are an IPossibleSite, but this
        # defines the getSiteManager method to be available
        try:
            sm = site.getSiteManager()
        except ComponentLookupError:
            sm = None

    if sm is None or not IComponentRegistry.providedBy(sm):
        logger = context.getLogger('componentregistry')
        logger.info("Can not register components, as no registry was found.")
        return

    importer = queryMultiAdapter((sm, context), IBody)
    if importer:
        body = context.readDataFile('componentregistry.xml')
        if body is not None:
            importer.body = body


And then adjust exportComponentRegistry in a similar way. This is
untested code :)

Hanno


More information about the Zope-CMF mailing list