[Checkins] SVN: zc.zope3recipes/trunk/ use the new schemaless
support from ZConfig, mostly so we can get %import
Fred L. Drake, Jr.
fdrake at gmail.com
Thu Jun 21 13:57:49 EDT 2007
Log message for revision 76910:
use the new schemaless support from ZConfig, mostly so we can get %import
support without having to implement it within the recipe
Changed:
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/setup.py
===================================================================
--- zc.zope3recipes/trunk/setup.py 2007-06-21 17:56:43 UTC (rev 76909)
+++ zc.zope3recipes/trunk/setup.py 2007-06-21 17:57:48 UTC (rev 76910)
@@ -35,7 +35,7 @@
#package_dir = {'':'src'},
namespace_packages = ['zc'],
install_requires = ['zc.buildout', 'zope.testing', 'setuptools',
- 'zc.recipe.egg', 'ZConfig'],
+ 'zc.recipe.egg', 'ZConfig >=2.4a5'],
dependency_links = ['http://download.zope.org/distribution/'],
entry_points = {
'zc.buildout': [
Modified: zc.zope3recipes/trunk/zc/zope3recipes/README.txt
===================================================================
--- zc.zope3recipes/trunk/zc/zope3recipes/README.txt 2007-06-21 17:56:43 UTC (rev 76909)
+++ zc.zope3recipes/trunk/zc/zope3recipes/README.txt 2007-06-21 17:57:48 UTC (rev 76910)
@@ -628,7 +628,6 @@
<filestorage>
path /sample-buildout/parts/database/Data.fs
</filestorage>
- <BLANKLINE>
</zodb>
<BLANKLINE>
<server>
@@ -640,7 +639,6 @@
<logfile>
path /sample-buildout/parts/instance/access.log
</logfile>
- <BLANKLINE>
</accesslog>
<BLANKLINE>
<eventlog>
@@ -648,7 +646,6 @@
formatter zope.exceptions.log.Formatter
path STDOUT
</logfile>
- <BLANKLINE>
</eventlog>
This uses the twisted server types, since that's the default
@@ -712,7 +709,6 @@
<filestorage>
path /sample-buildout/parts/database/Data.fs
</filestorage>
- <BLANKLINE>
</zodb>
<BLANKLINE>
<server>
@@ -724,7 +720,6 @@
<logfile>
path /sample-buildout/parts/instance/access.log
</logfile>
- <BLANKLINE>
</accesslog>
<BLANKLINE>
<eventlog>
@@ -732,7 +727,6 @@
formatter zope.exceptions.log.Formatter
path STDOUT
</logfile>
- <BLANKLINE>
</eventlog>
The Twisted-based servers can also be specified explicitly:
@@ -794,7 +788,6 @@
<filestorage>
path /sample-buildout/parts/database/Data.fs
</filestorage>
- <BLANKLINE>
</zodb>
<BLANKLINE>
<server>
@@ -806,7 +799,6 @@
<logfile>
path /sample-buildout/parts/instance/access.log
</logfile>
- <BLANKLINE>
</accesslog>
<BLANKLINE>
<eventlog>
@@ -814,7 +806,6 @@
formatter zope.exceptions.log.Formatter
path STDOUT
</logfile>
- <BLANKLINE>
</eventlog>
It includes the database definition that we provided in the zope.conf
@@ -887,7 +878,6 @@
<filestorage>
path /sample-buildout/parts/database/Data.fs
</filestorage>
- <BLANKLINE>
</zodb>
<BLANKLINE>
<server>
@@ -899,7 +889,6 @@
<logfile>
path /sample-buildout/parts/instance/access.log
</logfile>
- <BLANKLINE>
</accesslog>
<BLANKLINE>
<eventlog>
@@ -907,7 +896,6 @@
formatter zope.exceptions.log.Formatter
path STDOUT
</logfile>
- <BLANKLINE>
</eventlog>
If we just want to specify alternate ports or addresses, we can use
@@ -964,7 +952,6 @@
<filestorage>
path /sample-buildout/parts/database/Data.fs
</filestorage>
- <BLANKLINE>
</zodb>
<BLANKLINE>
<server>
@@ -981,7 +968,6 @@
<logfile>
path /sample-buildout/parts/instance/access.log
</logfile>
- <BLANKLINE>
</accesslog>
<BLANKLINE>
<eventlog>
@@ -989,7 +975,6 @@
formatter zope.exceptions.log.Formatter
path STDOUT
</logfile>
- <BLANKLINE>
</eventlog>
We can specify our own accesslog and eventlog configuration. For
@@ -1056,7 +1041,6 @@
<filestorage>
path /sample-buildout/parts/database/Data.fs
</filestorage>
- <BLANKLINE>
</zodb>
<BLANKLINE>
<eventlog>
@@ -1064,7 +1048,6 @@
formatter zope.exceptions.log.Formatter
path /sample-buildout/parts/instance/event.log
</logfile>
- <BLANKLINE>
</eventlog>
<BLANKLINE>
<accesslog>
@@ -1090,7 +1073,6 @@
<logfile>
path /sample-buildout/parts/instance/z3.log
</logfile>
- <BLANKLINE>
</eventlog>
Here we see a fairly ordinary zdaemon.conf file. The program option
@@ -1264,7 +1246,6 @@
server 127.0.0.1:8001
server 127.0.0.1:8002
</zeoclient>
- <BLANKLINE>
</zodb>
<BLANKLINE>
<server>
@@ -1276,7 +1257,6 @@
<logfile>
path /sample-buildout/parts/instance/access.log
</logfile>
- <BLANKLINE>
</accesslog>
<BLANKLINE>
<eventlog>
@@ -1284,7 +1264,6 @@
formatter zope.exceptions.log.Formatter
path STDOUT
</logfile>
- <BLANKLINE>
</eventlog>
@@ -1442,7 +1421,6 @@
<filestorage>
path /sample-buildout/parts/database/Data.fs
</filestorage>
- <BLANKLINE>
</zodb>
<BLANKLINE>
<server>
@@ -1454,7 +1432,6 @@
<logfile>
path /root/var/log/myapp-run/instance-access.log
</logfile>
- <BLANKLINE>
</accesslog>
<BLANKLINE>
<eventlog>
@@ -1462,7 +1439,6 @@
formatter zope.exceptions.log.Formatter
path STDOUT
</logfile>
- <BLANKLINE>
</eventlog>
>>> cat(root, 'etc', 'myapp-run', 'instance-zdaemon.conf')
@@ -1479,7 +1455,6 @@
<logfile>
path /root/var/log/myapp-run/instance-z3.log
</logfile>
- <BLANKLINE>
</eventlog>
Defining multiple similar instances
@@ -1565,7 +1540,6 @@
<filestorage>
path /sample-buildout/parts/database/Data.fs
</filestorage>
- <BLANKLINE>
</zodb>
<BLANKLINE>
<server>
@@ -1577,7 +1551,6 @@
<logfile>
path /root/var/log/myapp-run/instance2-access.log
</logfile>
- <BLANKLINE>
</accesslog>
<BLANKLINE>
<eventlog>
@@ -1585,5 +1558,4 @@
formatter zope.exceptions.log.Formatter
path STDOUT
</logfile>
- <BLANKLINE>
</eventlog>
Modified: zc.zope3recipes/trunk/zc/zope3recipes/recipes.py
===================================================================
--- zc.zope3recipes/trunk/zc/zope3recipes/recipes.py 2007-06-21 17:56:43 UTC (rev 76909)
+++ zc.zope3recipes/trunk/zc/zope3recipes/recipes.py 2007-06-21 17:57:48 UTC (rev 76910)
@@ -18,7 +18,7 @@
import zc.buildout
import zc.recipe.egg
import pkg_resources
-import ZConfig.cfgparser
+import ZConfig.schemaless
import cStringIO
this_loc = pkg_resources.working_set.find(
@@ -211,27 +211,24 @@
app_loc = options['application-location']
zope_conf = options.get('zope.conf', '')+'\n'
- zope_conf = ZConfigParse(cStringIO.StringIO(zope_conf))
+ zope_conf = ZConfig.schemaless.loadConfigFile(
+ cStringIO.StringIO(zope_conf))
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],
- ),
- )
+ ZConfig.schemaless.Section(
+ 'server',
+ data=dict(type=[server_type], address=[address]))
)
if not [s for s in zope_conf.sections
if ('server' in s.type)]:
zope_conf.sections.append(
- ZConfigSection('server',
- data=dict(type=[server_type],
- address=['8080'],
- ),
- )
+ ZConfig.schemaless.Section(
+ 'server',
+ data=dict(type=[server_type], address=['8080']))
)
if not [s for s in zope_conf.sections if s.type == 'zodb']:
@@ -246,7 +243,8 @@
zdaemon_conf = options.get('zdaemon.conf', '')+'\n'
- zdaemon_conf = ZConfigParse(cStringIO.StringIO(zdaemon_conf))
+ zdaemon_conf = ZConfig.schemaless.loadConfigFile(
+ cStringIO.StringIO(zdaemon_conf))
defaults = {
'program': "%s -C %s" % (os.path.join(app_loc, 'runzope'),
@@ -264,11 +262,11 @@
if runner:
runner = runner[0]
else:
- runner = ZConfigSection('runner')
+ runner = ZConfig.schemaless.Section('runner')
zdaemon_conf.sections.insert(0, runner)
for name, value in defaults.items():
if name not in runner:
- runner.addValue(name, value)
+ runner[name] = [value]
if not [s for s in zdaemon_conf.sections
if s.type == 'eventlog']:
@@ -314,31 +312,28 @@
update = install
def access_log(path):
- return ZConfigSection(
+ return ZConfig.schemaless.Section(
'accesslog', '',
- sections=[ZConfigSection('logfile', '', dict(path=[path]))]
+ sections=[ZConfig.schemaless.Section('logfile', '', dict(path=[path]))]
)
def event_log(path, *data):
- return ZConfigSection(
+ return ZConfig.schemaless.Section(
'eventlog', '', None,
- [ZConfigSection('logfile', '',
- dict(path=[path],
- formatter=['zope.exceptions.log.Formatter'],
- )
- )
- ],
- )
+ [ZConfig.schemaless.Section(
+ 'logfile',
+ '',
+ dict(path=[path], formatter=['zope.exceptions.log.Formatter'])),
+ ])
def event_log2(path, *data):
- return ZConfigSection(
+ return ZConfig.schemaless.Section(
'eventlog', '', None,
- [ZConfigSection('logfile', '',
- dict(path=[path],
- )
- )
- ],
- )
+ [ZConfig.schemaless.Section(
+ 'logfile',
+ '',
+ dict(path=[path])),
+ ])
server_template = """
@@ -365,76 +360,7 @@
</eventlog>
"""
-class ZConfigResource:
- def __init__(self, file, url=''):
- self.file, self.url = file, url
-
-class ZConfigSection(dict):
-
- def __init__(self, type='', name='', data=None, sections=None):
- dict.__init__(self)
- if data:
- self.update(data)
- self.sections = sections or []
- self.type, self.name = type, name
-
- def addValue(self, key, value, *args):
- if key in self:
- self[key].append(value)
- else:
- self[key] = [value]
-
- def __str__(self, pre=''):
- result = []
- if self.type:
- if self.name:
- result = ['%s<%s %s>' % (pre, self.type, self.name)]
- else:
- result = ['%s<%s>' % (pre, self.type)]
- pre += ' '
-
- 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('')
-
- for section in self.sections:
- result.append(section.__str__(pre))
-
- if self.type:
- result.append('%s</%s>' % (pre[:-2], self.type))
- result.append('')
-
- return '\n'.join(result).rstrip()+'\n'
-
-class ZConfigContext:
-
- def __init__(self):
- self.top = ZConfigSection()
- self.sections = []
-
- def startSection(self, container, type, name):
- newsec = ZConfigSection(type, name)
- container.sections.append(newsec)
- return newsec
-
- def endSection(self, container, type, name, newsect):
- pass
-
- def importSchemaComponent(self, pkgname):
- pass
-
- def includeConfiguration(self, section, newurl, defines):
- raise NotImplementedError('includes are not supported')
-
-def ZConfigParse(file):
- c = ZConfigContext()
- ZConfig.cfgparser.ZConfigParser(ZConfigResource(file), c).parse(c.top)
- return c.top
-
ftesting_base = """
<configure
xmlns="http://namespaces.zope.org/zope"
More information about the Checkins
mailing list