Ejemplo n.º 1
0
 def _exportNode(self):
     # hack around an issue where _getObjectNode expects to have the context
     # a meta_type and a getId method, which isn't the case for a component
     # registry
     if IComponentRegistry.providedBy(self.context):
         self.context.meta_type = 'ComponentRegistry'
         self.context.getId = dummyGetId
     node = self._getObjectNode('layers')
     if IComponentRegistry.providedBy(self.context):
         del(self.context.meta_type)
         del(self.context.getId)
     node.appendChild(self._extractLayers())
     self._logger.info('Browser layers exported')
     return node
Ejemplo n.º 2
0
 def _exportNode(self):
     # hack around an issue where _getObjectNode expects to have the context
     # a meta_type and a getId method, which isn't the case for a component
     # registry
     if IComponentRegistry.providedBy(self.context):
         self.context.meta_type = 'ComponentRegistry'
         self.context.getId = dummyGetId
     node = self._getObjectNode('layers')
     if IComponentRegistry.providedBy(self.context):
         del (self.context.meta_type)
         del (self.context.getId)
     node.appendChild(self._extractLayers())
     self._logger.info('Browser layers exported')
     return node
Ejemplo n.º 3
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")
Ejemplo n.º 4
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")
    def testSiteManagerSetup(self):
        clearSite()
        # The portal should be an ISite
        self.assertTrue(ISite.providedBy(self.portal))
        # There should be a IComponentRegistry
        comp = IComponentLookup(self.portal)
        IComponentRegistry.providedBy(comp)

        # Test if we get the right site managers
        gsm = getGlobalSiteManager()
        sm = getSiteManager()
        # Without setting the site we should get the global site manager
        self.assertTrue(sm is gsm)

        # Now we set the site, as it is done in url traversal normally
        setSite(self.portal)
        # And should get the local site manager
        sm = getSiteManager()
        self.assertTrue(aq_base(sm) is aq_base(comp))
Ejemplo n.º 6
0
def disableRedirectTracking(site):
    # Add additional setup code here
    from zope.component import getSiteManager
    from zope.component.interfaces import IComponentRegistry
    from plone.app.redirector.interfaces import IRedirectionStorage
    sm = getSiteManager(site)
    if sm is None or not IComponentRegistry.providedBy(sm):
        log.warn("Failed to find a site manager, can not remove "
                 "IRedirectionStorage utility")
        return

    sm.unregisterUtility(provided=IRedirectionStorage)
Ejemplo n.º 7
0
def disableRedirectTracking(site):
    # Add additional setup code here
    from zope.component import getSiteManager
    from zope.component.interfaces import IComponentRegistry
    from plone.app.redirector.interfaces import IRedirectionStorage
    sm = getSiteManager(site)
    if sm is None or not IComponentRegistry.providedBy(sm):
        log.warn("Failed to find a site manager, can not remove "
                 "IRedirectionStorage utility")
        return

    sm.unregisterUtility(provided=IRedirectionStorage)
Ejemplo n.º 8
0
def export_sharing(context):

    sm = getSiteManager(context.getSite())
    logger = context.getLogger('plone.app.workflow')

    if sm is None or not IComponentRegistry.providedBy(sm):
        logger.debug("Nothing to export.")
        return

    exporter = queryMultiAdapter((sm, context), IBody, name=u"plone.app.workflow.sharing")
    if exporter:
        body = exporter.body
        if body is not None:
            context.writeDataFile('sharing.xml', body, exporter.mime_type)
Ejemplo n.º 9
0
def exportComponentRegistry(context):
    """Export local components.
    """
    sm = getSiteManager(context.getSite())
    if sm is None or not IComponentRegistry.providedBy(sm):
        logger = context.getLogger('componentregistry')
        logger.info("Nothing to export.")
        return
    # XXX GenericSetup.utils.exportObjects expects the object to have a getId
    # function. We provide a dummy one for now, but this should be fixed in GS
    # itself
    sm.getId = dummyGetId
    exportObjects(sm, '', context)
    del(sm.getId)
Ejemplo n.º 10
0
def importComponentRegistry(context):
    """Import local components.
    """
    sm = getSiteManager(context.getSite())
    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
Ejemplo n.º 11
0
def exportComponentRegistry(context):
    """Export local components.
    """
    sm = getSiteManager(context.getSite())
    if sm is None or not IComponentRegistry.providedBy(sm):
        logger = context.getLogger('componentregistry')
        logger.info("Nothing to export.")
        return
    # XXX GenericSetup.utils.exportObjects expects the object to have a getId
    # function. We provide a dummy one for now, but this should be fixed in GS
    # itself
    sm.getId = dummyGetId
    exportObjects(sm, '', context)
    del (sm.getId)
Ejemplo n.º 12
0
def import_sharing(context):

    sm = getSiteManager(context.getSite())
    logger = context.getLogger('plone.app.workflow')

    if sm is None or not IComponentRegistry.providedBy(sm):
        logger.info("Can not register sharing page roles, as no component registry was found.")
        return

    importer = queryMultiAdapter((sm, context), IBody, name=u"plone.app.workflow.sharing")
    if importer:
        body = context.readDataFile('sharing.xml')
        if body is not None:
            importer.body = body
Ejemplo n.º 13
0
def importComponentRegistry(context):
    """Import local components.
    """
    sm = getSiteManager(context.getSite())
    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
Ejemplo n.º 14
0
def export_sharing(context):

    sm = getSiteManager(context.getSite())
    logger = context.getLogger('plone.app.workflow')

    if sm is None or not IComponentRegistry.providedBy(sm):
        logger.debug("Nothing to export.")
        return

    exporter = queryMultiAdapter((sm, context), IBody, name=u"plone.app.workflow.sharing")
    if exporter:
        body = exporter.body
        if body is not None:
            context.writeDataFile('sharing.xml', body, exporter.mime_type)
Ejemplo n.º 15
0
def import_sharing(context):

    sm = getSiteManager(context.getSite())
    logger = context.getLogger('plone.app.workflow')

    if sm is None or not IComponentRegistry.providedBy(sm):
        logger.info("Can not register sharing page roles, as no component registry was found.")
        return

    importer = queryMultiAdapter((sm, context), IBody, name=u"plone.app.workflow.sharing")
    if importer:
        body = context.readDataFile('sharing.xml')
        if body is not None:
            importer.body = body
Ejemplo n.º 16
0
def enable_ieditfinishedevent(context):
    """
        Replaces handler registration for IObjectModifiedEvent with
        IEditFinishedEvent.
        The important part of this step is purging the component registry of
        old registrations for adapters. Due to the way unregistering works in
        the registry (by comparing actual factory instances instead of
        classes), we cannot rely on the registry to perform this task.
    """
    old_for_ = """plone.multilingualbehavior.interfaces.IDexterityTranslatable
        zope.lifecycleevent.interfaces.IObjectModifiedEvent"""
    new_for_ = """plone.multilingualbehavior.interfaces.IDexterityTranslatable
        plone.dexterity.interfaces.IEditFinishedEvent"""
    handler_name = "plone.multilingualbehavior.subscriber.handler"
    portal = getSite()
    sm = portal.getSiteManager()
    if not IComponentRegistry.providedBy(sm):
        log.warning('Site manager does not provide component registry')
        return

    handler = _resolveDottedName(handler_name)
    required_old = []
    for interface in old_for_.split():
        required_old.append(_resolveDottedName(interface))

    required_new = []
    for interface in new_for_.split():
        required_new.append(_resolveDottedName(interface))

    # Very similar code is found in zope.component.registry.Components,
    # method unregisterHandler()
    # But here we compare the __class__ of each factory, not the factory
    # itself
    existing_registration = [
        (r, n, f, i)
        for (r, n, f, i)
        in sm._handler_registrations
        if (r == tuple(required_old) and f.__class__ == handler.__class__)
    ]

    # Depending on how often the compentneregistry step had been run in the
    # current site, this list may contain one or many registrations for
    # the same pair of interfaces
    for existing in existing_registration:
        if sm.unregisterHandler(
                factory=existing[2], required=required_old):
            log.info('Unregistered old event handler')

    sm.registerHandler(handler, required=required_new)
Ejemplo n.º 17
0
def exportComponentRegistry(context):
    """Export local components.
    """
    sm = getSiteManager(context.getSite())
    if sm is None or not IComponentRegistry.providedBy(sm):
        logger = context.getLogger('componentregistry')
        logger.info("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)
Ejemplo n.º 18
0
def exportLayers(context):
    """Export local browser layers
    """
    sm = getSiteManager(context.getSite())
    if sm is None or not IComponentRegistry.providedBy(sm):
        logger = context.getLogger("browserlayer")
        logger.info("Can not register components - no site manager found.")
        return

    exporter = queryMultiAdapter((sm, context), IBody, name=u"plone.browserlayer")
    if exporter is not None:
        filename = "%s%s" % (exporter.name, exporter.suffix)
        body = exporter.body
        if body is not None:
            context.writeDataFile(filename, body, exporter.mime_type)
Ejemplo n.º 19
0
def exportCustomMenuFactories(context):
    """Export custommenu configuration
    """
    sm = getSiteManager(context.getSite())
    if sm is None or not IComponentRegistry.providedBy(sm):
        logger = context.getLogger("custommenu.factories")
        logger.info("Nothing to export.")
        return

    exporter = queryMultiAdapter((sm, context), IBody, name=u"redturtle.custommenu.factories")
    if exporter:
        filename = "%s%s" % (exporter.name, exporter.suffix)
        body = exporter.body
        if body is not None:
            context.writeDataFile(filename, body, exporter.mime_type)
Ejemplo n.º 20
0
def exportComponentRegistry(context):
    """Export local components.
    """
    sm = getSiteManager(context.getSite())
    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)
Ejemplo n.º 21
0
def importCookieConsentSettings(context):
    """Import cookies consent configurations
    """
    sm = getSiteManager(context.getSite())
    if sm is None or not IComponentRegistry.providedBy(sm):
        logger.info("Can not register components - no site manager found.")
        return

    importer = queryMultiAdapter((sm, context), IBody,
                                  name=u'rer.cookieconsent')
    if importer:
        filename = '%s%s' % (importer.name, importer.suffix)
        body = context.readDataFile(filename)
        if body is not None:
            importer.filename = filename  # for error reporting
            importer.body = body
Ejemplo n.º 22
0
def importCustomMenuFactories(context):
    """Import custommenu configurations
    """
    sm = getSiteManager(context.getSite())
    if sm is None or not IComponentRegistry.providedBy(sm):
        logger = context.getLogger("custommenu.factories")
        logger.info("Can not register components - no site manager found.")
        return

    importer = queryMultiAdapter((sm, context), IBody, name=u"redturtle.custommenu.factories")
    if importer:
        filename = "%s%s" % (importer.name, importer.suffix)
        body = context.readDataFile(filename)
        if body is not None:
            importer.filename = filename  # for error reporting
            importer.body = body
Ejemplo n.º 23
0
def importLayers(context):
    """Import local browser layers
    """
    sm = getSiteManager(context.getSite())
    if sm is None or not IComponentRegistry.providedBy(sm):
        logger = context.getLogger("browserlayer")
        logger.info("Can not register components - no site manager found.")
        return

    importer = queryMultiAdapter((sm, context), IBody, name=u"plone.browserlayer")
    if importer is not None:
        filename = "%s%s" % (importer.name, importer.suffix)
        body = context.readDataFile(filename)
        if body is not None:
            importer.filename = filename  # for error reporting
            importer.body = body
Ejemplo n.º 24
0
def exportLayers(context):
    """Export local browser layers
    """
    sm = getSiteManager(context.getSite())
    if sm is None or not IComponentRegistry.providedBy(sm):
        logger = context.getLogger('browserlayer')
        logger.info("Can not register components - no site manager found.")
        return

    exporter = queryMultiAdapter((sm, context),
                                 IBody,
                                 name=u'plone.browserlayer')
    if exporter is not None:
        filename = '%s%s' % (exporter.name, exporter.suffix)
        body = exporter.body
        if body is not None:
            context.writeDataFile(filename, body, exporter.mime_type)
Ejemplo n.º 25
0
def importCookieConsentSettings(context):
    """Import cookies consent configurations
    """
    sm = getSiteManager(context.getSite())
    if sm is None or not IComponentRegistry.providedBy(sm):
        logger.info("Can not register components - no site manager found.")
        return

    importer = queryMultiAdapter((sm, context),
                                 IBody,
                                 name=u'rer.cookieconsent')
    if importer:
        filename = '%s%s' % (importer.name, importer.suffix)
        body = context.readDataFile(filename)
        if body is not None:
            importer.filename = filename  # for error reporting
            importer.body = body
Ejemplo n.º 26
0
def registerPortletAddview(context):
    portal = getToolByName(context, 'portal_url').getPortalObject()
    sm = getSiteManager(portal)
    if sm is None or not IComponentRegistry.providedBy(sm):
        # plone.app.portlets.exportimport.portlets has this same check.
        logger.info('Cannot register portlet addview - no site manager found.')
        return
    if queryUtility(IPortletType, name=''):
        # For a few years we have registered our portlet with an empty string
        # as add view.  This is wrong.
        sm.unregisterUtility(provided=IPortletType, name='')
        logger.info('Unregistered portlet type with empty addview.')
    addview = 'portlets.OpenIDLogin'
    if queryUtility(IPortletType, name=addview) is None:
        # Apply our default portlets.xml.
        context.runImportStepFromProfile(PROFILE_ID, 'portlets')
        logger.info('Applied our portlets.xml to register portlet '
                    'with correct addview.')
Ejemplo n.º 27
0
def registerPortletAddview(context):
    portal = getToolByName(context, 'portal_url').getPortalObject()
    sm = getSiteManager(portal)
    if sm is None or not IComponentRegistry.providedBy(sm):
        # plone.app.portlets.exportimport.portlets has this same check.
        logger.info('Cannot register portlet addview - no site manager found.')
        return
    if queryUtility(IPortletType, name=''):
        # For a few years we have registered our portlet with an empty string
        # as add view.  This is wrong.
        sm.unregisterUtility(provided=IPortletType, name='')
        logger.info('Unregistered portlet type with empty addview.')
    addview = 'portlets.OpenIDLogin'
    if queryUtility(IPortletType, name=addview) is None:
        # Apply our default portlets.xml.
        context.runImportStepFromProfile(PROFILE_ID, 'portlets')
        logger.info('Applied our portlets.xml to register portlet '
                    'with correct addview.')
Ejemplo n.º 28
0
def importLayers(context):
    """Import local browser layers
    """
    sm = getSiteManager(context.getSite())
    if sm is None or not IComponentRegistry.providedBy(sm):
        logger = context.getLogger('browserlayer')
        logger.info("Can not register components - no site manager found.")
        return

    importer = queryMultiAdapter((sm, context),
                                 IBody,
                                 name=u'plone.browserlayer')
    if importer is not None:
        filename = '%s%s' % (importer.name, importer.suffix)
        body = context.readDataFile(filename)
        if body is not None:
            importer.filename = filename  # for error reporting
            importer.body = body
Ejemplo n.º 29
0
def exportPortlets(context):
    """Export portlet managers and portlets
    """
    sm = getSiteManager(context.getSite())
    if sm is None or not IComponentRegistry.providedBy(sm):
        logger = context.getLogger('portlets')
        logger.info("Nothing to export.")
        return

    # This code was taken from GenericSetup.utils.import.exportObjects
    # and slightly simplified. The main difference is the lookup of a named
    # adapter to make it possible to have more than one handler for the same
    # object, which in case of a component registry is crucial.
    exporter = queryMultiAdapter((sm, context), IBody, name=u'plone.portlets')
    if exporter:
        filename = '%s%s' % (exporter.name, exporter.suffix)
        body = exporter.body
        if body is not None:
            context.writeDataFile(filename, body, exporter.mime_type)
Ejemplo n.º 30
0
def exportPortlets(context):
    """Export portlet managers and portlets
    """
    sm = getSiteManager(context.getSite())
    if sm is None or not IComponentRegistry.providedBy(sm):
        logger = context.getLogger('portlets')
        logger.info("Nothing to export.")
        return

    # This code was taken from GenericSetup.utils.import.exportObjects
    # and slightly simplified. The main difference is the lookup of a named
    # adapter to make it possible to have more than one handler for the same
    # object, which in case of a component registry is crucial.
    exporter = queryMultiAdapter((sm, context), IBody, name=u'plone.portlets')
    if exporter:
        filename = '%s%s' % (exporter.name, exporter.suffix)
        body = exporter.body
        if body is not None:
            context.writeDataFile(filename, body, exporter.mime_type)
Ejemplo n.º 31
0
def importPortlets(context):
    """Import portlet managers and portlets
    """
    sm = getSiteManager(context.getSite())
    if sm is None or not IComponentRegistry.providedBy(sm):
        logger = context.getLogger('portlets')
        logger.info("Can not register components - no site manager found.")
        return

    # This code was taken from GenericSetup.utils.import.importObjects
    # and slightly simplified. The main difference is the lookup of a named
    # adapter to make it possible to have more than one handler for the same
    # object, which in case of a component registry is crucial.
    importer = queryMultiAdapter((sm, context), IBody, name='plone.portlets')
    if importer:
        filename = '%s%s' % (importer.name, importer.suffix)
        body = context.readDataFile(filename)
        if body is not None:
            importer.filename = filename # for error reporting
            importer.body = body
Ejemplo n.º 32
0
def importPortlets(context):
    """Import portlet managers and portlets
    """
    sm = getSiteManager(context.getSite())
    if sm is None or not IComponentRegistry.providedBy(sm):
        logger = context.getLogger('portlets')
        logger.info("Can not register components - no site manager found.")
        return

    # This code was taken from GenericSetup.utils.import.importObjects
    # and slightly simplified. The main difference is the lookup of a named
    # adapter to make it possible to have more than one handler for the same
    # object, which in case of a component registry is crucial.
    importer = queryMultiAdapter((sm, context), IBody, name='plone.portlets')
    if importer:
        filename = '%s%s' % (importer.name, importer.suffix)
        body = context.readDataFile(filename)
        if body is not None:
            importer.filename = filename  # for error reporting
            importer.body = body
Ejemplo n.º 33
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)
Ejemplo n.º 34
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)
def uninstall(context):
    """
    """
    if context.readDataFile('pmb_uninstall.txt') is None:
        return
    for_ = """plone.multilingualbehavior.interfaces.IDexterityTranslatable
        plone.dexterity.interfaces.IEditFinishedEvent"""
    handler_name = "plone.multilingualbehavior.subscriber.handler"

    portal = getSite()
    sm = portal.getSiteManager()
    if not IComponentRegistry.providedBy(sm):
        log.warning('Site manager does not provide component registry')
        return

    handler = _resolveDottedName(handler_name)

    required = []
    for interface in for_.split():
        required.append(_resolveDottedName(interface))

    existing_registration = [(r, n, f, i) for (r, n, f, i) in sm._handler_registrations if (r == tuple(required) and f.__class__ == handler.__class__)]
    # Depending on how often the compentneregistry step had been run in the
    # current site, this list may contain one or many registrations for
    # the same pair of interfaces

    for existing in existing_registration:
        sm.unregisterHandler(
            factory=existing[2], # plone.multilingualbehavior.subscriber.LanguageIndependentModifier
            required=required) # (IDexterityTranslatable, IEditFinishedEvent)
        log.info('Unregistered old event handler')


    # gsm = getGlobalSiteManager()
    # adapter_hook = gsm.adapters.adapter_hook
    # adapters = gsm.utilities._adapters
    # for x in adapters[0]:
    #     for key in adapters[0][x].keys():
    #         if 'plone.multilingualbehavior' in str(key):
    #             del adapters[0][x][key]
    #             log.info("Delete adapter {0} from {1}".format(key, x))
    # gsm.utilities._adapters = adapters

    # provided = gsm.utilities._provided
    # for x in provided:
    #     for interface in interfaces:
    #         if interface in str(x):
    #             del provided[x]
    #             log.info("Delete provided {0} from {1}".format(interface, x))
    # gsm.utilities._provided = provided

    subscribers = sm.adapters._subscribers
    for i, sub in enumerate(subscribers):
        for key in sub.keys():
            if 'multilingualbehavior' in str(key):
                del subscribers[i][key]
    sm.adapters._subscribers = subscribers

    transaction.commit()
    app = portal.restrictedTraverse('/')
    app._p_jar.sync()