[Checkins] SVN: zc.zope3recipes/trunk/ add support for repeated keys in ZConfig sections

Fred L. Drake, Jr. fdrake at gmail.com
Tue May 22 13:10:44 EDT 2007


Log message for revision 75888:
  add support for repeated keys in ZConfig sections

Changed:
  U   zc.zope3recipes/trunk/README.txt
  U   zc.zope3recipes/trunk/setup.py
  U   zc.zope3recipes/trunk/zc/zope3recipes/README.txt
  U   zc.zope3recipes/trunk/zc/zope3recipes/recipes.py

-=-
Modified: zc.zope3recipes/trunk/README.txt
===================================================================
--- zc.zope3recipes/trunk/README.txt	2007-05-22 16:59:21 UTC (rev 75887)
+++ zc.zope3recipes/trunk/README.txt	2007-05-22 17:10:43 UTC (rev 75888)
@@ -17,6 +17,12 @@
 ********
 
 ==================
+0.5.1 (2007/05/22)
+==================
+
+Support repeated keys in ZConfig sections.
+
+==================
 0.5.0 (2007/03/21)
 ==================
 

Modified: zc.zope3recipes/trunk/setup.py
===================================================================
--- zc.zope3recipes/trunk/setup.py	2007-05-22 16:59:21 UTC (rev 75887)
+++ zc.zope3recipes/trunk/setup.py	2007-05-22 17:10:43 UTC (rev 75888)
@@ -21,7 +21,7 @@
 name = "zc.zope3recipes"
 setup(
     name = name,
-    version = "0.5.0",
+    version = "0.5.1",
     author = "Jim Fulton",
     author_email = "jim at zope.com",
     description = "ZC Buildout recipe for defining Zope 3 applications",

Modified: zc.zope3recipes/trunk/zc/zope3recipes/README.txt
===================================================================
--- zc.zope3recipes/trunk/zc/zope3recipes/README.txt	2007-05-22 16:59:21 UTC (rev 75887)
+++ zc.zope3recipes/trunk/zc/zope3recipes/README.txt	2007-05-22 17:10:43 UTC (rev 75888)
@@ -1205,6 +1205,101 @@
             ]+sys.argv[1:]
             )
 
+Some configuration sections can include a key multiple times; the ZEO
+client section works this way.  When a key is given multiple times,
+all values are included in the resulting configuration in the order in
+which they're give in the input::
+
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... develop = demo1 demo2
+    ... parts = instance
+    ...
+    ... [zope3]
+    ... location = %(zope3)s
+    ...
+    ... [myapp]
+    ... recipe = zc.zope3recipes:app
+    ... site.zcml = <include package="demo2" />
+    ...             <principal
+    ...                 id="zope.manager"
+    ...                 title="Manager"
+    ...                 login="jim"
+    ...                 password_manager="SHA1"
+    ...                 password="40bd001563085fc35165329ea1ff5c5ecbdbbeef"
+    ...                 />
+    ...             <grant
+    ...                 role="zope.Manager"
+    ...                 principal="zope.manager"
+    ...                 />
+    ... eggs = demo2
+    ...
+    ... [instance]
+    ... recipe = zc.zope3recipes:instance
+    ... application = myapp
+    ... zope.conf =
+    ...     <zodb>
+    ...       <zeoclient>
+    ...         server 127.0.0.1:8001
+    ...         server 127.0.0.1:8002
+    ...       </zeoclient>
+    ...     </zodb>
+    ... address = 8081
+    ... zdaemon.conf =
+    ...     <runner>
+    ...       daemon off
+    ...       socket-name /sample-buildout/parts/instance/sock
+    ...       transcript /dev/null
+    ...     </runner>
+    ...     <eventlog>
+    ...     </eventlog>
+    ...
+    ... ''' % globals())
+
+    >>> print system(join('bin', 'buildout')),
+    buildout: Develop: /sample-buildout/demo1
+    buildout: Develop: /sample-buildout/demo2
+    buildout: Uninstalling instance
+    buildout: Uninstalling database
+    buildout: Updating myapp
+    zc.buildout.easy_install: Generated script /sample-buildout/parts/myapp/runzope.
+    zc.buildout.easy_install: Generated script /sample-buildout/parts/myapp/debugzope.
+    buildout: Installing instance
+    zc.buildout.easy_install: Generated script /sample-buildout/bin/instance.
+
+    >>> cat('parts', 'instance', 'zope.conf')
+    site-definition /sample-buildout/parts/myapp/site.zcml
+    <BLANKLINE>
+    <zodb>
+      <zeoclient>
+        server 127.0.0.1:8001
+        server 127.0.0.1:8002
+      </zeoclient>
+    <BLANKLINE>
+    </zodb>
+    <BLANKLINE>
+    <server>
+      address 8081
+      type HTTP
+    </server>
+    <BLANKLINE>
+    <accesslog>
+      <logfile>
+        path /sample-buildout/parts/instance/access.log
+      </logfile>
+    <BLANKLINE>
+    </accesslog>
+    <BLANKLINE>
+    <eventlog>
+      <logfile>
+        formatter zope.exceptions.log.Formatter
+        path STDOUT
+      </logfile>
+    <BLANKLINE>
+    </eventlog>
+
+
 Log files
 ---------
 
@@ -1316,7 +1411,7 @@
     buildout: Develop: /sample-buildout/demo1
     buildout: Develop: /sample-buildout/demo2
     buildout: Uninstalling instance
-    buildout: Updating database
+    buildout: Installing database
     buildout: Updating myapp
     zc.buildout.easy_install: Generated script /sample-buildout/parts/myapp/runzope.
     zc.buildout.easy_install: Generated script /sample-buildout/parts/myapp/debugzope.

Modified: zc.zope3recipes/trunk/zc/zope3recipes/recipes.py
===================================================================
--- zc.zope3recipes/trunk/zc/zope3recipes/recipes.py	2007-05-22 16:59:21 UTC (rev 75887)
+++ zc.zope3recipes/trunk/zc/zope3recipes/recipes.py	2007-05-22 17:10:43 UTC (rev 75888)
@@ -213,14 +213,14 @@
             zope_conf = options.get('zope.conf', '')+'\n'
             zope_conf = ZConfigParse(cStringIO.StringIO(zope_conf))
 
-            zope_conf['site-definition'] = os.path.join(app_loc, 'site.zcml')
+            zope_conf['site-definition'] = [os.path.join(app_loc, 'site.zcml')]
 
             server_type = server_types[options['servers']][1]
             for address in options.get('address', '').split():
                 zope_conf.sections.append(
                     ZConfigSection('server',
-                                   data=dict(type=server_type,
-                                             address=address,
+                                   data=dict(type=[server_type],
+                                             address=[address],
                                              ),
                                    )
                     )
@@ -228,8 +228,8 @@
                     if ('server' in s.type)]:
                 zope_conf.sections.append(
                     ZConfigSection('server',
-                                   data=dict(type=server_type,
-                                             address='8080',
+                                   data=dict(type=[server_type],
+                                             address=['8080'],
                                              ),
                                    )
                     )
@@ -268,7 +268,7 @@
                 zdaemon_conf.sections.insert(0, runner)
             for name, value in defaults.items():
                 if name not in runner:
-                    runner[name] = value
+                    runner.addValue(name, value)
 
             if not [s for s in zdaemon_conf.sections
                     if s.type == 'eventlog']:
@@ -316,15 +316,15 @@
 def access_log(path):
     return ZConfigSection(
         'accesslog', '',
-        sections=[ZConfigSection('logfile', '', dict(path=path))]
+        sections=[ZConfigSection('logfile', '', dict(path=[path]))]
         )
 
 def event_log(path, *data):
     return ZConfigSection(
         'eventlog', '', None,
         [ZConfigSection('logfile', '',
-                        dict(path=path,
-                             formatter='zope.exceptions.log.Formatter',
+                        dict(path=[path],
+                             formatter=['zope.exceptions.log.Formatter'],
                              )
                         )
          ],
@@ -334,7 +334,7 @@
     return ZConfigSection(
         'eventlog', '', None,
         [ZConfigSection('logfile', '',
-                        dict(path=path,
+                        dict(path=[path],
                              )
                         )
          ],
@@ -380,7 +380,10 @@
         self.type, self.name = type, name
 
     def addValue(self, key, value, *args):
-        self[key] = value
+        if key in self:
+            self[key].append(value)
+        else:
+            self[key] = [value]
 
     def __str__(self, pre=''):
         result = []
@@ -391,8 +394,9 @@
                 result = ['%s<%s>' % (pre, self.type)]
             pre += '  '
 
-        for name, value in sorted(self.items()):
-            result.append('%s%s %s' % (pre, name, value))
+        for name, values in sorted(self.items()):
+            for value in values:
+                result.append('%s%s %s' % (pre, name, value))
 
         if self.sections and self:
             result.append('')



More information about the Checkins mailing list