Commit 2c936305 authored by Chris McDonough's avatar Chris McDonough

Wire up ZODB database configuration via configuration file.

parent ad9aed9f
...@@ -48,9 +48,11 @@ def startup(): ...@@ -48,9 +48,11 @@ def startup():
# Try to use custom storage # Try to use custom storage
m=imp.find_module('custom_zodb',[getConfiguration().instancehome]) m=imp.find_module('custom_zodb',[getConfiguration().instancehome])
except: except:
import ZODB.FileStorage # if there is no custom_zodb, use the config file specified databases
storage = ZODB.FileStorage.FileStorage(Globals.BobobaseName) config = getConfiguration()
DB = ZODB.DB(storage) name = config.db_mount_tab['/']
DB = config.db_name_tab[name].open()
Globals.BobobaseName = name
else: else:
m=imp.load_module('Zope.custom_zodb', m[0], m[1], m[2]) m=imp.load_module('Zope.custom_zodb', m[0], m[1], m[2])
if hasattr(m,'DB'): if hasattr(m,'DB'):
......
...@@ -68,12 +68,22 @@ def dns_resolver(hostname): ...@@ -68,12 +68,22 @@ def dns_resolver(hostname):
from ZServer.medusa import resolver from ZServer.medusa import resolver
return resolver.caching_resolver(hostname) return resolver.caching_resolver(hostname)
# mount-point definition
def mount_point(value):
if not value:
raise ValueError, 'mount-point must not be empty'
if not value.startswith('/'):
raise ValueError, ("mount-point '%s' is invalid: mount points must "
"begin with a slash" % value)
return value
# Datatype for the root configuration object # Datatype for the root configuration object
# (adds the softwarehome and zopehome fields; default values for some # (adds the softwarehome and zopehome fields; default values for some
# computed paths) # computed paths)
def root_config(section): def root_config(section):
from ZConfig import ConfigurationError
here = os.path.dirname(os.path.abspath(__file__)) here = os.path.dirname(os.path.abspath(__file__))
swhome = os.path.dirname(os.path.dirname(here)) swhome = os.path.dirname(os.path.dirname(here))
section.softwarehome = swhome section.softwarehome = swhome
...@@ -88,4 +98,46 @@ def root_config(section): ...@@ -88,4 +98,46 @@ def root_config(section):
section.pid_filename = os.path.join(section.clienthome, 'Z2.pid') section.pid_filename = os.path.join(section.clienthome, 'Z2.pid')
if section.lock_filename is None: if section.lock_filename is None:
section.lock_filename = os.path.join(section.clienthome, 'Z2.lock') section.lock_filename = os.path.join(section.clienthome, 'Z2.lock')
if not section.databases:
# default to a filestorage named 'Data.fs' in clienthome
from ZODB.config import FileStorage
from ZODB.config import ZODBDatabase
class dummy:
def __init__(self, name):
self.name = name
def getSectionName(self):
return self.name
path = os.path.join(section.clienthome, 'Data.fs')
ns = dummy('default filestorage at %s' % path)
ns.path = path
ns.create = None
ns.read_only = None
ns.quota = None
storage = FileStorage(ns)
ns2 = dummy('default zodb database using filestorage at %s' % path)
ns2.storage = storage
ns2.cache_size = 5000
ns2.pool_size = 7
ns2.version_pool_size=3
ns2.version_cache_size = 100
ns2.mount_points = ['/']
section.databases = [ZODBDatabase(ns2)]
section.db_mount_tab = db_mount_tab = {}
section.db_name_tab = db_name_tab = {}
dup_err = ('Invalid configuration: ZODB databases named "%s" and "%s" are '
'both configured to use the same mount point, named "%s"')
for database in section.databases:
mount_points = database.config.mount_points
name = database.config.getSectionName()
db_name_tab[name] = database
for point in mount_points:
if db_mount_tab.has_key(point):
raise ConfigurationError(dup_err % (db_mount_tab[point], name,
point))
db_mount_tab[point] = name
return section return section
...@@ -121,6 +121,18 @@ ...@@ -121,6 +121,18 @@
</sectiontype> </sectiontype>
<sectiontype name="zodb_db" datatype="ZODB.config.ZODBDatabase"
implements="ZODB.database" extends="zodb">
<description>
We need to specialize the database configuration section for Zope
only by including a (required) mount-point argument, which
is a string. A Zope ZODB database can have multiple mount points,
so this is a multikey.
</description>
<multikey name="mount-point" required="yes" attribute="mount_points"
datatype=".mount_point"/>
</sectiontype>
<!-- end of type definitions --> <!-- end of type definitions -->
<!-- schema begins --> <!-- schema begins -->
...@@ -261,7 +273,17 @@ ...@@ -261,7 +273,17 @@
</description> </description>
</key> </key>
<multisection type="ZODB.database" name="*" attribute="databases"/> <multisection type="ZODB.database" name="+" attribute="databases">
<description>
Zope ZODB databases must have a name, and they are required to be
referenced via the "zodb_db" database type because it is
the only kind of database definition that implements
the required mount-point argument. There is another
database sectiontype named "zodb", but it cannot be used
in the context of a proper Zope configuration (due to
lack of a mount-point).
</description>
</multisection>
<section type="zoperunner" name="*" attribute="runner"/> <section type="zoperunner" name="*" attribute="runner"/>
......
...@@ -705,11 +705,11 @@ products $INSTANCE/Products ...@@ -705,11 +705,11 @@ products $INSTANCE/Products
# port-base 1000 # port-base 1000
# Database section # Database (zodb_db) section
# #
# Description: # Description:
# A database section allows the definition of custom database and # A database section allows the definition of custom database and
# storage types. The standard # storage types.
# #
# Influences: Zope configuration # Influences: Zope configuration
# #
...@@ -719,12 +719,13 @@ products $INSTANCE/Products ...@@ -719,12 +719,13 @@ products $INSTANCE/Products
# #
# Example: # Example:
# #
# <zodb> # <zodb_db>
# <filestorage> # <filestorage>
# path $INSTANCE/var/Data.fs # path $INSTANCE/var/Data.fs
# </filestorage> # </filestorage>
# mount-point /
# cache-size 5000 # cache-size 5000
# pool-size 7 # pool-size 7
# version-pool-size 3 # version-pool-size 3
# version-cache-size 100 # version-cache-size 100
# </zodb> # </zodb_db>
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