[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/StartUp - SiteDefinition.py:1.4
Guido van Rossum
guido@python.org
Tue, 10 Dec 2002 18:04:09 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/StartUp
In directory cvs.zope.org:/tmp/cvs-serv31087
Modified Files:
SiteDefinition.py
Log Message:
A *very* preliminary version of code to create and configure Events
and ObjectHub services. This currently hardcodes everything. It
doesn't activate or even register them, because I don't know how to do
that yet.
XXX My motivation for checking this in now is:
(1) It works (as far as it goes).
(2) It's a definite improvement (cuts out several steps from my
recipe for setting up a text index).
(3) Maybe SteveA or Jim can look at my code and suggest a better way
to do it, or explain why my attempts to activate the services
failed.
(4) I plan to generalize this and add ZCML directives, once I
understand how it's done.
XXX Note: Wednesday I'm traveling to ZC HQ, which means I may not get
to hack on this code until Thursday.
=== Zope3/lib/python/Zope/App/StartUp/SiteDefinition.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/StartUp/SiteDefinition.py:1.3 Tue Dec 10 14:42:51 2002
+++ Zope3/lib/python/Zope/App/StartUp/SiteDefinition.py Tue Dec 10 18:04:09 2002
@@ -24,7 +24,14 @@
from Zope.Configuration.INonEmptyDirective import INonEmptyDirective
from Zope.Configuration.ISubdirectiveHandler import ISubdirectiveHandler
+# Import classes related to initial-services
from ServerTypeRegistry import getServerType
+from Zope.App.OFS.Services.ObjectHub.ObjectHub import ObjectHub
+from Zope.App.OFS.Services.LocalEventService.LocalEventService import \
+ LocalEventService
+from Zope.App.OFS.Services.ServiceManager.ServiceManager import ServiceManager
+from Zope.App.OFS.Services.ServiceManager.ServiceConfiguration import \
+ ServiceConfiguration
# Import Undo-related classes
from Zope.ComponentArchitecture import getService
@@ -154,6 +161,7 @@
from Transaction import get_transaction
app = RootFolder()
+ self._addEssentialServices(app)
root[ZopePublication.root_name] = app
get_transaction().commit()
@@ -162,6 +170,47 @@
imp = PersistentModuleImporter()
imp.install()
+
+
+ def _addEssentialServices(self, app):
+ """Add essential services.
+
+ XXX This ought to be configurable. For now, hardcode an Event
+ service and an ObjectHub. I'll refactor later.
+
+ XXX To reiterate, THIS IS AN EXAMPLE ONLY!!! This code should
+ be generalized. Preferably, using marker interfaces,
+ adapters, and a factory or two. Oh, and don't forget
+ metameta.zcml. :-)
+ """
+
+ sm = ServiceManager()
+ app.setServiceManager(sm)
+
+ default = sm.Packages['default']
+
+ es = LocalEventService()
+ default.setObject('Events-1', es)
+
+ hub = ObjectHub()
+ default.setObject('ObjectHub-1', hub)
+
+ configure = default['configure']
+ here = ('', '++etc++Services', 'Packages', 'default')
+
+ sc = ServiceConfiguration('Events', here + ('Events-1',))
+ configure.setObject(None, sc)
+
+ sc = ServiceConfiguration('ObjectHub', here + ('ObjectHub-1',))
+ configure.setObject(None, sc)
+
+ # XXX I want to register and possibly activate these services,
+ # but the following code doesn't work. :-(
+ ##sc.status = "Active"
+ # XXX And the following code doesn't work either. :-(
+ registry = sm.createConfigurationsFor(sc)
+ ##registry.register(sc)
+ ##registry.activate(sc)
def __call__(self):