Commit be6fc1f9 authored by Jeremy Hylton's avatar Jeremy Hylton

Remove old configuration approach in favor of current ZConfig schema.

Update the ZEO tests to use the new configuration language.
Remove files from old configuration approach.
parent 1d2b2e12
......@@ -26,32 +26,25 @@ from ZEO.tests import ConnectionTests
class FileStorageConfig:
def getConfig(self, path, create, read_only):
return """\
<Storage>
type FileStorage
file_name %s
<filestorage>
path %s
create %s
read_only %s
</Storage>""" % (path,
read-only %s
</filestorage>""" % (path,
create and 'yes' or 'no',
read_only and 'yes' or 'no')
class BerkeleyStorageConfig:
def getConfig(self, path, create, read_only):
return """\
<Storage>
type BDBFullStorage
<fullstorage>
name %s
read_only %s
</Storage>""" % (path, read_only)
read-only %s
</fullstorage>""" % (path, read_only)
class MappingStorageConfig:
def getConfig(self, path, create, read_only):
return """\
<Storage>
type MappingStorage
name %s
</Storage>""" % path
return """<mappingstorage/>"""
class FileStorageConnectionTests(
......
......@@ -150,20 +150,11 @@ class FileStorageTests(GenericTests):
def getConfig(self):
filename = self.__fs_base = tempfile.mktemp()
return """\
<Storage>
type FileStorage
file_name %s
create yes
</Storage>
<filestorage>
path %s
</filestorage>
""" % filename
def checkPackVersionsInPast(self):
# FileStorage can't cope with backpointers to objects
# created in versions. Should fix if we can figure out actually how
# to fix it.
pass
class BDBTests(FileStorageTests):
"""ZEO backed by a Berkeley full storage."""
level = 2
......@@ -171,23 +162,16 @@ class BDBTests(FileStorageTests):
def getConfig(self):
self._envdir = tempfile.mktemp()
return """\
<Storage>
type BDBFullStorage
<fullstorage>
name %s
</Storage>
</fullstorage>
""" % self._envdir
class MappingStorageTests(FileStorageTests):
"""ZEO backed by a Mapping storage."""
def getConfig(self):
self._envdir = tempfile.mktemp()
return """\
<Storage>
type MappingStorage
name %s
</Storage>
""" % self._envdir
return """<mappingstorage/>"""
# Tests which MappingStorage can't possibly pass, because it doesn't
# support versions or undo.
......
......@@ -26,15 +26,8 @@ import ThreadedAsync.LoopCallback
import ZConfig.Context
import zLOG
from ZODB import StorageConfig
import ZEO.StorageServer
def load_storage(fp):
context = ZConfig.Context.Context()
rootconf = context.loadFile(fp)
storageconf = rootconf.getSection('Storage')
return StorageConfig.createStorage(storageconf)
from ZODB.config import storageFromURL
def cleanup(storage):
......@@ -166,9 +159,7 @@ def main():
monitor_address = '', int(arg)
# Open the config file and let ZConfig parse the data there. Then remove
# the config file, otherwise we'll leave turds.
fp = open(configfile, 'r')
storage = load_storage(fp)
fp.close()
storage = storageFromURL(configfile)
os.remove(configfile)
# The rest of the args are hostname, portnum
zeo_port = int(args[0])
......
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Higher-level support for configuring storages.
Storages are configured a la DBTab.
A storage section has the form
<Storage Name (dependent)>
# For example
type FileStorage
file_name var/Data.fs
read_only 1
</Storage>
where Name and (dependent) are optional. Once you have retrieved the
section object (probably with getSection("Storage", name), the
function creatStorage() in this module will create the storage object
for you.
"""
from StorageTypes import storage_types
def createStorage(section):
"""Create a storage specified by a configuration section."""
klass, args = getStorageInfo(section)
return klass(**args)
def getStorageInfo(section):
"""Extract a storage description from a configuration section.
Return a tuple (klass, args) where klass is the storage class and
args is a dictionary of keyword arguments. To create the storage,
call klass(**args).
Adapted from DatabaseFactory.setStorageParams() in DBTab.py.
"""
type = section.get("type")
if not type:
raise RuntimeError, "A storage type is required"
module = None
pos = type.rfind(".")
if pos >= 0:
# Specified the module
module, type = type[:pos], type[pos+1:]
converter = None
if not module:
# Use a default module and argument converter.
info = storage_types.get(type)
if not info:
raise RuntimeError, "Unknown storage type: %s" % type
module, converter = info
m = __import__(module, {}, {}, [type])
klass = getattr(m, type)
args = {}
if section.name:
args["name"] = section.name
for key in section.keys():
if key.lower() != "type":
args[key] = section.get(key)
if converter is not None:
args = converter(**args)
return (klass, args)
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""Default storage types.
Adapted from DBTab/StorageTypes.py.
"""
import re
from ZConfig.Config import asBoolean
def convertFileStorageArgs(quota=None, stop=None, **kw):
if kw.has_key('name'):
# FileStorage doesn't accept a 'name' arg
del kw['name']
if quota is not None:
kw['quota'] = long(quota) or None
if stop is not None:
stop = long(stop)
if not stop:
stop = None
else:
from ZODB.utils import p64
stop = p64(stop)
kw['stop'] = stop
# Boolean args
for name in (
'create', 'read_only'
):
if kw.has_key(name):
kw[name] = asBoolean(kw[name])
return kw
# Match URLs of the form 'zeo://zope.example.com:1234'
zeo_url_re = re.compile('zeo:/*(?P<host>[A-Za-z0-9\.-]+):(?P<port>[0-9]+)')
def convertAddresses(s):
# Allow multiple addresses using semicolons as a split character.
res = []
for a in s.split(';'):
a = a.strip()
if a:
mo = zeo_url_re.match(a)
if mo is not None:
# ZEO URL
host, port = mo.groups()
res.append((host, int(port)))
else:
# Socket file
res.append(a)
return res
def convertClientStorageArgs(addr=None, **kw):
if addr is None:
raise RuntimeError, 'An addr parameter is required for ClientStorage.'
kw['addr'] = convertAddresses(addr)
# Integer args
for name in (
'cache_size', 'min_disconnect_poll', 'max_disconnect_poll',
):
if kw.has_key(name):
kw[name] = int(kw[name])
# Boolean args
for name in (
'wait', 'read_only', 'read_only_fallback',
):
if kw.has_key(name):
kw[name] = asBoolean(kw[name])
# The 'client' parameter must be None to be false. Yuck.
if kw.has_key('client') and not kw['client']:
kw['client'] = None
return kw
def convertBDBStorageArgs(**kw):
from BDBStorage.BerkeleyBase import BerkeleyConfig
config = BerkeleyConfig()
for name in dir(BerkeleyConfig):
if name.startswith('_'):
continue
val = kw.get(name)
if val is not None:
if name != 'logdir':
val = int(val)
setattr(config, name, val)
del kw[name]
# XXX: Nobody ever passes in env
assert not kw.has_key('env')
kw['config'] = config
return kw
storage_types = {
'FileStorage': ('ZODB.FileStorage', convertFileStorageArgs),
'DemoStorage': ('ZODB.DemoStorage', None),
'MappingStorage': ('ZODB.MappingStorage', None),
'TemporaryStorage': ('Products.TemporaryFolder.TemporaryStorage', None),
'ClientStorage': ('ZEO.ClientStorage', convertClientStorageArgs),
'BDBFullStorage': ('BDBStorage.BDBFullStorage', convertBDBStorageArgs),
'BDBMinimalStorage': ('BDBStorage.BDBMinimalStorage',
convertBDBStorageArgs),
}
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