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

Noe*_*eto 9 zope plone buildout

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

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

我的想法是配置一个位置来存储可配置路径中的信息,就像iw.fss和iw.recipe.fss一样.

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

Mar*_*ers 17

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

[instance]
recipe = plone.recipe.zope2instance
...
zope-conf-additional =
   <product-config foobar>
       spam eggs
   </product-config>
Run Code Online (Sandbox Code Playgroud)

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

from App.config import getConfiguration
config = getConfiguration()
configuration = config.product_config.get('foobar', dict())
spamvalue = configuration.get('spam')
Run Code Online (Sandbox Code Playgroud)