[Zodb-checkins] SVN: ZODB/branches/tseaver-better_repozo_tests/src/ZODB/scripts/repozo.py Hooks for testability:
Tres Seaver
tseaver at palladion.com
Fri May 14 13:43:39 EDT 2010
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)
More information about the Zodb-checkins
mailing list