[Zope3-checkins] CVS: Zope3/src/zope/app/services - service.py:1.31

Jim Fulton cvs-admin at zope.org
Fri Nov 21 12:10:25 EST 2003


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

Modified Files:
	service.py 
Log Message:
Added references between site managers.  Each sm has a reference to
the site-manager directly above it (may be the global sm) and to the
site managers directly below it.

(We now love cycles. :)


=== Zope3/src/zope/app/services/service.py 1.30 => 1.31 ===
--- Zope3/src/zope/app/services/service.py:1.30	Sun Sep 21 13:33:00 2003
+++ Zope3/src/zope/app/services/service.py	Fri Nov 21 12:09:55 2003
@@ -28,6 +28,7 @@
 
 import sys
 
+from zope.app import zapi
 from zodb.code.module import PersistentModuleRegistry
 
 from zope.interface import implements
@@ -54,7 +55,11 @@
 from zope.app.container.contained import Contained
 from zope.app.container.btree import BTreeContainer
 
-class ServiceManager(BTreeContainer,
+from zope.app.interfaces.traversing import IContainmentRoot
+from zope.app.interfaces.services.service import ISite
+from zope.app.location import inside
+
+class SiteManager(BTreeContainer,
                      PersistentModuleRegistry,
                      NameComponentRegistry,
                      ):
@@ -67,8 +72,43 @@
         BTreeContainer.__init__(self)
         PersistentModuleRegistry.__init__(self)
         NameComponentRegistry.__init__(self)
+        self.subSites = ()
+        self._setNext(site)
         self['default'] = SiteManagementFolder()
 
+    def _setNext(self, site):
+        """Find set the next service manager
+        """
+
+        while 1:
+            if IContainmentRoot.isImplementedBy(site):
+                # we're the root site, use the global sm
+                self.next = zapi.getServiceManager(None)
+                return
+            site = site.__parent__
+            if site is None:
+                raise TypeError("Not enough context information")
+            if ISite.isImplementedBy(site):
+                self.next = site.getSiteManager()
+                self.next.addSubsite(self)
+                return
+
+    def addSubsite(self, sub):
+
+        subsite = sub.__parent__
+
+        # Update any sites that are now in the subsite:
+        subsites = []
+        for s in self.subSites:
+            if inside(s, subsite):
+                s.next = sub
+                sub.addSubsite(s)
+            else:
+                subsites.append(s)
+
+        subsites.append(sub)
+        self.subSites = tuple(subsites)
+
     def getServiceDefinitions(wrapped_self):
         "See IServiceService"
 
@@ -201,6 +241,7 @@
 
         return mod
 
+ServiceManager = SiteManager # Backward compat
 
 class ServiceRegistration(NamedComponentRegistration):
 
@@ -262,3 +303,53 @@
     def extra(self):
         obj = removeAllProxies(self.context)
         return AttrMapping(obj, _smattrs)
+
+#BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
+
+
+
+from zope.app.event.function import Subscriber
+from transaction import get_transaction
+from zope.component.exceptions import ComponentLookupError
+from zope.app.interfaces.services.service import IPossibleSite
+
+def fixup(event):
+    database = event.database
+    connection = database.open()
+    app = connection.root().get('Application')
+    if app is None:
+        # no old site
+        return
+
+    try:
+        sm = app.getSiteManager()
+    except ComponentLookupError:
+        # no old site
+        return
+
+    if hasattr(sm, 'next'):
+        # already done
+        return
+    
+    print "Fixing up sites that don't have next pointers"
+    fixfolder(app)
+    get_transaction().commit()
+    connection.close()
+    
+fixup = Subscriber(fixup)
+
+def fixfolder(folder):
+    try:
+        sm = folder.getSiteManager()
+    except ComponentLookupError:
+        pass # nothing to do
+    else:
+        sm._setNext(folder)
+        sm.subSites = ()
+        for name in ('Views', 'Adapters'):
+            if name in sm._bindings:
+                del sm._bindings[name]
+
+    for item in folder.values():
+        if IPossibleSite.isImplementedBy(item):
+            fixfolder(item)




More information about the Zope3-Checkins mailing list