Discussion:
[Zope3-Users] Resource lookup by resource name
Andreas Jung
2009-10-17 07:11:05 UTC
Permalink
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
Shailesh Kumar
2009-10-17 12:02:28 UTC
Permalink
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
Post by Andreas Jung
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
https://mail.zope.org/mailman/listinfo/zope3-users
Loading...