[Zodb-checkins] SVN: ZODB/trunk/src/ZODB/scripts/ Added a utility
module for getting object-referrer information.
Jim Fulton
jim at zope.com
Wed Dec 20 13:12:48 EST 2006
Log message for revision 71630:
Added a utility module for getting object-referrer information.
It isn't actually a script but it is used in the same spirit. Maybe
it will be a script someday.
Changed:
A ZODB/trunk/src/ZODB/scripts/referrers.py
A ZODB/trunk/src/ZODB/scripts/referrers.txt
A ZODB/trunk/src/ZODB/scripts/tests.py
-=-
Added: ZODB/trunk/src/ZODB/scripts/referrers.py
===================================================================
--- ZODB/trunk/src/ZODB/scripts/referrers.py 2006-12-20 17:44:25 UTC (rev 71629)
+++ ZODB/trunk/src/ZODB/scripts/referrers.py 2006-12-20 18:12:47 UTC (rev 71630)
@@ -0,0 +1,30 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Compute a table of object id referrers
+
+$Id$
+"""
+
+from ZODB.serialize import referencesf
+
+def referrers(storage):
+ result = {}
+ for transaction in storage.iterator():
+ for record in transaction:
+ for oid in referencesf(record.data):
+ result.setdefault(oid, []).append((record.oid, record.tid))
+ return result
+
+
+
Property changes on: ZODB/trunk/src/ZODB/scripts/referrers.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: ZODB/trunk/src/ZODB/scripts/referrers.txt
===================================================================
--- ZODB/trunk/src/ZODB/scripts/referrers.txt 2006-12-20 17:44:25 UTC (rev 71629)
+++ ZODB/trunk/src/ZODB/scripts/referrers.txt 2006-12-20 18:12:47 UTC (rev 71630)
@@ -0,0 +1,40 @@
+Getting Object Referrers
+========================
+
+The referrers module provides a way to get object referrers. It
+provides a referrers method that takes an iterable storage object. It
+returns a dictionary mapping object ids to lists of referrer object
+versions, which each version is a tuple an object id nd serial
+nummber.
+
+To see how this works, we'll create a small database:
+
+ >>> import transaction
+ >>> from persistent.mapping import PersistentMapping
+ >>> from ZODB.FileStorage import FileStorage
+ >>> from ZODB.DB import DB
+ >>> import os, tempfile
+ >>> dest = tempfile.mkdtemp()
+ >>> fs = FileStorage(os.path.join(dest, 'Data.fs'))
+ >>> db = DB(fs)
+ >>> conn = db.open()
+ >>> conn.root()['a'] = PersistentMapping()
+ >>> conn.root()['b'] = PersistentMapping()
+ >>> transaction.commit()
+ >>> roid = conn.root()._p_oid
+ >>> aoid = conn.root()['a']._p_oid
+ >>> boid = conn.root()['b']._p_oid
+ >>> s1 = conn.root()['b']._p_serial
+
+ >>> conn.root()['a']['b'] = conn.root()['b']
+ >>> transaction.commit()
+ >>> s2 = conn.root()['a']._p_serial
+
+Now we'll get the storage and compute the referrers:
+
+ >>> import ZODB.scripts.referrers
+ >>> referrers = ZODB.scripts.referrers.referrers(fs)
+
+ >>> referrers[boid] == [(roid, s1), (aoid, s2)]
+ True
+
Property changes on: ZODB/trunk/src/ZODB/scripts/referrers.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: ZODB/trunk/src/ZODB/scripts/tests.py
===================================================================
--- ZODB/trunk/src/ZODB/scripts/tests.py 2006-12-20 17:44:25 UTC (rev 71629)
+++ ZODB/trunk/src/ZODB/scripts/tests.py 2006-12-20 18:12:47 UTC (rev 71630)
@@ -0,0 +1,25 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""XXX short summary goes here.
+
+$Id$
+"""
+import unittest
+from zope.testing import doctest
+
+def test_suite():
+ return unittest.TestSuite((
+ doctest.DocFileSuite('referrers.txt'),
+ ))
+
Property changes on: ZODB/trunk/src/ZODB/scripts/tests.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
More information about the Zodb-checkins
mailing list