[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/server/ Added
multi-database support.
Jim Fulton
jim at zope.com
Sat Jun 4 08:19:43 EDT 2005
Log message for revision 30641:
Added multi-database support.
Changed:
U Zope3/trunk/src/zope/app/server/main.py
U Zope3/trunk/src/zope/app/server/schema.xml
U Zope3/trunk/src/zope/app/server/tests/test_server.py
-=-
Modified: Zope3/trunk/src/zope/app/server/main.py
===================================================================
--- Zope3/trunk/src/zope/app/server/main.py 2005-06-04 10:32:45 UTC (rev 30640)
+++ Zope3/trunk/src/zope/app/server/main.py 2005-06-04 12:19:42 UTC (rev 30641)
@@ -61,12 +61,64 @@
sys.exit(0)
+def multi_database(database_factories):
+ """Set up a multi-database from an iterable of database factories
+
+ Return a sequence of databases, and a mapping of from database name to
+ database.
+
+ >>> class DB:
+ ... def __init__(self, number):
+ ... self.number = number
+ ... def __repr__(self):
+ ... return "DB(%s)" % self.number
+
+ >>> class Factory:
+ ... def __init__(self, name, number):
+ ... self.name = name
+ ... self.number = number
+ ... def open(self):
+ ... return DB(self.number)
+
+ >>> s, m = multi_database(
+ ... [Factory(None, 3), Factory('y', 2), Factory('x', 1)])
+
+ >>> list(s)
+ [DB(3), DB(2), DB(1)]
+
+ >>> [d.database_name for d in s]
+ ['', 'y', 'x']
+
+ >>> [d.databases is m for d in s]
+ [True, True, True]
+
+ >>> m = m.items()
+ >>> m.sort()
+ >>> m
+ [('', DB(3)), ('x', DB(1)), ('y', DB(2))]
+ """
+
+ databases = {}
+ result = []
+ for factory in database_factories:
+ name = factory.name or ''
+ if name in databases:
+ raise ValueError("Duplicate database name: %r" % name)
+ db = factory.open()
+ db.databases = databases
+ db.database_name = name
+ databases[name] = db
+ result.append(db)
+
+ return result, databases
+
+
def debug(args=None):
options = load_options(args)
zope.app.appsetup.config(options.site_definition)
- db = options.database.open()
+ db = multi_database(options.databases)[0][0]
notify(zope.app.appsetup.interfaces.DatabaseOpened(db))
return db
@@ -100,7 +152,7 @@
zope.app.appsetup.config(options.site_definition)
- db = options.database.open()
+ db = multi_database(options.databases)[0][0]
notify(zope.app.appsetup.interfaces.DatabaseOpened(db))
Modified: Zope3/trunk/src/zope/app/server/schema.xml
===================================================================
--- Zope3/trunk/src/zope/app/server/schema.xml 2005-06-04 10:32:45 UTC (rev 30640)
+++ Zope3/trunk/src/zope/app/server/schema.xml 2005-06-04 12:19:42 UTC (rev 30641)
@@ -19,12 +19,21 @@
<key name="verbose" datatype="boolean" />
</sectiontype>
- <section type="ZODB.database" name="*" required="yes"
- attribute="database">
+ <multisection type="ZODB.database" name="*" required="yes"
+ attribute="databases">
<description>
- The main application database that should be used.
+
+ Application database.
+
+ At least one database must be specified. The first will be used
+ as the main database. At most one of the databases can be unnamed.
+
+ All of the databases specified will be part of a multi-database.
+ See the ZODB documentation of multi-databases for details of how
+ this is useful.
+
</description>
- </section>
+ </multisection>
<section type="eventlog" attribute="eventlog" name="*" required="yes">
<description>
Modified: Zope3/trunk/src/zope/app/server/tests/test_server.py
===================================================================
--- Zope3/trunk/src/zope/app/server/tests/test_server.py 2005-06-04 10:32:45 UTC (rev 30640)
+++ Zope3/trunk/src/zope/app/server/tests/test_server.py 2005-06-04 12:19:42 UTC (rev 30641)
@@ -85,7 +85,10 @@
def test_suite():
- return doctest.DocTestSuite()
+ return unittest.TestSuite((
+ doctest.DocTestSuite(),
+ doctest.DocTestSuite('zope.app.server.main'),
+ ))
if __name__ == '__main__':
More information about the Zope3-Checkins
mailing list