[Zope3-checkins] SVN: Zope3/branches/srichter-twisted-integration2/src/zope/app/ Moved multi_databases method to appsetup.

Stephan Richter srichter at cosmos.phy.tufts.edu
Thu Sep 8 23:24:35 EDT 2005


Log message for revision 38415:
  Moved multi_databases method to appsetup.
  

Changed:
  U   Zope3/branches/srichter-twisted-integration2/src/zope/app/appsetup/appsetup.py
  U   Zope3/branches/srichter-twisted-integration2/src/zope/app/appsetup/tests.py
  U   Zope3/branches/srichter-twisted-integration2/src/zope/app/server/main.py
  U   Zope3/branches/srichter-twisted-integration2/src/zope/app/server/schema.xml
  U   Zope3/branches/srichter-twisted-integration2/src/zope/app/server/tests/test_server.py
  U   Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/main.py

-=-
Modified: Zope3/branches/srichter-twisted-integration2/src/zope/app/appsetup/appsetup.py
===================================================================
--- Zope3/branches/srichter-twisted-integration2/src/zope/app/appsetup/appsetup.py	2005-09-09 02:42:44 UTC (rev 38414)
+++ Zope3/branches/srichter-twisted-integration2/src/zope/app/appsetup/appsetup.py	2005-09-09 03:24:35 UTC (rev 38415)
@@ -17,7 +17,9 @@
 """
 __docformat__ = 'restructuredtext'
 
+import ZODB.interfaces
 import zope.interface
+import zope.component
 import zope.app.component.hooks
 from zope.security.interfaces import IParticipation
 from zope.security.management import system_user
@@ -88,6 +90,71 @@
 
     return db
 
+
+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]
+
+    >>> items = m.items()
+    >>> items.sort()
+    >>> items
+    [('', DB(3)), ('x', DB(1)), ('y', DB(2))]
+
+    Each of the databases is registered as an IDatabase utility:
+
+    >>> from zope import component
+    >>> [(component.getUtility(ZODB.interfaces.IDatabase, name) is m[name])
+    ...  for name in m]
+    [True, True, True]
+
+    """
+    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
+        # Grrr bug in ZODB. Database doesn't declare that it implements
+        # IDatabase.
+        if not ZODB.interfaces.IDatabase.providedBy(db):
+            zope.interface.directlyProvides(db, ZODB.interfaces.IDatabase)
+        zope.component.provideUtility(db, ZODB.interfaces.IDatabase, name)
+        result.append(db)
+
+    return result, databases
+
+
 __config_context = None
 def getConfigContext():
     return __config_context

Modified: Zope3/branches/srichter-twisted-integration2/src/zope/app/appsetup/tests.py
===================================================================
--- Zope3/branches/srichter-twisted-integration2/src/zope/app/appsetup/tests.py	2005-09-09 02:42:44 UTC (rev 38414)
+++ Zope3/branches/srichter-twisted-integration2/src/zope/app/appsetup/tests.py	2005-09-09 03:24:35 UTC (rev 38415)
@@ -122,6 +122,9 @@
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(TestBootstrapSubscriber))
+    suite.addTest(doctest.DocTestSuite(
+        'zope.app.appsetup.appsetup',
+        setUp=placelesssetup.setUp, tearDown=placelesssetup.tearDown))
     suite.addTest(doctest.DocFileSuite(
         'bootstrap.txt',
         setUp=placelesssetup.setUp, tearDown=placelesssetup.tearDown,

Modified: Zope3/branches/srichter-twisted-integration2/src/zope/app/server/main.py
===================================================================
--- Zope3/branches/srichter-twisted-integration2/src/zope/app/server/main.py	2005-09-09 02:42:44 UTC (rev 38414)
+++ Zope3/branches/srichter-twisted-integration2/src/zope/app/server/main.py	2005-09-09 03:24:35 UTC (rev 38415)
@@ -22,12 +22,8 @@
 
 from zdaemon import zdoptions
 
-import ZODB.interfaces
-
 import ThreadedAsync
 
-from zope import component, interface
-
 import zope.app.appsetup
 import zope.app.appsetup.interfaces
 from zope.event import notify
@@ -65,70 +61,6 @@
     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]
-
-    >>> items = m.items()
-    >>> items.sort()
-    >>> items
-    [('', DB(3)), ('x', DB(1)), ('y', DB(2))]
-
-    Each of the databases is registered as an IDatabase utility:
-
-    >>> [(component.getUtility(ZODB.interfaces.IDatabase, name) is m[name])
-    ...  for name in m]
-    [True, True, True]
-    
-    """
-
-    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
-        # Grrr bug in ZODB. Database doesn't declare that it implements
-        # IDatabase.
-        if not ZODB.interfaces.IDatabase.providedBy(db):
-            interface.directlyProvides(db, ZODB.interfaces.IDatabase)
-        component.provideUtility(db, ZODB.interfaces.IDatabase, name)
-        result.append(db)
-
-    return result, databases
-        
-
 def debug(args=None):
     options = load_options(args)
 

Modified: Zope3/branches/srichter-twisted-integration2/src/zope/app/server/schema.xml
===================================================================
--- Zope3/branches/srichter-twisted-integration2/src/zope/app/server/schema.xml	2005-09-09 02:42:44 UTC (rev 38414)
+++ Zope3/branches/srichter-twisted-integration2/src/zope/app/server/schema.xml	2005-09-09 03:24:35 UTC (rev 38415)
@@ -1,6 +1,4 @@
 <schema extends="../appsetup/schema.xml">
-  <!-- Zope 3 Application Server Configuration Schema -->
-  <import package="zope.app.appsetup" file="app.xml" />
 
   <!-- logging configuration -->
   <import package="zope.app.server" file="accesslog.xml" />

Modified: Zope3/branches/srichter-twisted-integration2/src/zope/app/server/tests/test_server.py
===================================================================
--- Zope3/branches/srichter-twisted-integration2/src/zope/app/server/tests/test_server.py	2005-09-09 02:42:44 UTC (rev 38414)
+++ Zope3/branches/srichter-twisted-integration2/src/zope/app/server/tests/test_server.py	2005-09-09 03:24:35 UTC (rev 38415)
@@ -87,9 +87,6 @@
 def test_suite():
     return unittest.TestSuite((
         doctest.DocTestSuite(),
-        doctest.DocTestSuite(
-            'zope.app.server.main',
-            setUp=placelesssetup.setUp, tearDown=placelesssetup.tearDown),
         ))
 
 

Modified: Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/main.py
===================================================================
--- Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/main.py	2005-09-09 02:42:44 UTC (rev 38414)
+++ Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/main.py	2005-09-09 03:24:35 UTC (rev 38415)
@@ -112,7 +112,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))
 



More information about the Zope3-Checkins mailing list