Reputation: 2600
How do I include configuration information from Buildout in my Plone products?
One of the plone products i'm working on reads and writes info to and from the filesystem. It currently does that inside the egg namespace (for example inside plone/product/directory), but that doesn't look quite right to me.
The idea is to configure a place to store that information in a configurable path, just like iw.fss and iw.recipe.fss does.
For example, save that info to ${buildout:directory}/var/mydata.
Upvotes: 8
Views: 950
Reputation: 1121296
You could add configuration sections to your zope.conf file via the zope-conf-additional section of the plone.recipe.zope2instance part:
[instance]
recipe = plone.recipe.zope2instance
...
zope-conf-additional =
<product-config foobar>
spam eggs
</product-config>
Any named product-config section is then available as a simple dictionary to any python product that cares to look for it; the above example creates a 'foobar' entry which is a dict with a 'spam': 'eggs' mapping. Here is how you then access that from your code:
from App.config import getConfiguration
config = getConfiguration()
configuration = config.product_config.get('foobar', dict())
spamvalue = configuration.get('spam')
Upvotes: 16