[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/ Added a public interfaces module for appsetup and moved teh key

Jim Fulton jim at zope.com
Fri Feb 18 15:57:06 EST 2005


Log message for revision 29211:
  Added a public interfaces module for appsetup and moved teh key
  interfaces there.
  
  Added the beginning of a doctest.
  
  Changed the bootstrap subscriber that generates a root object to
  generate a new IDatabaseOpenedWithRootEvent event so that other
  startup code can subscribe to that and know that the root object does,
  in fact, exist.
  

Changed:
  U   Zope3/trunk/src/zope/app/appsetup/__init__.py
  U   Zope3/trunk/src/zope/app/appsetup/appsetup.py
  U   Zope3/trunk/src/zope/app/appsetup/bootstrap.py
  A   Zope3/trunk/src/zope/app/appsetup/bootstrap.txt
  A   Zope3/trunk/src/zope/app/appsetup/interfaces.py
  U   Zope3/trunk/src/zope/app/appsetup/tests.py
  U   Zope3/trunk/src/zope/app/server/main.py

-=-
Modified: Zope3/trunk/src/zope/app/appsetup/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/appsetup/__init__.py	2005-02-18 20:00:24 UTC (rev 29210)
+++ Zope3/trunk/src/zope/app/appsetup/__init__.py	2005-02-18 20:57:05 UTC (rev 29211)
@@ -17,6 +17,6 @@
 """
 __docformat__ = 'restructuredtext'
 
-from zope.app.appsetup.appsetup import IDatabaseOpenedEvent, DatabaseOpened
-from zope.app.appsetup.appsetup import IProcessStartingEvent, ProcessStarting
+from zope.app.appsetup.interfaces import IDatabaseOpenedEvent, DatabaseOpened
+from zope.app.appsetup.interfaces import IProcessStartingEvent, ProcessStarting
 from zope.app.appsetup.appsetup import config, database

Modified: Zope3/trunk/src/zope/app/appsetup/appsetup.py
===================================================================
--- Zope3/trunk/src/zope/app/appsetup/appsetup.py	2005-02-18 20:00:24 UTC (rev 29210)
+++ Zope3/trunk/src/zope/app/appsetup/appsetup.py	2005-02-18 20:57:05 UTC (rev 29211)
@@ -21,24 +21,8 @@
 import zope.app.component.hooks
 from zope.security.interfaces import IParticipation
 from zope.security.management import system_user
+from zope.app.appsetup import interfaces
 
-class IDatabaseOpenedEvent(zope.interface.Interface):
-    """The main database has been opened."""
-
-    database = zope.interface.Attribute("The main database.")
-
-class DatabaseOpened(object):
-    zope.interface.implements(IDatabaseOpenedEvent)
-
-    def __init__(self, database):
-        self.database = database
-
-class IProcessStartingEvent(zope.interface.Interface):
-    """The application server process is starting."""
-
-class ProcessStarting(object):
-    zope.interface.implements(IProcessStartingEvent)
-
 class SystemConfigurationParticipation(object):
     zope.interface.implements(IParticipation)
 
@@ -98,7 +82,7 @@
 
     # The following will fail unless the application has been configured.
     from zope.event import notify
-    notify(DatabaseOpened(db))
+    notify(interfaces.DatabaseOpened(db))
 
     return db
 
@@ -106,3 +90,19 @@
 __config_source = None
 def getConfigSource():
     return __config_source
+
+
+# BBB
+import zope.deprecation
+IDatabaseOpenedEvent = interfaces.IDatabaseOpenedEvent
+DatabaseOpened = interfaces.DatabaseOpened
+IProcessStartingEvent = interfaces.IProcessStartingEvent
+ProcessStarting = interfaces.ProcessStarting
+zope.deprecation.deprecated(
+    ['IDatabaseOpenedEvent', 'DatabaseOpened',
+     'IProcessStartingEvent', 'ProcessStarting'
+     ],
+    "The database opened and process starting events have moved to "
+    "zope.app.appsetup.interfaces they will disappear from here in "
+    "in ZopeX3.3."
+    )

Modified: Zope3/trunk/src/zope/app/appsetup/bootstrap.py
===================================================================
--- Zope3/trunk/src/zope/app/appsetup/bootstrap.py	2005-02-18 20:00:24 UTC (rev 29210)
+++ Zope3/trunk/src/zope/app/appsetup/bootstrap.py	2005-02-18 20:57:05 UTC (rev 29211)
@@ -21,12 +21,15 @@
 __docformat__ = 'restructuredtext'
 from transaction import get_transaction
 
+import zope.event
+
 from zope.app.component.interfaces import ISite
 from zope.app.component import site
 from zope.app.container.interfaces import INameChooser
 from zope.app.folder import rootFolder
 from zope.app.publication.zopepublication import ZopePublication
 from zope.app.traversing.api import traverse
+from zope.app.appsetup import interfaces
 
 def ensureObject(root_folder, object_name, object_type, object_factory):
     """Check that there's a basic object in the site
@@ -143,5 +146,7 @@
 
     connection.close()
 
+    zope.event.notify(interfaces.DatabaseOpenedWithRoot(db))
+
 ########################################################################
 ########################################################################

Added: Zope3/trunk/src/zope/app/appsetup/bootstrap.txt
===================================================================
--- Zope3/trunk/src/zope/app/appsetup/bootstrap.txt	2005-02-18 20:00:24 UTC (rev 29210)
+++ Zope3/trunk/src/zope/app/appsetup/bootstrap.txt	2005-02-18 20:57:05 UTC (rev 29211)
@@ -0,0 +1,36 @@
+Bootstrap helpers
+=================
+
+The bootstrap helpers provide a number of functions that help with
+bootstrapping.
+
+The bootStrapSubscriber function makes sure that there is a root
+object.  It subscribes to DatabaseOpened events:
+
+    >>> from zope.app.appsetup import bootstrap
+    >>> from zope.app.appsetup import interfaces
+
+    >>> from ZODB.tests import util
+    >>> db = util.DB()
+    >>> bootstrap.bootStrapSubscriber(interfaces.DatabaseOpened(db))
+
+The subscriber makes ure that there is a root folder:
+
+    >>> from zope.app.publication.zopepublication import ZopePublication
+    >>> conn = db.open()
+    >>> root = conn.root()[ZopePublication.root_name]
+    >>> sm = root.getSiteManager()
+    >>> conn.close()
+    
+A DatabaseOpenedWithRoot is generated with the database.
+
+    >>> from zope.app.event.tests.placelesssetup import getEvents
+    >>> [event] = getEvents(interfaces.IDatabaseOpenedWithRootEvent)
+    >>> event.database is db
+    True
+
+Generally, startup code that expects the root object and site to have
+been created will want to subscribe to this event, not
+IDataBaseOpenedEvent.
+
+


Property changes on: Zope3/trunk/src/zope/app/appsetup/bootstrap.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: Zope3/trunk/src/zope/app/appsetup/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/appsetup/interfaces.py	2005-02-18 20:00:24 UTC (rev 29210)
+++ Zope3/trunk/src/zope/app/appsetup/interfaces.py	2005-02-18 20:57:05 UTC (rev 29211)
@@ -0,0 +1,51 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""API for working installing things on startup.
+
+$Id$
+"""
+
+from zope import interface
+
+
+class IDatabaseOpenedEvent(interface.Interface):
+    """The main database has been opened."""
+
+    database = interface.Attribute("The main database.")
+
+class DatabaseOpened(object):
+    interface.implements(IDatabaseOpenedEvent)
+
+    def __init__(self, database):
+        self.database = database
+
+class IDatabaseOpenedWithRootEvent(interface.Interface):
+    """The main database has been opened."""
+
+    database = interface.Attribute("The main database.")
+
+class DatabaseOpenedWithRoot(object):
+    interface.implements(IDatabaseOpenedWithRootEvent)
+
+    def __init__(self, database):
+        self.database = database
+
+class IProcessStartingEvent(interface.Interface):
+    """The application server process is starting."""
+
+class ProcessStarting(object):
+    interface.implements(IProcessStartingEvent)
+
+
+    


Property changes on: Zope3/trunk/src/zope/app/appsetup/interfaces.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: Zope3/trunk/src/zope/app/appsetup/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/appsetup/tests.py	2005-02-18 20:00:24 UTC (rev 29210)
+++ Zope3/trunk/src/zope/app/appsetup/tests.py	2005-02-18 20:57:05 UTC (rev 29211)
@@ -17,6 +17,8 @@
 """
 import unittest
 from transaction import get_transaction
+from zope.testing import doctest
+
 from ZODB.tests.util import DB
 
 from zope.app.component.testing import PlacefulSetup
@@ -32,6 +34,8 @@
 from zope.app.appsetup.bootstrap import getInformationFromEvent, \
      ensureObject, ensureUtility
 
+from zope.app.testing import placelesssetup
+
 class EventStub(object):
 
     def __init__(self, db):
@@ -112,9 +116,16 @@
 
         cx.close()
 
+def bootstraptearDown(test):
+    test.globs['db'].close()
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(TestBootstrapSubscriber))
+    suite.addTest(doctest.DocFileSuite(
+        'bootstrap.txt',
+        setUp=placelesssetup.setUp, tearDown=placelesssetup.tearDown,
+        ))
     return suite
 
 if __name__ == '__main__':

Modified: Zope3/trunk/src/zope/app/server/main.py
===================================================================
--- Zope3/trunk/src/zope/app/server/main.py	2005-02-18 20:00:24 UTC (rev 29210)
+++ Zope3/trunk/src/zope/app/server/main.py	2005-02-18 20:57:05 UTC (rev 29211)
@@ -25,6 +25,7 @@
 import ThreadedAsync
 
 import zope.app.appsetup
+import zope.app.appsetup.interfaces
 from zope.event import notify
 from zope.server.taskthreads import ThreadedTaskDispatcher
 
@@ -66,7 +67,7 @@
     zope.app.appsetup.config(options.site_definition)
 
     db = options.database.open()
-    notify(zope.app.appsetup.DatabaseOpened(db))
+    notify(zope.app.appsetup.interfaces.DatabaseOpened(db))
     return db
 
 
@@ -101,7 +102,7 @@
 
     db = options.database.open()
 
-    notify(zope.app.appsetup.DatabaseOpened(db))
+    notify(zope.app.appsetup.interfaces.DatabaseOpened(db))
 
     task_dispatcher = ThreadedTaskDispatcher()
     task_dispatcher.setThreadCount(options.threads)
@@ -109,6 +110,6 @@
     for server in options.servers:
         server.create(task_dispatcher, db)
 
-    notify(zope.app.appsetup.ProcessStarting())
+    notify(zope.app.appsetup.interfaces.ProcessStarting())
 
     return db



More information about the Zope3-Checkins mailing list