[Checkins] SVN: zodbupdate/trunk/src/zodbupdate/ Add an option do debug pickling/unpickling of classes, and a skip records.

Sylvain Viollon sylvain at infrae.com
Tue Jun 8 10:44:45 EDT 2010


Log message for revision 113279:
  Add an option do debug pickling/unpickling of classes, and a skip records.
  
  

Changed:
  U   zodbupdate/trunk/src/zodbupdate/main.py
  U   zodbupdate/trunk/src/zodbupdate/update.py

-=-
Modified: zodbupdate/trunk/src/zodbupdate/main.py
===================================================================
--- zodbupdate/trunk/src/zodbupdate/main.py	2010-06-08 14:17:51 UTC (rev 113278)
+++ zodbupdate/trunk/src/zodbupdate/main.py	2010-06-08 14:44:45 UTC (rev 113279)
@@ -36,7 +36,12 @@
                   help="suppress non-error messages")
 parser.add_option("-v", "--verbose", action="store_true",
                   help="more verbose output")
+parser.add_option("-o", "--oid",
+                  help="start with provided oid in hex format, ex: 0xaa1203")
+parser.add_option("-d", "--debug", action="store_true",
+                  help="post mortem pdb on failure")
 
+
 class DuplicateFilter(object):
 
     def __init__(self):
@@ -77,6 +82,10 @@
         raise SystemExit(
             u'Exactly one of --file or --config must be given.')
 
+    start_at = '0x00'
+    if options.oid:
+        start_at = options.oid
+
     rename_rules = {}
     for entry_point in pkg_resources.iter_entry_points('zodbupdate'):
         rules = entry_point.load()
@@ -85,8 +94,11 @@
                       (len(rules), entry_point.module_name, entry_point.name))
 
     updater = zodbupdate.update.Updater(
-        storage, dry=options.dry_run,
-        renames=rename_rules)
+        storage,
+        dry=options.dry_run,
+        renames=rename_rules,
+        start_at=start_at,
+        debug=options.debug)
 
     try:
         updater()

Modified: zodbupdate/trunk/src/zodbupdate/update.py
===================================================================
--- zodbupdate/trunk/src/zodbupdate/update.py	2010-06-08 14:17:51 UTC (rev 113278)
+++ zodbupdate/trunk/src/zodbupdate/update.py	2010-06-08 14:44:45 UTC (rev 113279)
@@ -34,10 +34,13 @@
 class Updater(object):
     """Update class references for all current objects in a storage."""
 
-    def __init__(self, storage, dry=False, renames=None):
+    def __init__(self, storage, dry=False, renames=None,
+                 start_at='0x00', debug=False):
         self.dry = dry
         self.storage = storage
         self.processor = zodbupdate.serialize.ObjectRenamer(renames or {})
+        self.start_at = start_at
+        self.debug = debug
 
     def __new_transaction(self):
         t = transaction.Transaction()
@@ -55,31 +58,39 @@
             self.storage.tpc_finish(t)
 
     def __call__(self):
-        count = 0
-        t = self.__new_transaction()
+        try:
+            count = 0
+            t = self.__new_transaction()
 
-        for oid, serial, current in self.records:
-            new = self.processor.rename(current)
-            if new is None:
-                continue
+            for oid, serial, current in self.records:
+                new = self.processor.rename(current)
+                if new is None:
+                    continue
 
-            logger.debug('Updated %s' % ZODB.utils.oid_repr(oid))
-            self.storage.store(oid, serial, new.getvalue(), '', t)
-            count += 1
+                logger.debug('Updated %s' % ZODB.utils.oid_repr(oid))
+                self.storage.store(oid, serial, new.getvalue(), '', t)
+                count += 1
 
-            if count > TRANSACTION_COUNT:
-                count = 0
-                self.__commit_transaction(t, True)
-                t = self.__new_transaction()
+                if count > TRANSACTION_COUNT:
+                    count = 0
+                    self.__commit_transaction(t, True)
+                    t = self.__new_transaction()
 
-        self.__commit_transaction(t, count != 0)
+            self.__commit_transaction(t, count != 0)
+        except (Exception,), e:
+            if not self.debug:
+                raise e
+            import sys, pdb
+            (type, value, traceback) = sys.exc_info()
+            pdb.post_mortem(traceback)
+            del traceback
+            raise e
 
-
     @property
     def records(self):
+        next = ZODB.utils.repr_to_oid(self.start_at)
         if not isinstance(self.storage, FileStorage):
             # Only FileStorage as _index (this is not an API defined attribute)
-            next = None
             while True:
                 oid, tid, data, next = self.storage.record_iternext(next)
                 yield oid, tid, cStringIO.StringIO(data)
@@ -87,10 +98,9 @@
                     break
         else:
             index = self.storage._index
-            next_oid = None
 
             while True:
-                oid = index.minKey(next_oid)
+                oid = index.minKey(next)
                 try:
                     data, tid = self.storage.load(oid, "")
                 except ZODB.POSException.POSKeyError, e:
@@ -102,9 +112,9 @@
                     yield  oid, tid, cStringIO.StringIO(data)
 
                 oid_as_long, = unpack(">Q", oid)
-                next_oid = pack(">Q", oid_as_long + 1)
+                next = pack(">Q", oid_as_long + 1)
                 try:
-                    next_oid = index.minKey(next_oid)
+                    next = index.minKey(next)
                 except ValueError:
                     # No more records
                     break



More information about the checkins mailing list