Exemple #1
0
    def render(self):
        context = aq_inner(self.context)
        from Products.GenericSetup.tests.common import DummyImportContext
        from plone.app.registry.exportimport.handler import RegistryImporter
        from genweb.core.browser.cachesettings import cacheprofile
        from plone.cachepurging.interfaces import ICachePurgingSettings
        contextImport = DummyImportContext(context, purge=False)
        registry = queryUtility(IRegistry)
        importer = RegistryImporter(registry, contextImport)
        importer.importDocument(cacheprofile)

        cachepurginsettings = registry.forInterface(ICachePurgingSettings)

        varnish_url = os.environ.get('varnish_url', False)
        logger = logging.getLogger(
            'Genweb: Executing configure cache on site -')
        logger.info('%s' % self.context.id)
        if varnish_url:
            cachepurginsettings.cachingProxies = (varnish_url, )
            logger.info('Successfully set caching for this site')
            return 'Successfully set caching for this site.'
        else:
            logger.info(
                'There are not any varnish_url in the environment. No caching proxy could be configured.'
            )
            return 'There are not any varnish_url in the environment. No caching proxy could be configured.'
Exemple #2
0
 def createRegistry(self, xml):
     """Create a registry from a minimal set of fields and operators"""
     from plone.app.registry.exportimport.handler import RegistryImporter
     gsm = getGlobalSiteManager()
     self.registry = Registry()
     gsm.registerUtility(self.registry, IRegistry)
     importer = RegistryImporter(self.registry, self)
     importer.importDocument(xml)
     return self.registry
 def createRegistry(self, xml):
     """Create a registry from a minimal set of fields and operators"""
     from plone.app.registry.exportimport.handler import RegistryImporter
     gsm = getGlobalSiteManager()
     self.registry = Registry()
     gsm.registerUtility(self.registry, IRegistry)
     importer = RegistryImporter(self.registry, self)
     importer.importDocument(xml)
     return self.registry
Exemple #4
0
    def render(self):
        context = aq_inner(self.context)
        from Products.GenericSetup.tests.common import DummyImportContext
        from plone.app.registry.exportimport.handler import RegistryImporter
        from genweb.core.browser.cachesettings import cacheprofile
        from plone.cachepurging.interfaces import ICachePurgingSettings
        contextImport = DummyImportContext(context, purge=False)
        registry = queryUtility(IRegistry)
        importer = RegistryImporter(registry, contextImport)
        importer.importDocument(cacheprofile)

        cachepurginsettings = registry.forInterface(ICachePurgingSettings)
        cacheserver = 'http://sylar.upc.es:90%02d' % int(getDorsal())
        cachepurginsettings.cachingProxies = (cacheserver,)

        return 'Configuracio de cache importada correctament.'
Exemple #5
0
 def import_registry(self):
     try:
         fi = self.request.form['file']
         body = fi.read()
     except (AttributeError, KeyError):
         messages = IStatusMessage(self.request)
         messages.add(u"Must provide XML file", type=u"error")
         body = None
     if body is not None:
         importer = RegistryImporter(self.context, FakeEnv())
         try:
             importer.importDocument(body)
         except XMLSyntaxError:
             messages = IStatusMessage(self.request)
             messages.add(u"Must provide valid XML file", type=u"error")
     return self.request.response.redirect(self.context.absolute_url())
Exemple #6
0
 def import_registry(self):
     try:
         fi = self.request.form['file']
         body = fi.read()
     except (AttributeError, KeyError):
         messages = IStatusMessage(self.request)
         messages.add(u"Must provide XML file", type=u"error")
         body = None
     if body is not None:
         importer = RegistryImporter(self.context, FakeEnv())
         try:
             importer.importDocument(body)
         except XMLSyntaxError:
             messages = IStatusMessage(self.request)
             messages.add(u"Must provide valid XML file", type=u"error")
     return self.request.response.redirect(self.context.absolute_url())
Exemple #7
0
    def render(self):
        context = aq_inner(self.context)
        from Products.GenericSetup.tests.common import DummyImportContext
        from plone.app.registry.exportimport.handler import RegistryImporter
        from genweb.core.browser.cachesettings import cacheprofile
        from plone.cachepurging.interfaces import ICachePurgingSettings
        contextImport = DummyImportContext(context, purge=False)
        registry = queryUtility(IRegistry)
        importer = RegistryImporter(registry, contextImport)
        importer.importDocument(cacheprofile)

        cachepurginsettings = registry.forInterface(ICachePurgingSettings)

        varnish_url = os.environ.get('varnish_url', False)
        logger = logging.getLogger('Genweb: Executing configure cache on site -')
        logger.info('%s' % self.context.id)
        if varnish_url:
            cachepurginsettings.cachingProxies = (varnish_url,)
            logger.info('Successfully set caching for this site')
            return 'Successfully set caching for this site.'
        else:
            logger.info('There are not any varnish_url in the environment. No caching proxy could be configured.')
            return 'There are not any varnish_url in the environment. No caching proxy could be configured.'
from plone.app.registry.browser.records import FakeEnv
from plone.app.registry.exportimport.handler import RegistryImporter
from transaction import commit

import sys

sites = app.objectValues("Plone Site")  # noqa:F821

for filename in sys.argv[3:]:
    for site in sites:
        importer = RegistryImporter(site.portal_registry, FakeEnv())
        with open(filename) as f:
            print(f"Importing {filename} in {site}")
            importer.importDocument(f.read())
commit()