[Checkins] SVN: zodbupdate/trunk/src/zodbupdate/ Rename the `analyze` module to `update`.
Christian Theune
ct at gocept.com
Tue Jun 16 02:50:29 EDT 2009
Log message for revision 101033:
Rename the `analyze` module to `update`.
Changed:
D zodbupdate/trunk/src/zodbupdate/analyze.py
U zodbupdate/trunk/src/zodbupdate/main.py
U zodbupdate/trunk/src/zodbupdate/tests.py
A zodbupdate/trunk/src/zodbupdate/update.py
-=-
Deleted: zodbupdate/trunk/src/zodbupdate/analyze.py
===================================================================
--- zodbupdate/trunk/src/zodbupdate/analyze.py 2009-06-16 06:48:59 UTC (rev 101032)
+++ zodbupdate/trunk/src/zodbupdate/analyze.py 2009-06-16 06:50:28 UTC (rev 101033)
@@ -1,116 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2009 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-
-from ZODB.DB import DB
-import StringIO
-import ZODB.broken
-import ZODB.utils
-import logging
-import pickle
-import pickletools
-import sys
-import transaction
-import zodbupdate.picklefilter
-
-logger = logging.getLogger('zodbupdate')
-
-
-class Updater(object):
- """Update class references for all current objects in a storage."""
-
- def __init__(self, storage, dry=False, ignore_missing=False):
- self.ignore_missing = ignore_missing
- self.dry = dry
- self.storage = storage
- self.missing = set()
-
- def __call__(self):
- t = transaction.Transaction()
- self.storage.tpc_begin(t)
- t.note('Updated factory references using `zodbupdate`.')
-
- for oid, serial, current in self.records:
- new = self.update_record(current)
- if new == current:
- continue
- logger.debug('Updated %s' % ZODB.utils.oid_repr(oid))
- self.storage.store(oid, serial, new, '', t)
-
- if self.dry:
- logger.info('Dry run selected, aborting transaction.')
- self.storage.tpc_abort(t)
- else:
- logger.info('Committing changes.')
- self.storage.tpc_vote(t)
- self.storage.tpc_finish(t)
-
- @property
- def records(self):
- next = None
- while True:
- oid, tid, data, next = self.storage.record_iternext(next)
- yield oid, tid, StringIO.StringIO(data)
- if next is None:
- break
-
- def update_record(self, old):
- new = ''
- for i in range(2):
- # ZODB data records consist of two concatenated pickles, so the
- # following needs to be done twice:
- new += zodbupdate.picklefilter.filter(
- self.update_operation, old)
- return new
-
- def update_operation(self, code, arg):
- """Check a pickle operation for moved or missing factory references.
-
- Returns an updated (code, arg) tuple using the canonical reference for the
- factory as would be created if the pickle was unpickled and re-pickled.
-
- """
- if code not in 'ci':
- return
-
- # XXX Handle missing factories
- factory_module, factory_name = arg.split(' ')
- try:
- module = __import__(factory_module, globals(), {}, [factory_name])
- factory = getattr(module, factory_name)
- except (AttributeError, ImportError):
- name = '%s.%s' % (factory_module, factory_name)
- message = 'Missing factory: %s' % name
- logger.info(message)
- self.missing.add(name)
- if self.ignore_missing:
- return
- raise ValueError(message)
-
- if not hasattr(factory, '__name__'):
- logger.warn(
- "factory %r does not have __name__: "
- "can't check canonical location" % factory)
- return
- if not hasattr(factory, '__module__'):
- # TODO: This case isn't covered with a test. I just
- # couldn't provoke a factory to not have a __module__ but
- # users reported this issue to me.
- logger.warn(
- "factory %r does not have __module__: "
- "can't check canonical location" % factory)
- return
-
- # XXX Log for later reuse
- new_arg = '%s %s' % (factory.__module__, factory.__name__)
- return code, new_arg
Modified: zodbupdate/trunk/src/zodbupdate/main.py
===================================================================
--- zodbupdate/trunk/src/zodbupdate/main.py 2009-06-16 06:48:59 UTC (rev 101032)
+++ zodbupdate/trunk/src/zodbupdate/main.py 2009-06-16 06:50:28 UTC (rev 101033)
@@ -17,7 +17,7 @@
import logging
import optparse
import sys
-import zodbupdate.analyze
+import zodbupdate.update
parser = optparse.OptionParser(
@@ -70,7 +70,7 @@
logging.getLogger().setLevel(level)
logging.getLogger('zodbupdate').addFilter(duplicate_filter)
- updater = zodbupdate.analyze.Updater(storage,
+ updater = zodbupdate.update.Updater(storage,
dry=options.dry_run,
ignore_missing=options.ignore_missing)
try:
Modified: zodbupdate/trunk/src/zodbupdate/tests.py
===================================================================
--- zodbupdate/trunk/src/zodbupdate/tests.py 2009-06-16 06:48:59 UTC (rev 101032)
+++ zodbupdate/trunk/src/zodbupdate/tests.py 2009-06-16 06:50:28 UTC (rev 101033)
@@ -24,7 +24,7 @@
import transaction
import types
import unittest
-import zodbupdate.analyze
+import zodbupdate.update
import zodbupdate.picklefilter
@@ -39,7 +39,7 @@
class ZODBUpdateTests(unittest.TestCase):
def setUp(self):
- zodbupdate.analyze.logger.addFilter(ignore)
+ zodbupdate.update.logger.addFilter(ignore)
sys.modules['module1'] = types.ModuleType('module1')
class Factory(persistent.Persistent):
@@ -58,7 +58,7 @@
self.db.close()
self.storage = ZODB.FileStorage.FileStorage(self.dbfile)
- updater = zodbupdate.analyze.Updater(self.storage, **args)
+ updater = zodbupdate.update.Updater(self.storage, **args)
updater()
self.storage.close()
@@ -69,7 +69,7 @@
return updater
def tearDown(self):
- zodbupdate.analyze.logger.removeFilter(ignore)
+ zodbupdate.update.logger.removeFilter(ignore)
del sys.modules['module1']
self.db.close()
@@ -80,7 +80,7 @@
def test_factory_missing(self):
# Create a ZODB with an object referencing a factory, then
- # remove the factory and analyze the ZODB.
+ # remove the factory and update the ZODB.
self.root['test'] = sys.modules['module1'].Factory()
transaction.commit()
del sys.modules['module1'].Factory
@@ -89,7 +89,7 @@
def test_factory_ignore_missing(self):
# Create a ZODB with an object referencing a factory, then
- # remove the factory and analyze the ZODB.
+ # remove the factory and update the ZODB.
self.root['test'] = sys.modules['module1'].Factory()
transaction.commit()
del sys.modules['module1'].Factory
Copied: zodbupdate/trunk/src/zodbupdate/update.py (from rev 101032, zodbupdate/trunk/src/zodbupdate/analyze.py)
===================================================================
--- zodbupdate/trunk/src/zodbupdate/update.py (rev 0)
+++ zodbupdate/trunk/src/zodbupdate/update.py 2009-06-16 06:50:28 UTC (rev 101033)
@@ -0,0 +1,116 @@
+##############################################################################
+#
+# Copyright (c) 2009 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+from ZODB.DB import DB
+import StringIO
+import ZODB.broken
+import ZODB.utils
+import logging
+import pickle
+import pickletools
+import sys
+import transaction
+import zodbupdate.picklefilter
+
+logger = logging.getLogger('zodbupdate')
+
+
+class Updater(object):
+ """Update class references for all current objects in a storage."""
+
+ def __init__(self, storage, dry=False, ignore_missing=False):
+ self.ignore_missing = ignore_missing
+ self.dry = dry
+ self.storage = storage
+ self.missing = set()
+
+ def __call__(self):
+ t = transaction.Transaction()
+ self.storage.tpc_begin(t)
+ t.note('Updated factory references using `zodbupdate`.')
+
+ for oid, serial, current in self.records:
+ new = self.update_record(current)
+ if new == current:
+ continue
+ logger.debug('Updated %s' % ZODB.utils.oid_repr(oid))
+ self.storage.store(oid, serial, new, '', t)
+
+ if self.dry:
+ logger.info('Dry run selected, aborting transaction.')
+ self.storage.tpc_abort(t)
+ else:
+ logger.info('Committing changes.')
+ self.storage.tpc_vote(t)
+ self.storage.tpc_finish(t)
+
+ @property
+ def records(self):
+ next = None
+ while True:
+ oid, tid, data, next = self.storage.record_iternext(next)
+ yield oid, tid, StringIO.StringIO(data)
+ if next is None:
+ break
+
+ def update_record(self, old):
+ new = ''
+ for i in range(2):
+ # ZODB data records consist of two concatenated pickles, so the
+ # following needs to be done twice:
+ new += zodbupdate.picklefilter.filter(
+ self.update_operation, old)
+ return new
+
+ def update_operation(self, code, arg):
+ """Check a pickle operation for moved or missing factory references.
+
+ Returns an updated (code, arg) tuple using the canonical reference for the
+ factory as would be created if the pickle was unpickled and re-pickled.
+
+ """
+ if code not in 'ci':
+ return
+
+ # XXX Handle missing factories
+ factory_module, factory_name = arg.split(' ')
+ try:
+ module = __import__(factory_module, globals(), {}, [factory_name])
+ factory = getattr(module, factory_name)
+ except (AttributeError, ImportError):
+ name = '%s.%s' % (factory_module, factory_name)
+ message = 'Missing factory: %s' % name
+ logger.info(message)
+ self.missing.add(name)
+ if self.ignore_missing:
+ return
+ raise ValueError(message)
+
+ if not hasattr(factory, '__name__'):
+ logger.warn(
+ "factory %r does not have __name__: "
+ "can't check canonical location" % factory)
+ return
+ if not hasattr(factory, '__module__'):
+ # TODO: This case isn't covered with a test. I just
+ # couldn't provoke a factory to not have a __module__ but
+ # users reported this issue to me.
+ logger.warn(
+ "factory %r does not have __module__: "
+ "can't check canonical location" % factory)
+ return
+
+ # XXX Log for later reuse
+ new_arg = '%s %s' % (factory.__module__, factory.__name__)
+ return code, new_arg
Property changes on: zodbupdate/trunk/src/zodbupdate/update.py
___________________________________________________________________
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
More information about the Checkins
mailing list