[Zodb-checkins] CVS: ZODB3/ZODB - config.xml:1.1.4.1 config.py:1.1.4.1
Jeremy Hylton
jeremy@zope.com
Thu, 2 Jan 2003 17:40:14 -0500
Update of /cvs-repository/ZODB3/ZODB
In directory cvs.zope.org:/tmp/cvs-serv29246
Added Files:
Tag: zconfig-schema-devel-branch
config.xml config.py
Log Message:
Some preliminary code to create databases from config files
(added on the right branch this time)
=== Added File ZODB3/ZODB/config.xml ===
<schema type="database">
<sectiongroup type="storage">
<sectiontype type="filestorage">
<key name="path" datatype="str" required="yes"/>
<key name="create" datatype="boolean" default="true"/>
<key name="read_only" datatype="boolean" default="false"/>
<key name="stop" datatype="str"/>
<key name="quota" datatype="integer"/>
</sectiontype>
<sectiontype type="mappingstorage">
<key name="name" datatype="str" default="Mapping Storage"/>
</sectiontype>
<sectiontype type="zeoclient">
<key name="addr" datatype="str" required="yes"/>
<key name="storage" datatype="str" default="1"/>
<key name="cache_size" datatype="integer" default="20000000"/>
<key name="name" datatype="str" default=""/>
<key name="client" datatype="str"/>
<key name="var" datatype="str"/>
<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>
</sectiongroup>
<section type="storage" name="boo" 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>
=== Added File ZODB3/ZODB/config.py ===
##############################################################################
#
# 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: config.py,v 1.1.4.1 2003/01/02 22:40:10 jeremy Exp $"""
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(storageFromConfig(config.storage),
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 StorageOpener:
def fromConfig(self, config):
meth = getattr(self, config.__type__.name)
return meth(config)
def mappingstorage(self, config):
from ZODB.MappingStorage import MappingStorage
return MappingStorage(config.name)
def filestorage(self, config):
from ZODB.FileStorage import FileStorage
return FileStorage(config.path,
create=config.create,
read_only=config.read_only,
stop=config.stop,
quota=config.quota)
storageFromConfig = StorageOpener().fromConfig