[Zodb-checkins] SVN: ZODB/trunk/src/ZODB/scripts/ merge from 3.9 branch:

Chris Withers chris at simplistix.co.uk
Thu Nov 19 16:12:05 EST 2009


Log message for revision 105889:
  merge from 3.9 branch:
  - make testrepozo.py runnable from a buildout setup
  - fix deprecation warning from repozo.py under Python 2.6

Changed:
  U   ZODB/trunk/src/ZODB/scripts/manual_tests/testrepozo.py
  U   ZODB/trunk/src/ZODB/scripts/repozo.py

-=-
Modified: ZODB/trunk/src/ZODB/scripts/manual_tests/testrepozo.py
===================================================================
--- ZODB/trunk/src/ZODB/scripts/manual_tests/testrepozo.py	2009-11-19 21:08:58 UTC (rev 105888)
+++ ZODB/trunk/src/ZODB/scripts/manual_tests/testrepozo.py	2009-11-19 21:12:04 UTC (rev 105889)
@@ -19,6 +19,16 @@
 its home directory as the current directory.  It will destroy all files
 matching Data.* and Copy.* in this directory, and anything in a
 subdirectory of name 'backup'.
+
+Usage:
+
+python testrepozo.py [repozo_script]
+
+  repozo_script, if provided, is a path to a script that runs repozo,
+  such as that generated by buildout.
+
+eg:
+$ ../../../../bin/py testrepozo.py ../../../../bin/repozo
 """
 
 import os
@@ -32,8 +42,6 @@
 from ZODB import FileStorage
 import transaction
 
-PYTHON = sys.executable + ' '
-
 def cleanup():
     for fname in glob.glob('Data.*') + glob.glob('Copy.*'):
         os.remove(fname)
@@ -76,7 +84,7 @@
         extra = ''
     else:
         extra = ' -D ' + when
-    cmd = PYTHON + '../repozo.py -vRr backup -o Copy.fs' + extra
+    cmd = PYTHON + REPOZO + ' -vRr backup -o Copy.fs' + extra
     os.system(cmd)
     f = file(correctpath, 'rb')
     g = file('Copy.fs', 'rb')
@@ -122,9 +130,9 @@
 
         # Make an incremental backup, half the time with gzip (-z).
         if random.random() < 0.5:
-            os.system(PYTHON + '../repozo.py -vBQr backup -f Data.fs')
+            os.system(PYTHON + REPOZO + ' -vBQr backup -f Data.fs')
         else:
-            os.system(PYTHON + '../repozo.py -zvBQr backup -f Data.fs')
+            os.system(PYTHON + REPOZO + ' -zvBQr backup -f Data.fs')
 
         if i % 9 == 0:
             copytime = '%04d-%02d-%02d-%02d-%02d-%02d' % (time.gmtime()[:6])
@@ -148,4 +156,9 @@
     print 'Test passed!'
 
 if __name__ == '__main__':
+    PYTHON = sys.executable + ' '
+    if len(sys.argv)>1:
+        REPOZO = sys.argv[1]
+    else:
+        REPOZO = '../repozo.py'
     main()

Modified: ZODB/trunk/src/ZODB/scripts/repozo.py
===================================================================
--- ZODB/trunk/src/ZODB/scripts/repozo.py	2009-11-19 21:08:58 UTC (rev 105888)
+++ ZODB/trunk/src/ZODB/scripts/repozo.py	2009-11-19 21:12:04 UTC (rev 105889)
@@ -65,7 +65,6 @@
 
 import os
 import sys
-import md5
 import gzip
 import time
 import errno
@@ -82,6 +81,12 @@
 READCHUNK = 16 * 1024
 VERBOSE = False
 
+if sys.version_info[1]>4:
+    # the hashlib package is available from Python 2.5
+    from hashlib import md5
+else:
+    # the md5 package is deprecated in Python 2.6
+    from md5 import new as md5
 
 def usage(code, msg=''):
     outfp = sys.stderr
@@ -210,7 +215,7 @@
 
 def checksum(fp, n):
     # Checksum the first n bytes of the specified file
-    sum = md5.new()
+    sum = md5()
     def func(data):
         sum.update(data)
     dofile(func, fp, n)
@@ -221,7 +226,7 @@
     # Copy bytes from file src, to file dst, starting at offset start, for n
     # length of bytes.  For robustness, we first write, flush and fsync
     # to a temp file, then rename the temp file at the end.
-    sum = md5.new()
+    sum = md5()
     ifp = open(options.file, 'rb')
     ifp.seek(start)
     tempname = os.path.join(os.path.dirname(dst), 'tmp.tmp')
@@ -248,7 +253,7 @@
     # Concatenate a bunch of files from the repository, output to `outfile' if
     # given.  Return the number of bytes written and the md5 checksum of the
     # bytes.
-    sum = md5.new()
+    sum = md5()
     def func(data):
         sum.update(data)
         if ofp:



More information about the Zodb-checkins mailing list