[Checkins] SVN: zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/ Collect implicit renaming rules.
Sylvain Viollon
sylvain at infrae.com
Tue Jan 5 10:50:46 EST 2010
Log message for revision 107709:
Collect implicit renaming rules.
Changed:
U zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/main.py
U zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/serialize.py
U zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/update.py
-=-
Modified: zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/main.py
===================================================================
--- zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/main.py 2010-01-05 15:48:26 UTC (rev 107708)
+++ zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/main.py 2010-01-05 15:50:46 UTC (rev 107709)
@@ -65,7 +65,7 @@
if options.file and options.config:
raise SystemExit(
- 'Exactly one of --file or --config must be given.')
+ u'Exactly one of --file or --config must be given.')
if options.file:
storage = ZODB.FileStorage.FileStorage(options.file)
@@ -73,13 +73,13 @@
storage = ZODB.config.storageFromURL(options.config)
else:
raise SystemExit(
- 'Exactly one of --file or --config must be given.')
+ u'Exactly one of --file or --config must be given.')
rename_rules = {}
for entry_point in pkg_resources.iter_entry_points('zodbupdate'):
rules = entry_point.load()
rename_rules.update(rules)
- logging.info('Loaded %s rules from %s:%s' %
+ logging.info(u'Loaded %s rules from %s:%s' %
(len(rules), entry_point.module_name, entry_point.name))
updater = zodbupdate.update.Updater(
@@ -88,8 +88,12 @@
try:
updater()
except Exception, e:
- logging.debug('An error occured', exc_info=True)
- logging.error('Stopped processing, due to: %s' % e)
+ logging.debug(u'An error occured', exc_info=True)
+ logging.error(u'Stopped processing, due to: %s' % e)
raise SystemExit()
+ implicit_renames = updater.processor.get_found_implicit_rules()
+ if implicit_renames:
+ print 'Found new rules:'
+ print pprint.pformat(implicit_renames)
storage.close()
Modified: zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/serialize.py
===================================================================
--- zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/serialize.py 2010-01-05 15:48:26 UTC (rev 107708)
+++ zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/serialize.py 2010-01-05 15:50:46 UTC (rev 107709)
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2009 Zope Corporation and Contributors.
+# Copyright (c) 2009-2010 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
@@ -12,11 +12,15 @@
#
##############################################################################
-from ZODB.broken import find_global
+from ZODB.broken import find_global, Broken
import cPickle
import cStringIO
+import logging
+import types
+logger = logging.getLogger('zodbupdate')
+
class ZODBReference:
"""Class to remenber reference we don't want to touch.
"""
@@ -37,21 +41,45 @@
"""
def __init__(self, changes):
+ self.__added = dict()
self.__changes = dict()
for old, new in changes.iteritems():
self.__changes[tuple(old.split(' '))] = tuple(new.split(' '))
self.__changed = False
- def __find_global(self, *names):
+ def __update_symb(self, symb_info):
+ """This method look in a klass or symbol have been renamed or
+ not. If the symbol have not been renamed explicitly, it's
+ loaded and its location is checked to see if it have moved as
+ well.
+ """
+ if symb_info in self.__changes:
+ self.__changed = True
+ return self.__changes[symb_info]
+ else:
+ symb = find_global(*symb_info)
+ if isinstance(symb, types.ClassType) and issubclass(symb, Broken):
+ logger.warning(u'Warning: Missing factory for %s' %
+ u' '.join(symb_info))
+ elif hasattr(symb, '__name__') and hasattr(symb, '__module__'):
+ new_symb_info = (symb.__module__, symb.__name__)
+ if new_symb_info != symb_info:
+ logger.info(
+ u'New implicit rule detected %s to %s' %
+ (u' '.join(symb_info), u' '.join(new_symb_info)))
+ self.__changes[symb_info] = new_symb_info
+ self.__added[symb_info] = new_symb_info
+ self.__changed = True
+ return new_symb_info
+ return symb_info
+
+ def __find_global(self, *klass_info):
"""Find a class with the given name, looking for a renaming
rule first.
Using ZODB find_global let us manage missing classes.
"""
- if names in self.__changes:
- names = self.__changes[names]
- self.__changed = True
- return find_global(*names)
+ return find_global(*self.__update_symb(klass_info))
def __persistent_load(self, reference):
"""Load a persistent reference. The reference might changed
@@ -60,11 +88,10 @@
by the reference.
"""
if isinstance(reference, tuple):
- oid, klass = reference
- if klass in self.__changes:
- klass = self.__changes[klass]
- self.__changed = True
- return ZODBReference((oid, klass))
+ oid, klass_info = reference
+ if isinstance(klass_info, tuple):
+ klass_info = self.__update_symb(klass_info)
+ return ZODBReference((oid, klass_info))
# TODO multidatabase ['m'], (database, oid, klass)
return ZODBReference(reference)
@@ -98,11 +125,9 @@
about a renamed class.
"""
if isinstance(class_meta, tuple):
- klass, args = class_meta
- if isinstance(klass, tuple):
- if klass in self.__changes:
- self.__changed = True
- return self.__changes[klass], args
+ klass_info, args = class_meta
+ if isinstance(klass_info, tuple):
+ return self.__update_symb(klass_info), args
return class_meta
def rename(self, input_file):
@@ -129,3 +154,9 @@
output_file.truncate()
return output_file
+
+ def get_found_implicit_rules(self):
+ result = {}
+ for old, new in self.__added.items():
+ result[' '.join(old)] = ' '.join(new)
+ return result
Modified: zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/update.py
===================================================================
--- zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/update.py 2010-01-05 15:48:26 UTC (rev 107708)
+++ zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/update.py 2010-01-05 15:50:46 UTC (rev 107709)
@@ -36,7 +36,7 @@
def __init__(self, storage, dry=False, renames=None):
self.dry = dry
self.storage = storage
- self.update = zodbupdate.serialize.ObjectRenamer(renames or {})
+ self.processor = zodbupdate.serialize.ObjectRenamer(renames or {})
def __new_transaction(self):
t = transaction.Transaction()
@@ -58,7 +58,7 @@
t = self.__new_transaction()
for oid, serial, current in self.records:
- new = self.update.rename(current)
+ new = self.processor.rename(current)
if new is None:
continue
@@ -85,7 +85,7 @@
data, tid = self.storage.load(oid, "")
except ZODB.POSException.POSKeyError, e:
logger.error(
- u'Error: Jumping record %s, '
+ u'Warning: Jumping record %s, '
u'referencing missing key in database: %s' %
(ZODB.utils.oid_repr(oid), str(e)))
else:
More information about the checkins
mailing list