[Zope-CVS] CVS: Products/ZCTextIndex/tests - mailtest.py:1.1.2.11
Guido van Rossum
guido@python.org
Wed, 1 May 2002 14:13:35 -0400
Update of /cvs-repository/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv22376
Modified Files:
Tag: TextIndexDS9-branch
mailtest.py
Log Message:
Pack one more time at the end.
Normalize whitespace.
=== Products/ZCTextIndex/tests/mailtest.py 1.1.2.10 => 1.1.2.11 ===
-q query
-i mailbox
+ -p NNN -- pack <data.fs> every NNN messages (default: at end only)
The script either indexes or queries depending on whether -q or -i is
passed as an option.
@@ -47,7 +48,7 @@
class Message:
total_bytes = 0
-
+
def __init__(self, msg):
self.text = msg.fp.read()
Message.total_bytes += len(self.text)
@@ -56,7 +57,7 @@
global NUM
idx_time = 0
pack_time = 0
-
+
rt["index"] = idx = ZCTextIndex("text")
rt["documents"] = docs = IOBTree()
get_transaction().commit()
@@ -68,10 +69,10 @@
NUM = sys.maxint
i = 0
while i < NUM:
- i += 1
_msg = mbox.next()
if _msg is None:
break
+ i += 1
msg = Message(_msg)
if VERBOSE >= 2:
print "indexing msg", i
@@ -84,6 +85,8 @@
if VERBOSE and i % 50 == 0:
print i, "messages indexed"
if i % PACK_INTERVAL == 0:
+ if VERBOSE >= 2:
+ print "packing..."
p0 = time.clock()
db.pack(time.time())
p1 = time.clock()
@@ -91,6 +94,16 @@
print "pack took %s sec" % (p1 - p0)
pack_time += p1 - p0
+ if i % PACK_INTERVAL != 0:
+ if VERBOSE >= 2:
+ print "packing one last time..."
+ p0 = time.clock()
+ db.pack(time.time())
+ p1 = time.clock()
+ if VERBOSE:
+ print "pack took %s sec" % (p1 - p0)
+ pack_time += p1 - p0
+
if VERBOSE:
print "Index time", idx_time
print "Index bytes", Message.total_bytes
@@ -100,7 +113,6 @@
def query(rt, query_str):
idx = rt["index"]
results = idx.query(query_str)
- print results
for r in results.items():
print r
@@ -109,7 +121,7 @@
db = ZODB.DB(f)
cn = db.open()
rt = cn.root()
-
+
if mbox_path is not None:
index(rt, mbox_path, db)
if query_str is not None: