[Checkins] SVN: Sandbox/ctheune/zodbupgrade/src/zodbupgrade/analyze.py - Rename classes to factories

Christian Theune ct at gocept.com
Fri May 29 02:58:29 EDT 2009


Log message for revision 100529:
  - Rename classes to factories
  - Handle factories which don't know their name gracefully, but provide a
    warning.
  - Only log progress message every 5k objects.
  

Changed:
  U   Sandbox/ctheune/zodbupgrade/src/zodbupgrade/analyze.py

-=-
Modified: Sandbox/ctheune/zodbupgrade/src/zodbupgrade/analyze.py
===================================================================
--- Sandbox/ctheune/zodbupgrade/src/zodbupgrade/analyze.py	2009-05-29 05:59:19 UTC (rev 100528)
+++ Sandbox/ctheune/zodbupgrade/src/zodbupgrade/analyze.py	2009-05-29 06:58:28 UTC (rev 100529)
@@ -40,7 +40,7 @@
         - factories whose dotted name could not be imported (an iterable)
 
     """
-    missing_classes = set()
+    missing_factories = set()
     rewrites_found = dict()
     for op, arg, pos in pickletools.genops(pickle):
         if op.code in SAFE_OPS:
@@ -51,9 +51,13 @@
                 module = __import__(module_name, globals(), {}, [symbol])
                 factory = getattr(module, symbol)
             except (ImportError, AttributeError):
-                missing_classes.add('%s.%s' % (module_name, symbol))
+                missing_factories.add('%s.%s' % (module_name, symbol))
             else:
                 # XXX Special case broken objects. They don't have __module__
+                if not hasattr(factory, '__name__'):
+                    logging.warn(
+                        "factory %r does not have __name__, can't check canonical location" % factory)
+                    continue
                 if ((factory.__module__, factory.__name__) !=
                     (module_name, symbol)):
                     # The factory is reachable but it's not the
@@ -62,7 +66,7 @@
                         factory.__module__, factory.__name__)
         else:
             raise ValueError('Unknown pickle opcode %r' % op.code)
-    return rewrites_found, missing_classes
+    return rewrites_found, missing_factories
 
 
 def analyze_storage(storage):
@@ -83,7 +87,7 @@
         count += 1
         pickle_data = StringIO.StringIO(data)
 
-        if not count % 1000:
+        if not count % 5000:
             logger.info(
                 'Analyzed %i objects. Found %i moved classes and %i missing '
                 'classes so far.' % (count, len(rewrites_found), len(missing_classes)))



More information about the Checkins mailing list