[Zope-Checkins] SVN: Products.Five/trunk/ Support and tests for
site migration from Five.site to Five.component.
Lennart Regebro
regebro at gmail.com
Thu Jul 27 08:33:38 EDT 2006
Log message for revision 69269:
Support and tests for site migration from Five.site to Five.component.
Changed:
U Products.Five/trunk/CHANGES.txt
U Products.Five/trunk/doc/localsite.txt
U Products.Five/trunk/site/browser.py
U Products.Five/trunk/site/managesite.pt
U Products.Five/trunk/site/tests/test_localsite.py
U Products.Five/trunk/site/tests/test_utility.py
-=-
Modified: Products.Five/trunk/CHANGES.txt
===================================================================
--- Products.Five/trunk/CHANGES.txt 2006-07-27 10:03:20 UTC (rev 69268)
+++ Products.Five/trunk/CHANGES.txt 2006-07-27 12:33:37 UTC (rev 69269)
@@ -24,7 +24,8 @@
(and not on attributes).
* The FiveSiteManager classes now work again, but are deprecated for the
- new zope.component support.
+ new zope.component support. There is also a method to migrate Five.site
+ to zope.component.
Five 1.5c (2006-05-29)
======================
Modified: Products.Five/trunk/doc/localsite.txt
===================================================================
--- Products.Five/trunk/doc/localsite.txt 2006-07-27 10:03:20 UTC (rev 69268)
+++ Products.Five/trunk/doc/localsite.txt 2006-07-27 12:33:37 UTC (rev 69269)
@@ -42,8 +42,15 @@
or programmatically through enableLocalSiteHook(site) turn it into a site.
The new setup involves calling enableSite(site) and createing and setting
-a site manager. The simplest way to do this programatically is to look
-up the "components.html" view on the site, and calling view.makeSite().
+a site manager. The simplest way to do this manually is to go to the
+"components.html" view of the object you want to make a site, and press the
+"Make site" button. The easist way to do this programmatically, is to look
+up the "components.html" view on the site, and calling view.makeSite():
+
+ components_view = queryMultiAdapter((self.context, self.request),
+ Interface, 'components.html')
+ components_view.makeSite()
+
As any ObjectManager can be a site there is no longer any need to specially
mark the class as being a possible site.
@@ -62,7 +69,9 @@
Migrating the actual sites
..........................
-Not Yet Implemented.
+Go to the object of the site, and add "manage_site.html" to the URL to open
+the old site management view. There you have a button
+"Migrate to Five.component". Press it to migrate the site.
Experimental forwards compatibility
...................................
@@ -76,7 +85,7 @@
Old site implementation details
--------------------------------
+===============================
The rest of this document documents the details of the old site implementation.
Everything from here on concerns only the old implementation and is of mainly
Modified: Products.Five/trunk/site/browser.py
===================================================================
--- Products.Five/trunk/site/browser.py 2006-07-27 10:03:20 UTC (rev 69268)
+++ Products.Five/trunk/site/browser.py 2006-07-27 12:33:37 UTC (rev 69269)
@@ -16,7 +16,9 @@
$Id$
"""
from zope.app.component.interfaces import ISite
-from zope.app.component.hooks import clearSite
+from zope.app.component.hooks import clearSite, setSite
+from zope.component import getSiteManager, queryMultiAdapter
+from zope.interface import Interface, providedBy
from Products.Five.browser import BrowserView
from Products.Five.site.localsite import enableLocalSiteHook, disableLocalSiteHook
@@ -31,10 +33,16 @@
self.makeSite()
elif form.has_key('UPDATE_UNMAKESITE'):
self.unmakeSite()
+ elif form.has_key('UPDATE_MIGRATE'):
+ self.migrateToFive15()
def isSite(self):
return ISite.providedBy(self.context)
+ def isOldSite(self):
+ from Products.Five.site.interfaces import IFiveSiteManager
+ return self.isSite() and IFiveSiteManager.providedBy(getSiteManager())
+
def makeSite(self):
"""Convert a possible site to a site"""
if self.isSite():
@@ -58,3 +66,30 @@
clearSite()
return "This object is no longer a site"
+
+ def migrateToFive15(self):
+ all_utilities = self.context.utilities.objectItems()
+
+ self.unmakeSite()
+ self.context.manage_delObjects(['utilities'])
+ components_view = queryMultiAdapter((self.context, self.request),
+ Interface, 'components.html')
+ components_view.makeSite()
+ setSite(self.context)
+
+ site_manager = getSiteManager()
+ for id, utility in all_utilities:
+ info = id.split('-')
+ if len(info) == 1:
+ name = ''
+ else:
+ name = info[1]
+ interface_name = info[0]
+
+ for iface in providedBy(utility):
+ if iface.getName() == interface_name:
+ site_manager.registerUtility(utility, iface, name=name)
+
+ return "Migration done!"
+
+
\ No newline at end of file
Modified: Products.Five/trunk/site/managesite.pt
===================================================================
--- Products.Five/trunk/site/managesite.pt 2006-07-27 10:03:20 UTC (rev 69268)
+++ Products.Five/trunk/site/managesite.pt 2006-07-27 12:33:37 UTC (rev 69269)
@@ -14,6 +14,10 @@
<input type="submit" value="Unmake site" name="UPDATE_UNMAKESITE"
i18n:attributes="value"
tal:attributes="disabled not:view/isSite"/>
+ <input type="submit" value="Migrate to Five.component"
+ name="UPDATE_MIGRATE"
+ i18n:attributes="value"
+ tal:attributes="disabled not:view/isOldSite"/>
</div>
</div>
Modified: Products.Five/trunk/site/tests/test_localsite.py
===================================================================
--- Products.Five/trunk/site/tests/test_localsite.py 2006-07-27 10:03:20 UTC (rev 69268)
+++ Products.Five/trunk/site/tests/test_localsite.py 2006-07-27 12:33:37 UTC (rev 69269)
@@ -122,16 +122,10 @@
marker = object()
self.assert_(queryNextSiteManager(self.root, marker) is marker)
self.assert_(queryNextSiteManager(self.f1, marker) is getGlobalSiteManager())
- #XXX the following used to be
- #self.assertEqual(queryNextSiteManager(self.f2, marker), marker)
self.assertEqual(queryNextSiteManager(self.f2, marker), self.sm1)
self.assertEqual(queryNextSiteManager(self.sm1), getGlobalSiteManager())
self.assertEqual(queryNextSiteManager(self.sm2), self.sm1)
- #XXX the following used to be
- #self.assert_(queryNextSiteManager(self.p1) is getGlobalSiteManager())
self.assert_(queryNextSiteManager(self.p1, marker) is marker)
- #XXX the following used to be
- #self.assertEqual(queryNextSiteManager(self.p2), self.sm1)
self.assert_(queryNextSiteManager(self.p2, marker) is marker)
self.assert_(queryNextSiteManager(self.unparented_folder, marker)
@@ -143,16 +137,10 @@
from zope.app.component import getNextSiteManager
self.assertRaises(ComponentLookupError, getNextSiteManager, self.root)
self.assertEqual(getNextSiteManager(self.f1), getGlobalSiteManager())
- #XXX the following used to be
- #self.assertRaises(ComponentLookupError, getNextSiteManager, self.f2)
self.assertEqual(getNextSiteManager(self.f2), self.sm1)
self.assertEqual(getNextSiteManager(self.sm1), getGlobalSiteManager())
self.assertEqual(getNextSiteManager(self.sm2), self.sm1)
- #XXX the following used to be
- #self.assert_(getNextSiteManager(self.p1) is getGlobalSiteManager())
self.assertRaises(ComponentLookupError, getNextSiteManager, self.p1)
- #XXX the following used to be
- #self.assertEqual(getNextSiteManager(self.p2), self.sm1)
self.assertRaises(ComponentLookupError, getNextSiteManager, self.p2)
self.assertRaises(ComponentLookupError,
Modified: Products.Five/trunk/site/tests/test_utility.py
===================================================================
--- Products.Five/trunk/site/tests/test_utility.py 2006-07-27 10:03:20 UTC (rev 69268)
+++ Products.Five/trunk/site/tests/test_utility.py 2006-07-27 12:33:37 UTC (rev 69269)
@@ -277,9 +277,65 @@
self.assertEquals(getNextUtility(self.folder.site, IDummyUtility),
global_dummy)
+
+class LocalUtilityMigrateTest(ZopeTestCase.ZopeTestCase):
+
+ def afterSetUp(self):
+ setUp()
+ zcml.load_config("meta.zcml", Products.Five)
+ zcml.load_config("permissions.zcml", Products.Five)
+ zcml.load_config("configure.zcml", Products.Five.component)
+ zcml.load_config("configure.zcml", Products.Five.site)
+ zcml_text = """\
+ <five:localsite
+ xmlns:five="http://namespaces.zope.org/five"
+ class="OFS.Folder.Folder" />"""
+
+ import warnings
+ showwarning = warnings.showwarning
+ warnings.showwarning = lambda *a, **k: None
+
+ zcml.load_string(zcml_text)
+ enableLocalSiteHook(self.folder)
+
+ warnings.showwarning = showwarning
+
+ # Hook up custom component architecture calls; we need to do
+ # this here because zope.app.component.hooks registers a
+ # cleanup with the testing cleanup framework, so the hooks get
+ # torn down by placelesssetup each time.
+ setHooks()
+
+ def test_migration(self):
+ # Migrate from Five.site to Five.component
+
+ # Register utilities
+ sm = getSiteManager()
+ self.failUnless(IRegisterUtilitySimply.providedBy(sm))
+ dummy = DummyUtility()
+ superdummy = DummyUtility()
+ directlyProvides(superdummy, ISuperDummyUtility)
+ sm.registerUtility(IDummyUtility, dummy, 'dummy')
+ sm.registerUtility(ISuperDummyUtility, superdummy, 'dummy')
+
+ self.assertEquals(zapi.getUtility(IDummyUtility, 'dummy'), dummy)
+ self.assertEquals(zapi.getUtility(ISuperDummyUtility, 'dummy'),
+ superdummy)
+
+ siteview = self.folder.unrestrictedTraverse('manage_site.html')
+ siteview.migrateToFive15()
+
+ self.assert_('utilities' not in self.folder.objectIds())
+ # It should still work
+ self.assertEquals(zapi.getUtility(IDummyUtility, 'dummy'), dummy)
+ self.assertEquals(zapi.getUtility(ISuperDummyUtility, 'dummy'),
+ superdummy)
+
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(LocalUtilityServiceTest))
+ suite.addTest(unittest.makeSuite(LocalUtilityMigrateTest))
return suite
if __name__ == '__main__':
More information about the Zope-Checkins
mailing list