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

Jeremy Hylton jeremy@zope.com
Wed, 1 May 2002 12:17:59 -0400


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

Modified Files:
      Tag: TextIndexDS9-branch
	mailtest.py 
Log Message:
Add a longer doc string / usage message.

Gracefully exit when the last message is read from the mailbox.


=== Products/ZCTextIndex/tests/mailtest.py 1.1.2.3 => 1.1.2.4 ===
+
+usage: python mailtest.py [options] <mailbox> <data.fs>
+
+options:
+    -v verbose
+    -n NNN -- max number of messages to read from mailbox
+
+The script reads mail messages from the mailbox and indexes them.  It
+indexes one message at a time, then commits the transaction.
+
+To interact with the index after it is completed, you can simply load
+the index from the database:
+
+    import ZODB
+    from ZODB.FileStorage import FileStorage
+    fs = FileStorage(<data.fs>
+    db = ZODB.DB(fs)
+    index = cn.open().root()["index"]
+    index.search("python AND unicode")
+"""
+
 import ZODB
 import ZODB.FileStorage
 from Products.ZCTextIndex.ZCTextIndex import ZCTextIndex
@@ -8,7 +30,7 @@
 
 def usage(msg):
     print msg
-    print "usage: mailtest.py [-v] [-n NUM] [-p PACK_INTERVAL] mailbox Data.fs"
+    print __doc__
     sys.exit(2)
 
 class Message:
@@ -46,7 +68,10 @@
         if box is None:
             break
         i += 1
-        msg = Message(box)
+        _msg = mbox.next()
+        if _msg is None:
+            break
+        msg = Message(_msg)
         i0 = time.clock()
         idx.index_object(i, msg)
         get_transaction().commit()