Skip to content

Commit

Permalink
Merge 5bdd0ed into a6df4b0
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Aug 22, 2019
2 parents a6df4b0 + 5bdd0ed commit 8483d84
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions CHANGES.rst
Expand Up @@ -3,8 +3,8 @@ Changes

1.4 (unreleased)
----------------

- Nothing changed yet.
- Fail with explanation when opening a Python 2 ZODB with --dry-run on Python 3
(`#22 <https://github.com/zopefoundation/zodbupdate/issues/22>`_)


1.3 (2019-07-30)
Expand Down
12 changes: 11 additions & 1 deletion buildout.cfg
@@ -1,6 +1,9 @@
[buildout]
develop = .
parts = zodbupdate test
parts =
zodbupdate
scripts
test

[test]
recipe = zc.recipe.testrunner
Expand All @@ -9,3 +12,10 @@ eggs = zodbupdate[test]
[zodbupdate]
recipe = zc.recipe.egg
eggs = zodbupdate

[scripts]
recipe = zc.recipe.egg
eggs =
tox
scripts =
tox
7 changes: 7 additions & 0 deletions src/zodbupdate/main.py
Expand Up @@ -192,6 +192,13 @@ def main():
# doesn't complain.
if args.convert_py3 and six.PY3 and not args.dry_run:
zodbupdate.convert.update_magic_data_fs(args.file)
elif args.convert_py3 and six.PY3 and args.dry_run:
zodb_magic = zodbupdate.utils.get_zodb_magic(args.file)
if zodb_magic != ZODB.FileStorage.packed_version:
raise AssertionError(
'You cannot use --dry-run under Python 3 with a ZODB '
'created under Python 2 as --dry-run does not rewrite the '
'magic header data before opening the ZODB file.')

if args.file:
storage = ZODB.FileStorage.FileStorage(args.file)
Expand Down
6 changes: 6 additions & 0 deletions src/zodbupdate/utils.py
Expand Up @@ -93,3 +93,9 @@ def safe_binary(value):
if isinstance(value, six.text_type):
return zodbpickle.binary(value.encode(ENCODING))
return value


def get_zodb_magic(filepath):
""" Read the first four bytes of a ZODB file to get its magic """
with open(filepath, 'rb') as fp:
return fp.read(4)

0 comments on commit 8483d84

Please sign in to comment.