[Checkins] SVN: Sandbox/ctheune/zodbupgrade/ snapshot of some work
Christian Theune
ct at gocept.com
Fri Jan 30 07:01:01 EST 2009
Log message for revision 95549:
snapshot of some work
Changed:
A Sandbox/ctheune/zodbupgrade/analyze.py
A Sandbox/ctheune/zodbupgrade/buildout.cfg
A Sandbox/ctheune/zodbupgrade/create.py
A Sandbox/ctheune/zodbupgrade/debug.py
A Sandbox/ctheune/zodbupgrade/setup.py
A Sandbox/ctheune/zodbupgrade/src/
A Sandbox/ctheune/zodbupgrade/src/klass2.py
A Sandbox/ctheune/zodbupgrade/src/klass3.py
-=-
Added: Sandbox/ctheune/zodbupgrade/analyze.py
===================================================================
--- Sandbox/ctheune/zodbupgrade/analyze.py (rev 0)
+++ Sandbox/ctheune/zodbupgrade/analyze.py 2009-01-30 12:01:01 UTC (rev 95549)
@@ -0,0 +1,71 @@
+# vim:fileencoding=utf-8
+# Copyright (c) 2008 gocept gmbh & co. kg
+# See also LICENSE.txt
+
+import sys
+import StringIO
+from ZODB.FileStorage import FileStorage
+from ZODB.DB import DB
+import ZODB.broken
+import transaction
+import pickle
+import pickletools
+import ZODB.utils
+
+SAFE_OPS = 'IJKML\x8a\x8bSTUN\x88\x89VXFG]ael)t\x85\x86\x87}dsu02(1ghjpqrRbo\x81\x80.PQ'
+KNOWN_HARD = 'ci'
+
+s = FileStorage('Data.fs')
+d = DB(s)
+c = d.open()
+r = c.root()
+
+missing_classes = set()
+oids_to_rewrite = set()
+rewrites_found = set()
+
+def find_missing_classes(oid, data):
+ # First part of the pickle: the object factory
+ for op, arg, pos in pickletools.genops(data):
+ if op.code in SAFE_OPS:
+ continue
+ elif op.code in KNOWN_HARD:
+ module_name, symbol = arg.split(' ')
+ try:
+ module = __import__(module_name, globals(), {}, [symbol])
+ factory = getattr(module, symbol)
+ except (ImportError, AttributeError):
+ missing_classes.add('%s.%s' % (module_name, symbol))
+ else:
+ if ((factory.__module__, factory.__name__) !=
+ (module_name, symbol)):
+ # The factory is reachable but it's not the
+ # canonical location. Mark object for updating.
+ rewrites_found.add(((module_name, symbol),
+ (factory.__module__, factory.__name__)))
+ oids_to_rewrite.add(oid)
+ else:
+ raise ValueError('Unknown pickle opcode %r' % op.code)
+
+next = None
+while True:
+ oid, tid, data, next = s.record_iternext(next)
+ pickle_data = StringIO.StringIO(data)
+ find_missing_classes(oid, pickle_data)
+ find_missing_classes(oid, pickle_data)
+ if next is None:
+ break
+
+if missing_classes:
+ print "The following classes are missing:"
+ for class_ in sorted(missing_classes):
+ print class_
+else:
+ print "All classes found."
+ print "%s moved classes detected, will update %s objects" % (len(rewrites_found), len(oids_to_rewrite))
+ for (old_mod, old_name), (new_mod, new_name) in rewrites_found:
+ print "%s.%s -> %s.%s" % (old_mod, old_name, new_mod, new_name)
+ for oid in oids_to_rewrite:
+ obj = c.get(oid)
+ obj._p_changed = True
+ transaction.commit()
Property changes on: Sandbox/ctheune/zodbupgrade/analyze.py
___________________________________________________________________
Added: svn:eol-style
+ native
Added: Sandbox/ctheune/zodbupgrade/buildout.cfg
===================================================================
--- Sandbox/ctheune/zodbupgrade/buildout.cfg (rev 0)
+++ Sandbox/ctheune/zodbupgrade/buildout.cfg 2009-01-30 12:01:01 UTC (rev 95549)
@@ -0,0 +1,17 @@
+[buildout]
+develop = .
+parts = py py2 tags
+
+[tags]
+recipe = z3c.recipe.tag:tags
+eggs = zodbupgrade
+
+[py2]
+recipe = zc.recipe.egg
+eggs = ZODB3==3.8.1
+interpreter = py2
+
+[py]
+recipe = zc.recipe.egg
+eggs = zodbupgrade
+interpreter = py
Added: Sandbox/ctheune/zodbupgrade/create.py
===================================================================
--- Sandbox/ctheune/zodbupgrade/create.py (rev 0)
+++ Sandbox/ctheune/zodbupgrade/create.py 2009-01-30 12:01:01 UTC (rev 95549)
@@ -0,0 +1,20 @@
+# vim:fileencoding=utf-8
+# Copyright (c) 2008 gocept gmbh & co. kg
+# See also LICENSE.txt
+
+from ZODB.FileStorage import FileStorage
+from ZODB.DB import DB
+
+s = FileStorage('Data.fs')
+d = DB(s)
+c = d.open()
+r = c.root()
+
+import klass
+
+r['foo'] = klass.P1()
+r['foo'].x = klass.P2()
+
+import transaction
+transaction.commit()
+
Property changes on: Sandbox/ctheune/zodbupgrade/create.py
___________________________________________________________________
Added: svn:eol-style
+ native
Added: Sandbox/ctheune/zodbupgrade/debug.py
===================================================================
--- Sandbox/ctheune/zodbupgrade/debug.py (rev 0)
+++ Sandbox/ctheune/zodbupgrade/debug.py 2009-01-30 12:01:01 UTC (rev 95549)
@@ -0,0 +1,12 @@
+# vim:fileencoding=utf-8
+# Copyright (c) 2008 gocept gmbh & co. kg
+# See also LICENSE.txt
+
+from ZODB.FileStorage import FileStorage
+from ZODB.DB import DB
+
+s = FileStorage('Data.fs')
+d = DB(s)
+c = d.open()
+r = c.root()
+
Property changes on: Sandbox/ctheune/zodbupgrade/debug.py
___________________________________________________________________
Added: svn:eol-style
+ native
Added: Sandbox/ctheune/zodbupgrade/setup.py
===================================================================
--- Sandbox/ctheune/zodbupgrade/setup.py (rev 0)
+++ Sandbox/ctheune/zodbupgrade/setup.py 2009-01-30 12:01:01 UTC (rev 95549)
@@ -0,0 +1,17 @@
+# vim:fileencoding=utf-8
+# Copyright (c) 2008 gocept gmbh & co. kg
+# See also LICENSE.txt
+
+from setuptools import setup, find_packages
+
+
+setup(name='zodbupgrade',
+ version='0',
+ package_dir={'': 'src'},
+ packages=find_packages('src'),
+ include_package_data=True,
+ install_requires=[
+ 'ZODB3==3.8.1',
+ 'setuptools'
+ ],
+ )
Property changes on: Sandbox/ctheune/zodbupgrade/setup.py
___________________________________________________________________
Added: svn:eol-style
+ native
Added: Sandbox/ctheune/zodbupgrade/src/klass2.py
===================================================================
--- Sandbox/ctheune/zodbupgrade/src/klass2.py (rev 0)
+++ Sandbox/ctheune/zodbupgrade/src/klass2.py 2009-01-30 12:01:01 UTC (rev 95549)
@@ -0,0 +1,10 @@
+# vim:fileencoding=utf-8
+# Copyright (c) 2008 gocept gmbh & co. kg
+# See also LICENSE.txt
+
+import persistent
+from klass3 import P1Replacement as P1
+
+
+class P2(object):
+ pass
Property changes on: Sandbox/ctheune/zodbupgrade/src/klass2.py
___________________________________________________________________
Added: svn:eol-style
+ native
Added: Sandbox/ctheune/zodbupgrade/src/klass3.py
===================================================================
--- Sandbox/ctheune/zodbupgrade/src/klass3.py (rev 0)
+++ Sandbox/ctheune/zodbupgrade/src/klass3.py 2009-01-30 12:01:01 UTC (rev 95549)
@@ -0,0 +1,8 @@
+# vim:fileencoding=utf-8
+# Copyright (c) 2008 gocept gmbh & co. kg
+# See also LICENSE.txt
+
+import persistent
+
+class P1Replacement(persistent.Persistent):
+ pass
Property changes on: Sandbox/ctheune/zodbupgrade/src/klass3.py
___________________________________________________________________
Added: svn:eol-style
+ native
More information about the Checkins
mailing list