[Zope3-checkins] CVS: Zope3/src/zope/app/startup - bootstrap.py:1.3
Steve Alexander
steve@cat-box.net
Mon, 30 Dec 2002 09:03:50 -0500
Update of /cvs-repository/Zope3/src/zope/app/startup
In directory cvs.zope.org:/tmp/cvs-serv23914/src/zope/app/startup
Modified Files:
bootstrap.py
Log Message:
Large refactoring of the event service.
=== Zope3/src/zope/app/startup/bootstrap.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/startup/bootstrap.py:1.2 Wed Dec 25 09:13:24 2002
+++ Zope3/src/zope/app/startup/bootstrap.py Mon Dec 30 09:03:19 2002
@@ -25,13 +25,10 @@
from zope.app.publication.zopepublication import ZopePublication
from zope.app.content.folder import RootFolder
from zope.app.services.service import ServiceManager
-from zope.app.services.service import \
- ServiceConfiguration
+from zope.app.services.service import ServiceConfiguration
from zope.app.services.hub import ObjectHub
-from zope.app.services.event import \
- LocalEventService
-from zope.app.services.errorr import \
- ErrorReportingService
+from zope.app.services.event import EventService
+from zope.app.services.errorr import ErrorReportingService
def bootstrapInstance(db):
@@ -65,19 +62,27 @@
"""
service_manager = ServiceManager()
root_folder.setServiceManager(service_manager)
- addService(root_folder, 'Events', LocalEventService)
- addService(root_folder, 'ObjectHub', ObjectHub)
- addService(root_folder, 'ErrorReportingService', ErrorReportingService,
- copy_to_zlog=True)
+ name = addConfigureService(root_folder, 'Events', EventService)
+ configureService(root_folder, 'Subscription', name)
+
+ addConfigureService(root_folder, 'HubIds', ObjectHub)
+ addConfigureService(root_folder, 'ErrorReportingService',
+ ErrorReportingService, copy_to_zlog=True)
+
+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)
+ configureService(root_folder, service_type, name)
+ return name
-
-def addService(root_folder, service_type, service_factory,
- initial_status='Active', **kw):
- """Add and configure a service to the root folder.
+def addService(root_folder, service_type, service_factory, **kw):
+ """Add a service to the root folder.
The service is added to the default package and activated.
This assumes the root folder already has a service manager,
and that we add at most one service of each type.
+
+ Returns the name of the service implementation in the default package.
"""
# The code here is complicated by the fact that the registry
# calls at the end require a fully context-wrapped
@@ -87,12 +92,21 @@
name = service_type + '-1'
service = service_factory()
package.setObject(name, service)
+
+ # Set additional attributes on the service
+ for k, v in kw.iteritems():
+ setattr(service, k, v)
+ return name
+
+def configureService(root_folder, service_type, name,
+ initial_status='Active'):
+ """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)
configuration = traverseName(configuration_manager, key)
configuration.status = initial_status
- # Set additional attributes on the service
- for k, v in kw.iteritems():
- setattr(service, k, v)
+