[Zodb-checkins] CVS: Zope/utilities/ZODBTools - zodbload.py:1.2.2.5

Jim Fulton jim at zope.com
Tue Oct 14 09:45:40 EDT 2003


Update of /cvs-repository/Zope/utilities/ZODBTools
In directory cvs.zope.org:/tmp/cvs-serv13703

Modified Files:
      Tag: Zope-2_7-branch
	zodbload.py 
Log Message:
Added a "max" option to index to limit the size of folders.  This is
used in a insertion test to avoid excessive folder sizes.


=== Zope/utilities/ZODBTools/zodbload.py 1.2.2.4 => 1.2.2.5 ===
--- Zope/utilities/ZODBTools/zodbload.py:1.2.2.4	Fri Oct  3 13:02:31 2003
+++ Zope/utilities/ZODBTools/zodbload.py	Tue Oct 14 09:45:39 2003
@@ -325,10 +325,20 @@
                 run1(tid, Zope.DB, factory, job, args)
 
 
-def index(connection, messages, catalog):
+def index(connection, messages, catalog, max):
     app = connection.root()['Application']
     for message in messages:
         mail = mailfolder(app, message.mbox, message.number)
+
+        if max:
+            # Cheat and use folder implementation secrets
+            # to avoid having to read the old data
+            _objects = mail._objects
+            if len(_objects) >= max:
+                for d in _objects[:len(_objects)-max+1]:
+                    del mail.__dict__[d['id']]
+                mail._objects = _objects[len(_objects)-max+1:]
+            
         docid = 'm'+str(message.number)
         mail.manage_addDTMLDocument(docid, file=message.body)
 
@@ -364,13 +374,13 @@
     catalog = 1
     prefix = 'index'
 
-    def __init__(self, mbox, number=1):
+    def __init__(self, mbox, number=1, max=0):
         self.__name__ = "%s%s_%s" % (self.prefix, number, mbox.__name__)
-        self.mbox, self.number = mbox, int(number)
+        self.mbox, self.number, self.max = mbox, int(number), int(max)
 
     def create(self):
         messages = [self.mbox.next() for i in range(self.number)]
-        return index, (messages, self.catalog)
+        return index, (messages, self.catalog, self.max)
 
 
 class InsertJob(IndexJob):




More information about the Zodb-checkins mailing list