[Checkins] SVN: zodbupdate/trunk/src/zodbupdate/ - add option for saving renames into a file

Christian Theune ct at gocept.com
Tue Jun 16 03:33:15 EDT 2009


Log message for revision 101039:
  - add option for saving renames into a file
  - add option for verbose output
  - verbose output displays exceptions with traceback if raised during update
    run
  - configure logging early to allow storage logging to appear in verbose mode
  

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	2009-06-16 07:18:42 UTC (rev 101038)
+++ zodbupdate/trunk/src/zodbupdate/main.py	2009-06-16 07:33:15 UTC (rev 101039)
@@ -28,10 +28,14 @@
                   help="load storage from config file")
 parser.add_option("-n", "--dry-run", action="store_true",
                   help="perform a trial run with no changes made")
-parser.add_option("--ignore-missing", action="store_true",
+parser.add_option("-i", "--ignore-missing", action="store_true",
                   help="update database even if classes are missing")
+parser.add_option("-s", "--save-renames",
+                  help="save automatically determined rename rules to file")
 parser.add_option("-q", "--quiet", action="store_true",
                   help="suppress non-error messages")
+parser.add_option("-v", "--verbose", action="store_true",
+                  help="more verbose output")
 
 class DuplicateFilter(object):
 
@@ -50,6 +54,17 @@
 def main():
     options, args = parser.parse_args()
 
+    if options.quiet:
+        level = logging.ERROR
+    elif options.verbose:
+        level = logging.DEBUG
+    else:
+        level = logging.INFO
+
+    logging.getLogger().addHandler(logging.StreamHandler())
+    logging.getLogger().setLevel(level)
+    logging.getLogger('zodbupdate').addFilter(duplicate_filter)
+
     if options.file and options.config:
         raise SystemExit(
             'Exactly one of --file or --config must be given.')
@@ -62,18 +77,17 @@
         raise SystemExit(
             'Exactly one of --file or --config must be given.')
 
-    if options.quiet:
-        level = logging.ERROR
-    else:
-        level = logging.INFO
-    logging.getLogger().addHandler(logging.StreamHandler())
-    logging.getLogger().setLevel(level)
-    logging.getLogger('zodbupdate').addFilter(duplicate_filter)
-
-    updater = zodbupdate.update.Updater(storage,
-                                          dry=options.dry_run,
-                                          ignore_missing=options.ignore_missing)
+    updater = zodbupdate.update.Updater(
+        storage, dry=options.dry_run, ignore_missing=options.ignore_missing)
     try:
         updater()
     except Exception, e:
+        logging.debug('An error occured', exc_info=True)
         logging.error('Stopped processing, due to: %s' % e)
+        raise SystemExit()
+
+    if options.save_renames:
+        f = open(options.save_renames, 'w')
+        for key, value in sorted(updater.renames.items()):
+            f.write('%s,%s\n' % (key, value))
+        f.close()

Modified: zodbupdate/trunk/src/zodbupdate/update.py
===================================================================
--- zodbupdate/trunk/src/zodbupdate/update.py	2009-06-16 07:18:42 UTC (rev 101038)
+++ zodbupdate/trunk/src/zodbupdate/update.py	2009-06-16 07:33:15 UTC (rev 101039)
@@ -34,6 +34,7 @@
         self.dry = dry
         self.storage = storage
         self.missing = set()
+        self.renames = {}
 
     def __call__(self):
         t = transaction.Transaction()
@@ -83,7 +84,10 @@
         if code not in 'ci':
             return
 
-        # XXX Handle missing factories
+        if arg in self.renames:
+            # XXX missing testcase
+            return code, self.renames[arg]
+
         factory_module, factory_name = arg.split(' ')
         try:
             module = __import__(factory_module, globals(), {}, [factory_name])
@@ -111,6 +115,7 @@
                 "can't check canonical location" % factory)
             return
 
-        # XXX Log for later reuse
         new_arg = '%s %s' % (factory.__module__, factory.__name__)
+        if new_arg != arg:
+            self.renames[arg] = new_arg
         return code, new_arg



More information about the Checkins mailing list