[Checkins] SVN: zc.fsutil/branches/dev/src/zc/fsutil/fixup.py
Checkng in an adaptation of a working script for fixing up an
old Zope
Jim Fulton
jim at zope.com
Thu Sep 27 14:57:57 EDT 2007
Log message for revision 80247:
Checkng in an adaptation of a working script for fixing up an old Zope
database. This was done with ZODB 3.2. I made changes for current
ZODB, but these are untested. Tests wouldn't be hard to right...
Changed:
A zc.fsutil/branches/dev/src/zc/fsutil/fixup.py
-=-
Added: zc.fsutil/branches/dev/src/zc/fsutil/fixup.py
===================================================================
--- zc.fsutil/branches/dev/src/zc/fsutil/fixup.py (rev 0)
+++ zc.fsutil/branches/dev/src/zc/fsutil/fixup.py 2007-09-27 18:57:56 UTC (rev 80247)
@@ -0,0 +1,55 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Fixup missing oids by copying them froma backup.
+
+XXX untested
+"""
+
+import ZODB.POSException
+import ZODB.serialize
+import transaction()
+
+def fixup_what(oids, src, dest, result=None, seen=None):
+ if result is None:
+ result = []
+ seen = {}
+
+ for oid in oids:
+ if oid in seen:
+ continue
+ seen[oid] = 1
+
+ # See if it is already in the dest:
+ try:
+ dest.load(oid, '')
+ except ZODB.POSException.POSKeyError:
+ pass
+ else:
+ # Already there. Skip
+ continue
+
+ pickle, s = src.load(oid, '')
+ result.append((oid, pickle))
+ fixup_what(ZODB.serialize.referencesf(pickle), src, dest,
+ result, seen)
+
+ return result
+
+def fixup(oids, src, dest):
+ t = transaction.begin()
+ dest.tpc_begin(t)
+ for oid, pickle in fixup_what(oids, src, dest):
+ dest.store(oid, '\0'*8, pickle, '', t)
+ dest.tpc_vote(t)
+ dest.tpc_finish(t)
Property changes on: zc.fsutil/branches/dev/src/zc/fsutil/fixup.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
More information about the Checkins
mailing list