[Zope-CVS] CVS: Products/ZCTextIndex/tests - mailtest.py:1.1.2.3

Guido van Rossum guido@python.org
Wed, 1 May 2002 11:45:31 -0400


Update of /cvs-repository/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv7745

Modified Files:
      Tag: TextIndexDS9-branch
	mailtest.py 
Log Message:
Add usage message.
Fix bug where end of mailbox wasn't detected properly.


=== Products/ZCTextIndex/tests/mailtest.py 1.1.2.2 => 1.1.2.3 ===
 from Products.ZCTextIndex.ZCTextIndex import ZCTextIndex
 
+import sys
 import mailbox
 import time
 
+def usage(msg):
+    print msg
+    print "usage: mailtest.py [-v] [-n NUM] [-p PACK_INTERVAL] mailbox Data.fs"
+    sys.exit(2)
+
 class Message:
 
     total_bytes = 0
@@ -36,8 +42,11 @@
         NUM = sys.maxint
     i = 0
     while i < NUM:
+        box = mbox.next()
+        if box is None:
+            break
         i += 1
-        msg = Message(mbox.next())
+        msg = Message(box)
         i0 = time.clock()
         idx.index_object(i, msg)
         get_transaction().commit()
@@ -55,13 +64,17 @@
     return idx_time, pack_time
 
 if __name__ == "__main__":
-    import sys
     import getopt
 
     NUM = 0
     VERBOSE = 0
     PACK_INTERVAL = 500
-    opts, args = getopt.getopt(sys.argv[1:], 'vn:p:')
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], 'vn:p:')
+    except getopt.error, msg:
+        usage(msg)
+    if len(args) != 2:
+        usage("exactly 2 filename arguments required")
     for o, v in opts:
         if o == '-n':
             NUM = int(v)