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

Jim Fulton jim at zope.com
Fri Oct 3 13:02:31 EDT 2003


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

Modified Files:
      Tag: Zope-2_7-branch
	zodbload.py 
Log Message:
Added more ways to specify messages to be read from the mailbox file.
See the doc string.


=== Zope/utilities/ZODBTools/zodbload.py 1.2.2.3 => 1.2.2.4 ===
--- Zope/utilities/ZODBTools/zodbload.py:1.2.2.3	Thu Oct  2 15:37:05 2003
+++ Zope/utilities/ZODBTools/zodbload.py	Fri Oct  3 13:02:31 2003
@@ -88,6 +88,30 @@
 
        Specify the mailbox for getting input data.
 
+       There is a (lame) syntax for providing options within the
+       filename. The filename may be followed by up to 3 integers,
+       min, max, and start:
+
+         -mbox 'foo.mbox 0 100 10000'
+
+       The messages from min to max will be read from the mailbox.
+       They will be assigned message numbers starting with start.
+       So, in the example above, we read the first hundred messages
+       and assign thgem message numbers starting with 10001.
+
+       The maxmum can be given as a negative number, in which case, it
+       specifies the number of messages to read.
+
+       The start defaults to the minimum. The following two options:
+
+         -mbox 'foo.mbox 300 400 300'
+
+       and
+
+         -mbox 'foo.mbox 300 -100'
+
+       are equivalent
+
 $Id$
 """
 
@@ -124,28 +148,40 @@
 
     def __init__(self, filename):
         if ' ' in filename:
-            filename, min, max = filename.split()
+            filename = filename.split()
+            if len(filename) < 4:
+                filename += [0, 0, -1][-(4-len(filename)):]
+            filename, min, max, start = filename
             min = int(min)
             max = int(max)
+            start = int(start)
+            
+            if start < 0:
+                start = min
+
+            if max < 0:
+                # negative max is treated as a count
+                self._max = start - max
+            elif max > 0:
+                self._max = start + max - min
+            else:
+                self._max = 0
+            
         else:
-            min = max = 0
+            self._max = 0
+            min = start = 0
 
-        if filename.endswith('.bz2'):
-            f = os.popen("bunzip2 <"+filename, 'r')
-            filename = filename[-4:]
-        else:
-            f = open(filename)
+        f = open(filename)
 
         self._mbox = mb = mailbox.UnixMailbox(f)
 
-        self.number = min
+        self.number = start
         while min:
             mb.next()
             min -= 1
 
         self._lock = threading.Lock()
         self.__name__ = os.path.splitext(os.path.split(filename)[1])[0]
-        self._max = max
 
     def next(self):
         self._lock.acquire()




More information about the Zodb-checkins mailing list