Commit 82701778 authored by Tres Seaver's avatar Tres Seaver

Allow custom section types to play in <product-config>.

parent cca0f2fa
...@@ -28,9 +28,10 @@ Zope Changes ...@@ -28,9 +28,10 @@ Zope Changes
- Added a 'product-config' section type to zope.conf, allowing - Added a 'product-config' section type to zope.conf, allowing
arbitrary key-value mappings. Products can look for such arbitrary key-value mappings. Products can look for such
confgiurations to set product-specific options (see the confgiurations to set product-specific options. Products mwy
example '<product-config>' section in skel/etc/zope.conf.in also register their own section types, extending the
for sample usage). 'zope.product.base' type. (see the example '<product-config>'
section in skel/etc/zope.conf.in for sample usage).
- Collector #1490: Added a new zope.conf option to control the - Collector #1490: Added a new zope.conf option to control the
character set used to encode unicode data that reaches character set used to encode unicode data that reaches
......
...@@ -113,6 +113,7 @@ def python_dotted_path(name): ...@@ -113,6 +113,7 @@ def python_dotted_path(name):
def root_config(section): def root_config(section):
from ZConfig import ConfigurationError from ZConfig import ConfigurationError
from ZConfig.matcher import SectionValue
here = os.path.dirname(os.path.abspath(__file__)) here = os.path.dirname(os.path.abspath(__file__))
swhome = os.path.dirname(os.path.dirname(here)) swhome = os.path.dirname(os.path.dirname(here))
section.softwarehome = swhome section.softwarehome = swhome
...@@ -152,7 +153,15 @@ def root_config(section): ...@@ -152,7 +153,15 @@ def root_config(section):
pconfigs = {} pconfigs = {}
for pconfig in section.product_config: for pconfig in section.product_config:
pconfigs[pconfig.getSectionName()] = pconfig.mapping section_name = pconfig.getSectionName()
if isinstance(pconfig, SectionValue):
section_type = pconfig.getSectionType()
if section_type == 'product-config':
pconfigs[section_name] = pconfig.mapping
else:
pconfigs[section_name] = pconfig
else:
pconfigs[section_name] = pconfig
section.product_config = pconfigs section.product_config = pconfigs
...@@ -227,6 +236,3 @@ def default_zpublisher_encoding(value): ...@@ -227,6 +236,3 @@ def default_zpublisher_encoding(value):
Converters.default_encoding = value Converters.default_encoding = value
HTTPRequest.default_encoding = value HTTPRequest.default_encoding = value
HTTPResponse.default_encoding = value HTTPResponse.default_encoding = value
class ProductConfig(dict):
pass
...@@ -821,7 +821,18 @@ ...@@ -821,7 +821,18 @@
<metadefault>iso-8859-15</metadefault> <metadefault>iso-8859-15</metadefault>
</key> </key>
<sectiontype name="product-config"> <abstracttype name="zope.product.base">
<description>
Base type for product-specific configuration sections.
Specific products should implement configuration sections by
defining section types that implement this abstract type and
using their own schema component to define meaningful settings.
</description>
</abstracttype>
<sectiontype name="product-config" implements="zope.product.base">
<description> <description>
Product-specific configuration, expressed as arbitrary name-value pairs. Product-specific configuration, expressed as arbitrary name-value pairs.
</description> </description>
...@@ -832,12 +843,17 @@ ...@@ -832,12 +843,17 @@
/> />
</sectiontype> </sectiontype>
<multisection type="product-config" name="+" <multisection type="zope.product.base" name="+"
attribute="product_config"> attribute="product_config">
<description> <description>
Product-specific configuration, expressed as arbitrary name-value pairs. Product-specific configuration stanzas.
Products may use the &lt;product-config&gt; section type, or may supply
a component.xml which defines section types with their own schemas.
All sections for this multisection will be collected into the
'product_config' attribute of the configuration object.
</description> </description>
</multisection> </multisection>
</schema> </schema>
...@@ -983,8 +983,37 @@ instancehome $INSTANCE ...@@ -983,8 +983,37 @@ instancehome $INSTANCE
# parsed into a dict, {'bar': 'baz'}, available as # parsed into a dict, {'bar': 'baz'}, available as
# config.product_config['foo'] # config.product_config['foo']
# #
# Products may also register their own section types, extending
#
#
# Example: # Example:
# #
# <product-config foo> # 1. Simple "bag of strings" section:
# bar baz #
# </product-config> # <product-config foo>
# bar baz
# </product-config>
#
# 2. Custom section type
#
# Products/Foo/component.xml:
#
# <component>
# <description>
# Some product-specific hackery.
# </description>
# <sectiontype name="myproduct" implements="zope.product.base">
# <description>
# Product-specific configuration.
# </description>
# <key name="foo" />
# </sectiontype>
# </component>
#
# In zope.conf:
#
# %import Products.Foo
#
# <myproduct bar>
# foo qux
# </myproduct>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment