On Wed, Dec 30, 2009 at 4:19 PM, Jens Vagelpohl <j...@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
            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.")

    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 :)

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

See https://bugs.launchpad.net/zope-cmf/ for bug reports and feature requests

Reply via email to