[Checkins] SVN: zope.app.generations/trunk/ Moved ``getRootFolder`` utility method from ``zope.app.zopeappgenerations`` to ``zope.app.generations.utils``.
Michael Howitz
mh at gocept.com
Sun Apr 5 15:17:58 EDT 2009
Log message for revision 98884:
Moved ``getRootFolder`` utility method from ``zope.app.zopeappgenerations`` to ``zope.app.generations.utils``.
Changed:
U zope.app.generations/trunk/CHANGES.txt
U zope.app.generations/trunk/src/zope/app/generations/utility.py
-=-
Modified: zope.app.generations/trunk/CHANGES.txt
===================================================================
--- zope.app.generations/trunk/CHANGES.txt 2009-04-05 19:17:32 UTC (rev 98883)
+++ zope.app.generations/trunk/CHANGES.txt 2009-04-05 19:17:58 UTC (rev 98884)
@@ -5,7 +5,8 @@
3.4.3 (unreleased)
------------------
--
+- Moved ``getRootFolder`` utility method from
+ ``zope.app.zopeappgenerations`` to ``zope.app.generations.utils``.
3.4.2 (2009-01-27)
Modified: zope.app.generations/trunk/src/zope/app/generations/utility.py
===================================================================
--- zope.app.generations/trunk/src/zope/app/generations/utility.py 2009-04-05 19:17:32 UTC (rev 98883)
+++ zope.app.generations/trunk/src/zope/app/generations/utility.py 2009-04-05 19:17:58 UTC (rev 98884)
@@ -17,7 +17,9 @@
"""
__docformat__ = "reStructuredText"
+import zope.app.publication.zopepublication
+
def findObjectsMatching(root, condition):
"""Find all objects in the root that match the condition.
@@ -125,3 +127,38 @@
"""
for match in findObjectsMatching(root, interface.providedBy):
yield match
+
+
+def getRootFolder(context):
+ """Get the root folder of the ZODB.
+
+ We need some set up. Create a database:
+
+ >>> from ZODB.tests.util import DB
+ >>> from zope.app.generations.generations import Context
+ >>> db = DB()
+ >>> context = Context()
+ >>> context.connection = db.open()
+ >>> root = context.connection.root()
+
+ Add a root folder:
+
+ >>> from zope.site.folder import rootFolder
+ >>> from zope.app.publication.zopepublication import ZopePublication
+ >>> import transaction
+ >>> root[ZopePublication.root_name] = rootFolder()
+ >>> transaction.commit()
+
+ Now we can get the root folder using the function:
+
+ >>> getRootFolder(context) # doctest: +ELLIPSIS
+ <zope.site.folder.Folder object at ...>
+
+ We'd better clean up:
+
+ >>> context.connection.close()
+ >>> db.close()
+
+ """
+ return context.connection.root().get(
+ zope.app.publication.zopepublication.ZopePublication.root_name, None)
More information about the Checkins
mailing list