[Zope3-checkins] CVS: Zope3/src/zope/app/startup - bootstrap.py:1.7.2.1

Guido van Rossum guido@python.org
Tue, 25 Feb 2003 16:38:23 -0500


Update of /cvs-repository/Zope3/src/zope/app/startup
In directory cvs.zope.org:/tmp/cvs-serv12207

Modified Files:
      Tag: use-config-branch
	bootstrap.py 
Log Message:
Make sure that the "uses" annotations are added for bootstrapped
services.  This is tricky because a HubIds service must be configured
before manage_afterAdd() can be called to connfigure the HubIds
service!  The solution special-cases the HubIds service to avoid using
a ZopeContainerAdapter, and calls manage_afterAdd() directly after
activating the configuration.


=== Zope3/src/zope/app/startup/bootstrap.py 1.7 => 1.7.2.1 ===
--- Zope3/src/zope/app/startup/bootstrap.py:1.7	Sun Feb 23 10:09:54 2003
+++ Zope3/src/zope/app/startup/bootstrap.py	Tue Feb 25 16:38:23 2003
@@ -32,6 +32,7 @@
 from zope.app.services.event import EventService
 from zope.app.services.errorr import ErrorReportingService
 from zope.app.services.principalannotation import PrincipalAnnotationService
+from zope.app.container.zopecontainer import ZopeContainerAdapter
 from zope.proxy.introspection import removeAllProxies
 
 def bootstrapInstance(db):
@@ -65,15 +66,22 @@
     """
     service_manager = ServiceManager()
     root_folder.setServiceManager(service_manager)
+
+    # Add the HubIds service first.  It has bootstrap issues
+    name = addService(root_folder, HubIds, ObjectHub)
+    configureService(root_folder, HubIds, name, use_container=False)
+
+    # The EventService class implements two services
     name = addConfigureService(root_folder, Events, EventService)
     configureService(root_folder, Subscription, name)
 
-    addConfigureService(root_folder, HubIds, ObjectHub)
+    # Sundry other services
     addConfigureService(root_folder, ErrorReports,
                         ErrorReportingService, copy_to_zlog=True)
     addConfigureService(root_folder, 'PrincipalAnnotation',
                         PrincipalAnnotationService)
 
+
 def addConfigureService(root_folder, service_type, service_factory, **kw):
     """Add and configure a service to the root folder."""
     name = addService(root_folder, service_type, service_factory, **kw)
@@ -105,14 +113,19 @@
     return name
 
 def configureService(root_folder, service_type, name,
-                     initial_status='Active'):
+                     initial_status='Active', use_container=True):
     """Configure a service in the root folder."""
     package_name = ('', '++etc++Services', 'Packages', 'default')
     package = traverse(root_folder, package_name)
     configuration_manager = traverseName(package, 'configure')
     configuration =  ServiceConfiguration(service_type,
                                           package_name + (name,))
-    key = configuration_manager.setObject(None, configuration)
+    cm = configuration_manager
+    if use_container:
+        cm = ZopeContainerAdapter(configuration_manager)
+    key = cm.setObject("", configuration)
     configuration = traverseName(configuration_manager, key)
     configuration.status = initial_status
-
+    if not use_container:
+        # For HubIds bootstrap
+        configuration.manage_afterAdd(configuration, configuration_manager)