[Zodb-checkins] CVS: Packages/ZEO - ClientCache.py:1.16

jeremy@digicool.com jeremy@digicool.com
Wed, 9 May 2001 14:34:01 -0400 (EDT)


Update of /cvs-repository/Packages/ZEO
In directory korak:/tmp/cvs-serv27896

Modified Files:
	ClientCache.py 
Log Message:
Add a close() method that closes the current file, guaranteeting that
any recent updates are written to the file.

Remove seek() and tell() at the beginning of read_index() because
their results are not used.

Add main() that prints the contents a cache file when executed as a
script.

Add a log call when the cache is being read.



--- Updated File ClientCache.py in package Packages/ZEO --
--- ClientCache.py	2001/04/19 19:20:19	1.15
+++ ClientCache.py	2001/05/09 18:34:01	1.16
@@ -149,9 +149,13 @@
 import os, tempfile
 from struct import pack, unpack
 from thread import allocate_lock
+import zLOG
 
 magic='ZEC0'
 
+def LOG(msg, level=zLOG.BLATHER):
+    zLOG.LOG("ZEC", level, msg)
+
 class ClientCache:
 
     def __init__(self, storage='', size=20000000, client=None, var=None):
@@ -210,6 +214,9 @@
         self._limit=size/2
         self._current=current
 
+    def close(self):
+        self._f[self._current].close()
+
     def open(self):
         self._acquire()
         try:
@@ -407,19 +414,19 @@
         self._pos=pos+tlen
 
 def read_index(index, serial, f, current):
+    LOG("read_index(%s)" % f.name)
     seek=f.seek
     read=f.read
     pos=4
-    seek(0,2)
-    size=f.tell()
 
     while 1:
-        f.seek(pos)
+        seek(pos)
         h=read(27)
-        
+
         if len(h)==27 and h[8] in 'vni':
             tlen, vlen, dlen = unpack(">iHi", h[9:19])
-        else: tlen=-1
+        else:
+            break
         if tlen <= 0 or vlen < 0 or dlen < 0 or vlen+dlen > tlen:
             break
 
@@ -454,3 +461,15 @@
     except: pass
     
     return pos
+
+def main(files):
+    for file in files:
+        print file
+        index = {}
+        serial = {}
+        read_index(index, serial, open(file), 0)
+        print index.keys()
+
+if __name__ == "__main__":
+    import sys
+    main(sys.argv[1:])