Commit e23b02fd authored by Fred Drake's avatar Fred Drake

Reorganize the schema support so we can actually use the revised component

import to load the database and storage types.
parent da830416
<component prefix="ZODB.config">
<!-- XXX needs descriptions for everything -->
<abstracttype name="storage"/>
<abstracttype name="database"/>
<sectiontype name="filestorage" datatype=".FileStorage"
implements="storage">
<key name="path" required="yes"/>
<key name="create" datatype="boolean" default="true"/>
<key name="read-only" datatype="boolean" default="false"/>
<key name="stop"/>
<key name="quota" datatype="integer"/>
</sectiontype>
<sectiontype name="mappingstorage" datatype=".MappingStorage"
implements="storage">
<key name="name" default="Mapping Storage"/>
</sectiontype>
<sectiontype name="fullstorage" datatype=".BDBStorage"
implements="storage">
<key name="name" required="yes" />
<key name="interval" datatype="time-interval" default="2m" />
<key name="kbyte" datatype="integer" default="0" />
<key name="min" datatype="integer" default="0" />
<key name="logdir" />
<key name="cachesize" datatype="byte-size" default="128MB" />
<key name="frequency" datatype="time-interval" default="0" />
<key name="packtime" datatype="time-interval" default="4h" />
<key name="classicpack" datatype="integer" default="0" />
<key name="read-only" datatype="boolean" default="off"/>
</sectiontype>
<!-- XXX Fred promises to make it so minimal storage is just an
extension of fullstorage -->
<sectiontype name="minimalstorage" datatype=".BDBStorage"
implements="storage">
<key name="name" required="yes" />
<key name="interval" datatype="time-interval" default="2m" />
<key name="kbyte" datatype="integer" default="0" />
<key name="min" datatype="integer" default="0" />
<key name="logdir" />
<key name="cachesize" datatype="byte-size" default="128MB" />
<key name="frequency" datatype="time-interval" default="0" />
<key name="packtime" datatype="time-interval" default="4h" />
<key name="classicpack" datatype="integer" default="0" />
<key name="read-only" datatype="boolean" default="off"/>
</sectiontype>
<sectiontype name="zeoclient" datatype=".ZEOClient"
implements="storage">
<multikey name="server" datatype="socket-address" required="yes"/>
<key name="storage" default="1"/>
<key name="cache-size" datatype="integer" default="20000000"/>
<key name="name" default=""/>
<key name="client"/>
<key name="var"/>
<key name="min-disconnect-poll" datatype="integer" default="5"/>
<key name="max-disconnect-poll" datatype="integer" default="300"/>
<key name="wait" datatype="boolean" default="on"/>
<key name="read-only" datatype="boolean" default="off"/>
<key name="read-only-fallback" datatype="boolean" default="off"/>
</sectiontype>
<sectiontype name="demostorage" datatype=".DemoStorage"
implements="storage">
<key name="name" default="Demo Storage"/>
<section type="storage" name="*" attribute="base"/>
<key name="quota" datatype="integer"/>
</sectiontype>
<sectiontype name="zodb"
implements="database">
<section type="storage" name="*" attribute="storage"/>
<key name="cache-size" datatype="integer" default="5000"/>
<key name="pool-size" datatype="integer" default="7"/>
<key name="version-pool-size" datatype="integer" default="3"/>
<key name="version-cache-size" datatype="integer" default="100"/>
</sectiontype>
</component>
......@@ -13,7 +13,7 @@
##############################################################################
"""Open database and storage from a configuration.
$Id: config.py,v 1.6 2003/01/09 18:26:53 fdrake Exp $"""
$Id: config.py,v 1.7 2003/01/10 06:44:50 fdrake Exp $"""
import os
import StringIO
......@@ -36,18 +36,18 @@ def databaseFromString(s):
def databaseFromFile(f):
config, handle = ZConfig.loadConfigFile(getSchema(), f)
return databaseFromConfig(config)
return databaseFromConfig(config.database)
def databaseFromURL(url):
config, handler = ZConfig.loadConfig(getSchema(), url)
return databaseFromConfig(config)
def databaseFromConfig(config):
return ZODB.DB(config.storage.open(),
pool_size=config.pool_size,
cache_size=config.cache_size,
version_pool_size=config.version_pool_size,
version_cache_size=config.version_cache_size)
return databaseFromConfig(config.database)
def databaseFromConfig(section):
return ZODB.DB(section.storage.open(),
pool_size=section.pool_size,
cache_size=section.cache_size,
version_pool_size=section.version_pool_size,
version_cache_size=section.version_cache_size)
class StorageConfig:
......
<schema type="database" prefix="ZODB.config">
<schema prefix="ZODB.config">
<abstracttype name="storage"/>
<import package="ZODB"/>
<sectiontype name="filestorage" datatype=".FileStorage"
implements="storage">
<key name="path" required="yes"/>
<key name="create" datatype="boolean" default="true"/>
<key name="read_only" datatype="boolean" default="false"/>
<key name="stop"/>
<key name="quota" datatype="integer"/>
</sectiontype>
<sectiontype name="mappingstorage" datatype=".MappingStorage"
implements="storage">
<key name="name" default="Mapping Storage"/>
</sectiontype>
<sectiontype name="fullstorage" datatype=".BDBStorage"
implements="storage">
<key name="name" required="yes" />
<key name="interval" datatype="time-interval" default="2m" />
<key name="kbyte" datatype="integer" default="0" />
<key name="min" datatype="integer" default="0" />
<key name="logdir" />
<key name="cachesize" datatype="byte-size" default="128MB" />
<key name="frequency" datatype="time-interval" default="0" />
<key name="packtime" datatype="time-interval" default="4h" />
<key name="classicpack" datatype="integer" default="0" />
<key name="read_only" datatype="boolean" default="off"/>
</sectiontype>
<!-- XXX Fred promises to make it so minimal storage is just an
extension of fullstorage -->
<sectiontype name="minimalstorage" datatype=".BDBStorage"
implements="storage">
<key name="name" required="yes" />
<key name="interval" datatype="time-interval" default="2m" />
<key name="kbyte" datatype="integer" default="0" />
<key name="min" datatype="integer" default="0" />
<key name="logdir" />
<key name="cachesize" datatype="byte-size" default="128MB" />
<key name="frequency" datatype="time-interval" default="0" />
<key name="packtime" datatype="time-interval" default="4h" />
<key name="classicpack" datatype="integer" default="0" />
<key name="read_only" datatype="boolean" default="off"/>
</sectiontype>
<sectiontype name="zeoclient" datatype=".ZEOClient"
implements="storage">
<multikey name="server" datatype="socket-address" required="yes"/>
<key name="storage" default="1"/>
<key name="cache_size" datatype="integer" default="20000000"/>
<key name="name" default=""/>
<key name="client"/>
<key name="var"/>
<key name="min_disconnect_poll" datatype="integer" default="5"/>
<key name="max_disconnect_poll" datatype="integer" default="300"/>
<key name="wait" datatype="boolean" default="on"/>
<key name="read_only" datatype="boolean" default="off"/>
<key name="read_only_fallback" datatype="boolean" default="off"/>
</sectiontype>
<sectiontype name="demostorage" datatype=".DemoStorage"
implements="storage">
<key name="name" default="Demo Storage"/>
<section type="storage" name="*" attribute="base"/>
<key name="quota" datatype="integer"/>
</sectiontype>
<!-- the rest is the actual configuration for the database -->
<section type="storage" name="*" attribute="storage"/>
<key name="cache_size" datatype="integer" default="5000"/>
<key name="pool_size" datatype="integer" default="7"/>
<key name="version_pool_size" datatype="integer" default="3"/>
<key name="version_cache_size" datatype="integer" default="100"/>
<section type="database" name="*" attribute="database"/>
</schema>
......@@ -39,49 +39,66 @@ class ConfigTestBase(unittest.TestCase):
class ZODBConfigTest(ConfigTestBase):
def test_map_config1(self):
self._test("<mappingstorage/>")
self._test(
"""
<zodb>
<mappingstorage/>
</zodb>
""")
def test_map_config2(self):
self._test(
"""<mappingstorage/>
cache_size 1000
"""
<zodb>
<mappingstorage/>
cache-size 1000
</zodb>
""")
def test_file_config1(self):
path = tempfile.mktemp()
self._test(
"""<filestorage>
path %s
</filestorage>
"""
<zodb>
<filestorage>
path %s
</filestorage>
</zodb>
""" % path)
os.unlink(path)
def test_file_config2(self):
path = tempfile.mktemp()
cfg = """
<filestorage>
<zodb>
<filestorage>
path %s
create false
read_only true
</filestorage>
read-only true
</filestorage>
</zodb>
""" % path
self.assertRaises(ReadOnlyError, self._test, cfg)
def test_zeo_config(self):
cfg = """
<zeoclient>
<zodb>
<zeoclient>
server /no/path/var/test/foo
wait false
</zeoclient>
</zeoclient>
</zodb>
"""
self.assertRaises(ClientDisconnected, self._test, cfg)
def test_demo_config(self):
cfg = """
<demostorage>
<zodb unused-name>
<demostorage>
name foo
<mappingstorage/>
</demostorage>
</demostorage>
</zodb>
"""
self._test(cfg)
......@@ -99,17 +116,21 @@ class BDBConfigTest(ConfigTestBase):
def test_bdbfull_simple(self):
cfg = """
<fullstorage>
<zodb>
<fullstorage>
name %s
</fullstorage>
</fullstorage>
</zodb>
""" % self._path
self._test(cfg)
def test_bdbminimal_simple(self):
cfg = """
<minimalstorage>
<zodb>
<minimalstorage>
name %s
</minimalstorage>
</minimalstorage>
</zodb>
""" % self._path
self._test(cfg)
......
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