[Zope-CVS] CVS: Products/ZCTextIndex/tests - indexhtml.py:1.1.2.2

Jeremy Hylton jeremy@zope.com
Fri, 10 May 2002 10:36:08 -0400


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

Modified Files:
      Tag: TextIndexDS9-branch
	indexhtml.py 
Log Message:
Add constants to control commit rate and pack rate


=== Products/ZCTextIndex/tests/indexhtml.py 1.1.2.1 => 1.1.2.2 ===
     return ZCTextIndex(extra, caller)
 
-def main(root, dir):
+def main(db, root, dir):
     rt["index"] = index = make_index()
     rt["files"] = paths = IOBTree()
     get_transaction().commit()
 
-    files = os.listdir(dir)
+    files = [os.path.join(dir, file) for file in os.listdir(dir)]
     docid = 0
     for file in files:
         if os.path.isdir(file):
@@ -44,12 +44,16 @@
         else:
             if not file.endswith(".html"):
                 continue
-            print file
             docid += 1
+            print "%5d" % docid, file
             f = open(file, "rb")
             paths[docid] = file
             index.index_object(docid, f)
             f.close()
+            if docid % TXN_INTERVAL == 0:
+                get_transaction().commit()
+            if docid % PACK_INTERVAL == 0:
+                db.pack()
     get_transaction().commit()
 
 if __name__ == "__main__":
@@ -58,6 +62,8 @@
 
     VERBOSE = 0
     FSPATH = "Data.fs"
+    TXN_INTERVAL = 100
+    PACK_INTERVAL = 500
     try:
         opts, args = getopt.getopt(sys.argv[1:], 'vf:')
     except getopt.error, msg:
@@ -81,6 +87,9 @@
     db = ZODB.DB(fs)
     cn = db.open()
     rt = cn.root()
-    main(rt, dir)
+    dir = os.path.join(os.getcwd(), dir)
+    print dir
+    main(db, rt, dir)
     cn.close()
-            
+    fs.close()        
+