[Zodb-checkins] CVS: StandaloneZODB/bsddb3Storage/bsddb3Storage/tests - timeiter.py:1.2.4.1

Barry Warsaw barry@wooz.org
Tue, 8 Jan 2002 16:18:13 -0500


Update of /cvs-repository/StandaloneZODB/bsddb3Storage/bsddb3Storage/tests
In directory cvs.zope.org:/tmp/cvs-serv27678

Modified Files:
      Tag: Standby-branch
	timeiter.py 
Log Message:
Add options to select the database class on the command line.  Note
that this file will soon be removed from this directory and added to
the top-level Tools directory.


=== StandaloneZODB/bsddb3Storage/bsddb3Storage/tests/timeiter.py 1.2 => 1.2.4.1 ===
     -s filename
     --source=filename
-        Use database in filename as the source (must be a FileStorage)
+        Use database in filename as the source.
 
     -d filename
     --dest=filename
-        Use database in filename as the destination (must be a BDB storage)
+        Use database in filename as the destination.
+
+    -S classname
+    --stype=classname
+        The class name of the source storage, including the full module name.
+        Defaults to ZODB.FileStorage.FileStorage.
+
+    -D classname
+    --dtype=classname
+        The class name of the destination storage, including the full module
+        name.  Defaults to ZODB.FileStorage.FileStorage.
 
     -o filename
     --output=filename
@@ -46,12 +56,8 @@
 import traceback
 import marshal
 
-from bsddb3 import db
-
 from ZODB import utils
 from ZODB.TimeStamp import TimeStamp
-from ZODB.FileStorage import FileStorage
-from bsddb3Storage.Full import Full
 
 PROGRAM = sys.argv[0]
 ZERO = '\0'*8
@@ -68,16 +74,18 @@
 
 def main():
     try:
-        opts, args = getopt.getopt(sys.argv[1:], 'hs:d:qo:l:pm:k:',
+        opts, args = getopt.getopt(sys.argv[1:], 'hs:d:qo:l:pm:k:D:S:',
                                    ['help', 'source=', 'dest=', 'quiet',
                                     'output=', 'logfile=', 'profile',
-                                    'max=', 'skip='])
+                                    'max=', 'skip=', 'dtype=', 'stype='])
     except getopt.error, msg:
         usage(1, msg)
 
     class Options:
         source = None
         dest = None
+        stype = 'ZODB.FileStorage.FileStorage'
+        dtype = 'ZODB.FileStorage.FileStorage'
         verbose = 1
         outfile = None
         logfile = None
@@ -94,6 +102,10 @@
             options.source = arg
         elif opt in ('-d', '--dest'):
             options.dest = arg
+        elif opt in ('-S', '--stype'):
+            options.stype = arg
+        elif opt in ('-D', '--dtype'):
+            options.dtype = arg
         elif opt in ('-q', '--quiet'):
             options.verbose = 0
         elif opt in ('-o', '--output'):
@@ -133,29 +145,29 @@
     print >> options.outfp, '# FS->BDB 3.3.11'
     print >> options.outfp, '#', time.ctime()
 
-    print >>sys.stderr, 'Opening source FileStorage...'
+    # Import the storage classes
+    __import__(options.stype)
+    Source = sys.modules[options.stype]
+
+    __import__(options.dtype)
+    Dest = sys.modules[options.dtype]
+
+    print >> sys.stderr, 'Opening source %s...' % Source.__class__.__name__
     t0 = time.time()
-    srcdb = FileStorage(options.source, read_only=1)
+    # Try to open this storage read-only, but fall back to normal open if
+    # that fails
+    try:
+        srcdb = Source(options.source, read_only=1)
+    except TypeError:
+        srcdb = Source(options.source)
     t1 = time.time()
-    print >>sys.stderr, 'Opening source FileStorage done. %s seconds' % (t1-t0)
-#
-# Uncomment this section to do a FS->BDB migration
-#
-    print >>sys.stderr, 'Opening destination BDB...'
+    print >> sys.stderr, 'Opening source done in %s seconds' % (t1-t0)
+
+    print >> sys.stderr, 'Opening destination %s...' % Dest.__class__.__name__
     t0 = time.time()
-    dstdb = Full(options.dest)
+    dstdb = Dest(options.dest)
     t1 = time.time()
-    print >>sys.stderr, 'Opening destination BDB done. %s seconds' % (t1-t0)
-
-#
-# Uncomment this section to do a FS->FS migration
-#
-##    print >>sys.stderr, 'Opening destination FileStorage...'
-##    t0 = time.time()
-##    dstdb = FileStorage(dest)
-##    t1 = time.time()
-##    print >>sys.stderr, 'Opening destination FileStorage done. %s seconds' % (
-##        t1-t0)
+    print >> sys.stderr, 'Opening destination done in  %s seconds' % (t1-t0)
 
     try:
         t0 = time.time()