Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I get configuration from buildout in my plone products?

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.

like image 696
Noe Nieto Avatar asked May 26 '11 19:05

Noe Nieto


1 Answers

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')
like image 142
Martijn Pieters Avatar answered Sep 19 '22 16:09

Martijn Pieters