[ZODB-Dev] Merge request: ZODB/branches/tseaver-better_repozo_tests
Tres Seaver
tseaver at palladion.com
Fri May 14 13:57:50 EDT 2010
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Tres Seaver wrote:
> Log message for revision 112305:
> Hooks for testability:
>
> Raise an exception from 'do_full_backup' / 'do_incremental_backup' where
> we would have called sys.exit(2) to avoid overwriting files. Catch the
> exception in 'main' and do the same error reporting / exit.
>
> Allow the 'options' object to pre-set the time used for generating the
> backup filenames.
>
>
> Changed:
> U ZODB/branches/tseaver-better_repozo_tests/src/ZODB/scripts/repozo.py
>
> -=-
> Modified: ZODB/branches/tseaver-better_repozo_tests/src/ZODB/scripts/repozo.py
> ===================================================================
> --- ZODB/branches/tseaver-better_repozo_tests/src/ZODB/scripts/repozo.py 2010-05-14 17:35:52 UTC (rev 112304)
> +++ ZODB/branches/tseaver-better_repozo_tests/src/ZODB/scripts/repozo.py 2010-05-14 17:43:39 UTC (rev 112305)
> @@ -93,6 +93,9 @@
> VERBOSE = False
>
>
> +class WouldOverwriteFiles(Exception):
> + pass
> +
> def usage(code, msg=''):
> outfp = sys.stderr
> if code == 0:
> @@ -301,7 +304,9 @@
> ext = '.deltafs'
> if options.gzip:
> ext += 'z'
> - t = time.gmtime()[:6] + (ext,)
> + # Hook for testing
> + now = getattr(options, 'test_now', time.gmtime()[:6])
> + t = now + (ext,)
> return '%04d-%02d-%02d-%02d-%02d-%02d%s' % t
>
> # Return a list of files needed to reproduce state at time options.date.
> @@ -419,8 +424,7 @@
> options.full = True
> dest = os.path.join(options.repository, gen_filename(options))
> if os.path.exists(dest):
> - print >> sys.stderr, 'Cannot overwrite existing file:', dest
> - sys.exit(2)
> + raise WouldOverwriteFiles('Cannot overwrite existing file: %s' % dest)
> log('writing full backup: %s bytes to %s', pos, dest)
> sum = copyfile(options, dest, 0, pos)
> # Write the data file for this full backup
> @@ -447,8 +451,7 @@
> options.full = False
> dest = os.path.join(options.repository, gen_filename(options))
> if os.path.exists(dest):
> - print >> sys.stderr, 'Cannot overwrite existing file:', dest
> - sys.exit(2)
> + raise WouldOverwriteFiles('Cannot overwrite existing file: %s' % dest)
> log('writing incremental: %s bytes to %s', pos-reposz, dest)
> sum = copyfile(options, dest, reposz, pos - reposz)
> # The first file in repofiles points to the last full backup. Use this to
> @@ -570,7 +573,11 @@
> argv = sys.argv[1:]
> options = parseargs(argv)
> if options.mode == BACKUP:
> - do_backup(options)
> + try:
> + do_backup(options)
> + except WouldOverwriteFiles, e:
> + print >> sys.stderr, str(e)
> + sys.exit(2)
> else:
> assert options.mode == RECOVER
> do_recover(options)
Jim, would you please review and merge the 'tseaver-better_repozo_tests'
branch to the ZODB trunk? The only non-test change is the one I'm
replying to, which is intended purely to make stuff more unit testable.
Once this merges, I can do the "index saving" work on top of the new tests.
Tres.
- --
===================================================================
Tres Seaver +1 540-429-0999 tseaver at palladion.com
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkvtjxoACgkQ+gerLs4ltQ7HYgCfU3DBrVQZXQMX0Qgz1YwdLo/T
44cAmwVHWlVvfKGH4miQe4nnxFc82Yd7
=7SLd
-----END PGP SIGNATURE-----
More information about the ZODB-Dev
mailing list