Exemple #1
0
def importComponentRegistry(context):
    """Import local components.
    """
    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
        else:
            logger = context.getLogger('componentregistry')
            logger.debug("Nothing to import")
Exemple #2
0
def importComponentRegistry(context):
    """Import local components.
    """
    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
        else:
            logger = context.getLogger('componentregistry')
            logger.debug("Nothing to import")
Exemple #3
0
def ensure_site(context):
    """Ensure the given context implements ISite.  The importance of
    this method is that it will ensure the given context is an ISite
    regardless of the Zope version (Zope 2.9 had a really hacked up
    SiteManager mechanism we have to account for).

      >>> from zope.location.interfaces import ISite, IPossibleSite
      >>> from OFS.Folder import Folder
      >>> if not IPossibleSite.implementedBy(Folder):
      ...    from zope import interface
      ...    from Products.Five.site.metaconfigure import (FiveSite,
      ...                                                  classSiteHook)
      ...    classSiteHook(Folder, FiveSite)
      ...    interface.classImplements(Folder, IPossibleSite)
      >>> om = Folder('foo')

      >>> ISite.providedBy(om)
      False

      >>> try:
      ...     ensure_site(om)
      ... except TypeError:
      ...     # not supposed to do anything unless enableLocalSiteHook was found
      ...     if enableLocalSiteHook is None:
      ...         True
      True
    """

    if not IPossibleSite.providedBy(context):
        if hasattr(context, 'getPhysicalPath'):
            p = '/'.join(context.getPhysicalPath())
        elif hasattr(context, 'getId'):
            p = context.getId()
        elif hasattr(context, 'id'):
            p = id
        else:
            p = str(context)

        raise TypeError('The object, "%s", is not an IPossibleSite' % p)

    if not ISite.providedBy(context):
        if enableLocalSiteHook is not None:
            enableLocalSiteHook(context)
            setSite(context)
        else:
            raise TypeError('"%s" is not configured as an ISite' %
                            '/'.join(context.getPhysicalPath()))

    if not ISite.providedBy(context):
        raise TypeError('Somehow trying to configure "%s" as an ISite '
                        'has failed' % '/'.join(context.getPhysicalPath()))
Exemple #4
0
def ensure_site(context):
    """Ensure the given context implements ISite.  The importance of
    this method is that it will ensure the given context is an ISite
    regardless of the Zope version (Zope 2.9 had a really hacked up
    SiteManager mechanism we have to account for).

      >>> from zope.location.interfaces import ISite, IPossibleSite
      >>> from OFS.Folder import Folder
      >>> if not IPossibleSite.implementedBy(Folder):
      ...    from zope import interface
      ...    from Products.Five.site.metaconfigure import (FiveSite,
      ...                                                  classSiteHook)
      ...    classSiteHook(Folder, FiveSite)
      ...    interface.classImplements(Folder, IPossibleSite)
      >>> om = Folder('foo')

      >>> ISite.providedBy(om)
      False

      >>> try:
      ...     ensure_site(om)
      ... except TypeError:
      ...     # not supposed to do anything unless enableLocalSiteHook was found
      ...     if enableLocalSiteHook is None:
      ...         True
      True
    """

    if not IPossibleSite.providedBy(context):
        if hasattr(context, 'getPhysicalPath'):
            p = '/'.join(context.getPhysicalPath())
        elif hasattr(context, 'getId'):
            p = context.getId()
        elif hasattr(context, 'id'):
            p = id
        else:
            p = str(context)

        raise TypeError('The object, "%s", is not an IPossibleSite' % p)

    if not ISite.providedBy(context):
        if enableLocalSiteHook is not None:
            enableLocalSiteHook(context)
            setSite(context)
        else:
            raise TypeError('"%s" is not configured as an ISite' %
                            '/'.join(context.getPhysicalPath()))

    if not ISite.providedBy(context):
        raise TypeError('Somehow trying to configure "%s" as an ISite '
                        'has failed' % '/'.join(context.getPhysicalPath()))
Exemple #5
0
def enableSite(obj, iface=ISite):
    """Install __before_traverse__ hook for Local Site
    """
    # We want the original object, not stuff in between, and no acquisition
    obj = aq_base(obj)
    if not IPossibleSite.providedBy(obj):
        raise TypeError, 'Must provide IPossibleSite'
    hook = AccessRule(HOOK_NAME)
    registerBeforeTraverse(obj, hook, HOOK_NAME, 1)

    if not hasattr(obj, HOOK_NAME):
        setattr(obj, HOOK_NAME, LocalSiteHook())

    zope.interface.alsoProvides(obj, iface)
Exemple #6
0
def enableSite(obj, iface=ISite):
    """Install __before_traverse__ hook for Local Site
    """
    # We want the original object, not stuff in between, and no acquisition
    obj = aq_base(obj)
    if not IPossibleSite.providedBy(obj):
        raise TypeError, 'Must provide IPossibleSite'
    hook = NameCaller(HOOK_NAME)
    registerBeforeTraverse(obj, hook, HOOK_NAME, 1)

    if not hasattr(obj, HOOK_NAME):
        setattr(obj, HOOK_NAME, LocalSiteHook())

    zope.interface.alsoProvides(obj, iface)
Exemple #7
0
def exportComponentRegistry(context):
    """Export local components.
    """
    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.debug("Nothing to export.")
        return

    exporter = queryMultiAdapter((sm, context), IBody)
    if exporter:
        body = exporter.body
        if body is not None:
            context.writeDataFile('componentregistry.xml', body,
                                  exporter.mime_type)
Exemple #8
0
def exportComponentRegistry(context):
    """Export local components.
    """
    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.debug("Nothing to export.")
        return

    exporter = queryMultiAdapter((sm, context), IBody)
    if exporter:
        body = exporter.body
        if body is not None:
            context.writeDataFile('componentregistry.xml', body,
                                  exporter.mime_type)