[Zodb-checkins] CVS: StandaloneZODB/Tools - timeiter.py:1.1.2.6

Guido van Rossum guido@python.org
Fri, 11 Jan 2002 18:05:10 -0500


Update of /cvs-repository/StandaloneZODB/Tools
In directory cvs.zope.org:/tmp/cvs-serv16067

Modified Files:
      Tag: Standby-branch
	timeiter.py 
Log Message:
Add the start() call to make the PrimaryStorage run.

Also improved the usage message somewhat and improved the quality of
the error messages.  There's no point in spitting out the entire
60-line usage message for every error, and the exit code for usage
errors should be 2, not 1.


=== StandaloneZODB/Tools/timeiter.py 1.1.2.5 => 1.1.2.6 ===
 sense of the performance of a storage by running this script.
 
-
-
 Actually just counts the size of pickles in the transaction via the iterator
 protocol, so storage overheads aren't counted.
 
-Usage: %(PROGRAM)s [options]
+Usage: %(PROGRAM)s [options] [source-storage-args] [destination-storage-args]
 Options:
     -S sourcetype
     --stype=sourcetype
@@ -48,6 +46,17 @@
 
     -h/--help
         Print this message and exit.
+
+Positional arguments:
+
+    source-storage-args:
+        Arguments for the source storage; typically a filename; use -T
+        for details.
+
+    destination-storage-args:
+        Arguments for the source storage; typically a filename; use -T
+        for details.
+
 """
 
 import sys
@@ -74,6 +83,10 @@
         print >> sys.stderr, msg
     sys.exit(code)
 
+def error(code, msg):
+    print >>sys.stderr, msg
+    print "use --help for usage message"
+    sys.exit(code)
 
 
 def main():
@@ -85,7 +98,7 @@
              'output=', 'profile', 'storage_types',
              'max=', 'skip=', 'dtype=', 'stype='])
     except getopt.error, msg:
-        usage(1, msg)
+        error(2, msg)
 
     class Options:
         stype = 'file'
@@ -125,9 +138,9 @@
     args = list(args)
 
     if not options.stype in STORAGETYPES.keys():
-        usage(1, 'Source database type must be provided')
+        usage(2, 'Source database type must be provided')
     if not options.dtype in STORAGETYPES.keys():
-        usage(1, 'Destination database type must be provided')
+        usage(2, 'Destination database type must be provided')
 
     # Open the output file
     if options.outfile is None:
@@ -157,7 +170,7 @@
         print 'Opening destination done in  %s seconds' % (t1-t0)
 
     if args:
-        usage(1)
+        error(2, "too many arguments")
 
     try:
         t0 = time.time()
@@ -276,7 +289,7 @@
     Requires one argument: the file name of the storage.
     """
     if not args:
-        usage(1, 'filename is required')
+        error(2, "filename is required")
         # No return
     from ZODB.FileStorage import FileStorage
     filename = args[0]
@@ -302,7 +315,8 @@
         port, defaults to RS_PORT
     """
     if not args:
-        usage(1, 'filename is required')
+        error(2, 'filename is required')
+        # No return
     from ZODB.FileStorage import FileStorage
     from socket import gethostname
     from Standby.primary import PrimaryStorage
@@ -320,7 +334,9 @@
         port = int(args[2])
         lastarg += 1
     del args[:lastarg]
-    return PrimaryStorage(name, dfs, port)
+    p = PrimaryStorage(name, dfs, port)
+    p.start() # Start the Spread message receive loop
+    return p
 
 
 # This maps case-insensitive names against factory functions.  The latter must