[Zope-Checkins] SVN: Zope/trunk/ Allow custom section types to play in <product-config>.

Tres Seaver tseaver at palladion.com
Wed Oct 26 15:10:41 EDT 2005


Log message for revision 39652:
  Allow custom section types to play in <product-config>.

Changed:
  U   Zope/trunk/doc/CHANGES.txt
  U   Zope/trunk/lib/python/Zope2/Startup/datatypes.py
  U   Zope/trunk/lib/python/Zope2/Startup/zopeschema.xml
  U   Zope/trunk/skel/etc/zope.conf.in

-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt	2005-10-26 18:36:17 UTC (rev 39651)
+++ Zope/trunk/doc/CHANGES.txt	2005-10-26 19:10:40 UTC (rev 39652)
@@ -28,9 +28,10 @@
 
       - Added a 'product-config' section type to zope.conf, allowing
         arbitrary key-value mappings.  Products can look for such
-        confgiurations to set product-specific options (see the
-        example '<product-config>' section in skel/etc/zope.conf.in
-        for sample usage).
+        confgiurations to set product-specific options.  Products mwy
+        also register their own section types, extending the
+        '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
         character set used to encode unicode data that reaches

Modified: Zope/trunk/lib/python/Zope2/Startup/datatypes.py
===================================================================
--- Zope/trunk/lib/python/Zope2/Startup/datatypes.py	2005-10-26 18:36:17 UTC (rev 39651)
+++ Zope/trunk/lib/python/Zope2/Startup/datatypes.py	2005-10-26 19:10:40 UTC (rev 39652)
@@ -113,6 +113,7 @@
 
 def root_config(section):
     from ZConfig import ConfigurationError
+    from ZConfig.matcher import SectionValue
     here = os.path.dirname(os.path.abspath(__file__))
     swhome = os.path.dirname(os.path.dirname(here))
     section.softwarehome = swhome
@@ -152,7 +153,15 @@
 
     pconfigs = {}
     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
 
@@ -227,6 +236,3 @@
     Converters.default_encoding = value
     HTTPRequest.default_encoding = value
     HTTPResponse.default_encoding = value
-
-class ProductConfig(dict):
-    pass

Modified: Zope/trunk/lib/python/Zope2/Startup/zopeschema.xml
===================================================================
--- Zope/trunk/lib/python/Zope2/Startup/zopeschema.xml	2005-10-26 18:36:17 UTC (rev 39651)
+++ Zope/trunk/lib/python/Zope2/Startup/zopeschema.xml	2005-10-26 19:10:40 UTC (rev 39652)
@@ -821,8 +821,19 @@
      <metadefault>iso-8859-15</metadefault>
   </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>
     Product-specific configuration, expressed as arbitrary name-value pairs.
     </description>
 
@@ -832,12 +843,17 @@
          />
   </sectiontype>
 
-  <multisection type="product-config" name="+"
+  <multisection type="zope.product.base" name="+"
                 attribute="product_config">
    <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>
   </multisection>
 
-
 </schema>

Modified: Zope/trunk/skel/etc/zope.conf.in
===================================================================
--- Zope/trunk/skel/etc/zope.conf.in	2005-10-26 18:36:17 UTC (rev 39651)
+++ Zope/trunk/skel/etc/zope.conf.in	2005-10-26 19:10:40 UTC (rev 39652)
@@ -983,8 +983,37 @@
 #    parsed into a dict, {'bar': 'baz'}, available as
 #    config.product_config['foo']
 #
+#    Products may also register their own section types, extending
+#    
+#
 # Example: 
 #
-# <product-config foo>
-#    bar baz
-# </product-config>
+# 1. Simple "bag of strings" section:
+#
+#    <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>



More information about the Zope-Checkins mailing list