[Zope-Checkins] CVS: ZODB3/ZODB - config.py:1.2 config.xml:1.2
Fred L. Drake, Jr.
fred@zope.com
Fri, 3 Jan 2003 16:19:38 -0500
Update of /cvs-repository/ZODB3/ZODB
In directory cvs.zope.org:/tmp/cvs-serv13656/ZODB
Added Files:
config.py config.xml
Log Message:
Merge ZConfig schema support integration from the zconfig-schema-devel-branch.
=== ZODB3/ZODB/config.py 1.1 => 1.2 ===
--- /dev/null Fri Jan 3 16:19:38 2003
+++ ZODB3/ZODB/config.py Fri Jan 3 16:19:06 2003
@@ -0,0 +1,112 @@
+##############################################################################
+#
+# Copyright (c) 2001, 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
+#
+##############################################################################
+"""Open database and storage from a configuration.
+
+$Id$"""
+
+import os
+import StringIO
+
+import ZConfig
+
+import ZODB
+
+schema_path = os.path.join(ZODB.__path__[0], "config.xml")
+_schema = None
+
+def getSchema():
+ global _schema
+ if _schema is None:
+ _schema = ZConfig.loadSchema(schema_path)
+ return _schema
+
+def databaseFromString(s):
+ return databaseFromFile(StringIO.StringIO(s))
+
+def databaseFromFile(f):
+ config, handle = ZConfig.loadConfigFile(getSchema(), f)
+ return databaseFromConfig(config)
+
+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)
+
+class StorageConfig:
+
+ def __init__(self, config):
+ self.config = config
+
+ def open(self):
+ raise NotImplementedError
+
+class MappingStorage(StorageConfig):
+
+ def open(self):
+ from ZODB.MappingStorage import MappingStorage
+ return MappingStorage(self.config.name)
+
+class FileStorage(StorageConfig):
+
+ def open(self):
+ from ZODB.FileStorage import FileStorage
+ return FileStorage(self.config.path,
+ create=self.config.create,
+ read_only=self.config.read_only,
+ stop=self.config.stop,
+ quota=self.config.quota)
+
+class ZEOClient(StorageConfig):
+
+ def open(self):
+ from ZEO.ClientStorage import ClientStorage
+ # config.server is a multikey of socket-address values
+ # where the value is a socket family, address tuple.
+ L = [addr for family, addr in self.config.server]
+ return ClientStorage(
+ L,
+ storage=self.config.storage,
+ cache_size=self.config.cache_size,
+ name=self.config.name,
+ client=self.config.client,
+ var=self.config.var,
+ min_disconnect_poll=self.config.min_disconnect_poll,
+ max_disconnect_poll=self.config.max_disconnect_poll,
+ wait=self.config.wait,
+ read_only=self.config.read_only,
+ read_only_fallback=self.config.read_only_fallback)
+
+class BDBStorage(StorageConfig):
+
+ def open(self):
+ from BDBStorage.BerkeleyBase import BerkeleyConfig
+ from BDBStorage.BDBFullStorage import BDBFullStorage
+ from BDBStorage.BDBMinimalStorage import BDBMinimalStorage
+ # Figure out which class we want
+ sectiontype = self.config.getSectionType()
+ storageclass = {'fullstorage': BDBFullStorage,
+ 'minimalstorage': BDBMinimalStorage,
+ }[sectiontype]
+ bconf = BerkeleyConfig()
+ for name in dir(BerkeleyConfig):
+ if name.startswith('_'):
+ continue
+ setattr(bconf, name, getattr(self.config, name))
+ return storageclass(self.config.name, config=bconf)
=== ZODB3/ZODB/config.xml 1.1 => 1.2 ===
--- /dev/null Fri Jan 3 16:19:38 2003
+++ ZODB3/ZODB/config.xml Fri Jan 3 16:19:06 2003
@@ -0,0 +1,75 @@
+<schema type="database">
+
+ <sectiongroup type="storage">
+
+ <sectiontype type="filestorage" datatype="ZODB.config.FileStorage">
+ <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 type="mappingstorage" datatype="ZODB.config.MappingStorage">
+ <key name="name" default="Mapping Storage"/>
+ </sectiontype>
+
+ <sectiontype type="fullstorage" datatype="ZODB.config.BDBStorage">
+ <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 type="minimalstorage" datatype="ZODB.config.BDBStorage">
+ <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 type="zeoclient" datatype="ZODB.config.ZEOClient">
+ <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 type="demostorage">
+ <!--datatype="ZODB.config.DemoStorage"-->
+ <key name="name" default="Demo Storage"/>
+ <section type="storage" name="*" attribute="base"/>
+ <key name="quota" datatype="integer"/>
+ </sectiontype>
+
+ </sectiongroup>
+
+ <!-- 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"/>
+
+</schema>