[Zope3-checkins] CVS: Zope3/src/zope/app/process - bootstrap.py:1.16
Stuart Bishop
zen at shangri-la.dropbear.id.au
Tue Feb 10 22:33:40 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/process
In directory cvs.zope.org:/tmp/cvs-serv6974
Modified Files:
bootstrap.py
Log Message:
ensureUtility shouldn't overwrite existing utilities if they already exist
=== Zope3/src/zope/app/process/bootstrap.py 1.15 => 1.16 ===
--- Zope3/src/zope/app/process/bootstrap.py:1.15 Mon Feb 9 02:52:08 2004
+++ Zope3/src/zope/app/process/bootstrap.py Tue Feb 10 22:33:39 2004
@@ -128,11 +128,22 @@
def ensureUtility(
self, interface, utility_type, utility_factory, name='', **kw):
- """ Add a utility to the top Utility Service """
- return addConfigureUtility(
- self.root_folder, interface, utility_type, utility_factory,
- name, **kw
+ """Add a utility to the top Utility Service
+
+ Returns the name added or None if nothing was added.
+ """
+ utility_manager = zapi.getService(
+ self.root_folder, Utilities
)
+ utility = utility_manager.queryUtility(interface, name=name)
+ if utility is None:
+ return addConfigureUtility(
+ self.root_folder, interface, utility_type, utility_factory,
+ name, **kw
+ )
+ else:
+ return None
+
class BootstrapInstance(BootstrapSubscriberBase):
"""Bootstrap a Zope3 instance given a database object.
More information about the Zope3-Checkins
mailing list