如何在我的plone产品中从buildout获取配置?

时间:2011-05-26 19:57:21

标签: plone zope buildout

如何在Plone产品中包含Buildout的配置信息?

我正在研究的plone产品之一是从文件系统读取和写入信息。它目前在egg命名空间内执行(例如在plone / product /目录中),但这对我来说并不合适。

我们的想法是配置一个地方将信息存储在一个可配置的路径中,就像iw.fss和iw.recipe.fss一样。

例如,将该信息保存到$ {buildout:directory} / var / mydata。

1 个答案:

答案 0 :(得分:17)

您可以通过plone.recipe.zope2instance部分的zope-conf-additional部分向zope.conf文件添加配置部分:

[instance]
recipe = plone.recipe.zope2instance
...
zope-conf-additional =
   <product-config foobar>
       spam eggs
   </product-config>

任何命名的product-config部分都可以作为一个简单的字典提供给任何关心它的python产品;上面的例子创建了一个'foobar'条目,这是一个带有'spam'的字典:'eggs'映射。以下是您从代码中访问它的方式:

from App.config import getConfiguration
config = getConfiguration()
configuration = config.product_config.get('foobar', dict())
spamvalue = configuration.get('spam')
相关问题