Hi Andreas,

I had a requirement where I needed to manage the resource directories
dynamically. So I developed some of following code. I guess this might
be of help.

Functions to work with browser resources at run time

#python imports
import logging

# zope imports
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from zope.interface import Interface
from zope.component.globalregistry import getGlobalSiteManager
from zope.app.publisher.browser.resourcemeta import (CheckerPublic,
                        allowed_names, NamesChecker )

def registerResourceDirectory(name, resourcedir,
    This function registers a resource directory with global registry
    logging.info('Registering %s as %s' , resourcedir, name)
    if permission == 'zope.Public':
        permission = CheckerPublic
    checker = NamesChecker(allowed_names + ('__getitem__', 'get'),
    factory = DirectoryResourceFactory(resourcedir, checker, name)
    gsm = getGlobalSiteManager()
    gsm.registerAdapter(factory, (layer,), Interface, name)
    return True

def unregisterResourceDirectory(name,
    logging.info('Removing %s' , name)
    gsm = getGlobalSiteManager()
    gsm.registerAdapter(None, (layer,), Interface, name)
    return True

On Sat, Oct 17, 2009 at 12:41 PM, Andreas Jung <li...@zopyx.com> wrote:
> Assume I have a <browser:resourceDirectory .../> configuration
> somewhere in my system. What is the API to lookup the the directory
> path for a configured resource 'name'?
> Andreas
> _______________________________________________
> Zope3-users mailing list
> Zope3-users@zope.org
> https://mail.zope.org/mailman/listinfo/zope3-users
Zope3-users mailing list

Reply via email to