[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services/service -
__init__.py:1.11
Richard Jones
richard at commonground.com.au
Fri Feb 6 23:23:53 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/browser/services/service
In directory cvs.zope.org:/tmp/cvs-serv8868/browser/services/service
Modified Files:
__init__.py
Log Message:
Services are now registered and active when added if there's only one
possible registration. If there's more than one (eg. EventService) then
registration and activation is punted to later.
=== Zope3/src/zope/app/browser/services/service/__init__.py 1.10 => 1.11 ===
--- Zope3/src/zope/app/browser/services/service/__init__.py:1.10 Wed Dec 10 00:13:00 2003
+++ Zope3/src/zope/app/browser/services/service/__init__.py Fri Feb 6 23:23:50 2004
@@ -89,8 +89,32 @@
if not ILocalService.isImplementedBy(content):
raise TypeError("%s is not a local service" % content)
- return super(ServiceAdding, self).add(content)
+ content = super(ServiceAdding, self).add(content)
+ # figure out the interfaces that this service implements
+ sm = zapi.getServiceManager(self.context)
+ implements = []
+ for type_name, interface in sm.getServiceDefinitions():
+ if interface.isImplementedBy(content):
+ implements.append(type_name)
+
+ # more than one interface, punt to user to make choice
+ if len(implements) > 1:
+ return content
+
+ type_name = implements[0]
+
+ # register an activated service registration
+ path = zapi.name(content)
+ rm = content.__parent__.getRegistrationManager()
+ chooser = zapi.getAdapter(rm, INameChooser)
+
+ sc = ServiceRegistration(type_name, path, content)
+ name = chooser.chooseName(type_name, sc)
+ rm[name] = sc
+ sc.status = ActiveStatus
+
+ return content
class UtilityAdding(ComponentAdding):
"""Adding subclass used for adding utilities."""
@@ -106,7 +130,7 @@
class AddServiceRegistration(BrowserView):
- """A view on a service implementation, used by add_svc_config.py."""
+ """A view on a service implementation, used by add_svc_config.pt."""
def listServiceTypes(self):
More information about the Zope3-Checkins
mailing list