[Zope3-Users] Resource lookup by resource name

Shailesh Kumar shaileshk at gmail.com
Sat Oct 17 08:02:28 EDT 2009


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,
                        DirectoryResourceFactory,
                        allowed_names, NamesChecker )


def registerResourceDirectory(name, resourcedir,
                             layer=IDefaultBrowserLayer,
                             permission='zope.Public'):
    """
    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'),
                           permission)
    factory = DirectoryResourceFactory(resourcedir, checker, name)
    gsm = getGlobalSiteManager()
    gsm.registerAdapter(factory, (layer,), Interface, name)
    return True


def unregisterResourceDirectory(name,
                             layer=IDefaultBrowserLayer):
    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 <lists at 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 at zope.org
> https://mail.zope.org/mailman/listinfo/zope3-users
>
>


More information about the Zope3-users mailing list