[Checkins] SVN: zc.beforestorage/trunk/s Added the capability for 'before now', which will behave the same as no

Aaron Lehmann aaron at zope.com
Wed Mar 5 14:06:13 EST 2008


Log message for revision 84480:
  Added the capability for 'before now', which will behave the same as no
  argument, and 'before startup', which will use the time at first module load.
  Added tests of same.
  
  

Changed:
  U   zc.beforestorage/trunk/setup.py
  U   zc.beforestorage/trunk/src/zc/beforestorage/README.txt
  U   zc.beforestorage/trunk/src/zc/beforestorage/__init__.py
  U   zc.beforestorage/trunk/src/zc/beforestorage/component.xml
  U   zc.beforestorage/trunk/src/zc/beforestorage/tests.py

-=-
Modified: zc.beforestorage/trunk/setup.py
===================================================================
--- zc.beforestorage/trunk/setup.py	2008-03-05 12:48:41 UTC (rev 84479)
+++ zc.beforestorage/trunk/setup.py	2008-03-05 19:06:13 UTC (rev 84480)
@@ -33,7 +33,7 @@
 
 setup(
     name = 'zc.beforestorage',
-    version = '0.2dev',
+    version = '0.3.0dev',
     author = 'Jim Fulton',
     author_email = 'jim at zope.com',
     description = 'View storage before a given time',

Modified: zc.beforestorage/trunk/src/zc/beforestorage/README.txt
===================================================================
--- zc.beforestorage/trunk/src/zc/beforestorage/README.txt	2008-03-05 12:48:41 UTC (rev 84479)
+++ zc.beforestorage/trunk/src/zc/beforestorage/README.txt	2008-03-05 19:06:13 UTC (rev 84480)
@@ -88,10 +88,53 @@
     ... """)
 
     >>> storage
-    <Before: my.fs before 2008-01-21 18:22:48.000000>
+    <Before: my.fs before 2008-01-21 18:22:49.000000>
 
     >>> storage.close()
 
+We can also give the option 'now' and get the current time.
+
+    >>> import ZODB.config
+    >>> storage = ZODB.config.storageFromString("""
+    ...
+    ... %import zc.beforestorage
+    ...
+    ... <before>
+    ...     before now
+    ...     <filestorage>
+    ...         path my.fs
+    ...     </filestorage>
+    ... </before>
+    ... """)
+
+    >>> storage
+    <Before: my.fs before 2008-01-21 18:22:53.000000>
+
+    >>> storage.close()
+
+We can give the option 'startup' and get the time at startup.
+
+    >>> import ZODB.config
+    >>> storage = ZODB.config.storageFromString("""
+    ...
+    ... %import zc.beforestorage
+    ...
+    ... <before>
+    ...     before startup
+    ...     <filestorage>
+    ...         path my.fs
+    ...     </filestorage>
+    ... </before>
+    ... """)
+
+    >>> storage
+    <Before: my.fs before 2008-01-21 18:22:43.000000>
+    >>> import zc.beforestorage
+    >>> import ZODB.TimeStamp
+    >>> print str(ZODB.TimeStamp.TimeStamp(zc.beforestorage.startup_time_stamp))
+    2008-01-21 18:22:43.000000
+    >>> storage.close()
+
 Demonstration (doctest)
 =======================
 
@@ -160,7 +203,7 @@
 Let's run through the storage methods:
 
     >>> b5.getName()
-    'Data.fs before 2008-01-21 18:22:56.000000'
+    'Data.fs before 2008-01-21 18:23:04.000000'
 
     >>> b5.getSize() == fs.getSize()
     True
@@ -285,7 +328,7 @@
 The timestamp may be passed directory, or as an ISO time.  For
 example:
 
-    >>> b5 = zc.beforestorage.Before(fs, '2008-01-21T18:22:56')
+    >>> b5 = zc.beforestorage.Before(fs, '2008-01-21T18:23:04')
     >>> db5 = DB(b5)
     >>> conn5 = db5.open()
     >>> root5 = conn5.root()

Modified: zc.beforestorage/trunk/src/zc/beforestorage/__init__.py
===================================================================
--- zc.beforestorage/trunk/src/zc/beforestorage/__init__.py	2008-03-05 12:48:41 UTC (rev 84479)
+++ zc.beforestorage/trunk/src/zc/beforestorage/__init__.py	2008-03-05 19:06:13 UTC (rev 84480)
@@ -18,13 +18,19 @@
 import ZODB.TimeStamp
 import ZODB.utils
 
+def time_stamp():
+    t = time.time()
+    g = time.gmtime(t)
+    before = repr(ZODB.TimeStamp.TimeStamp(*(g[:5] + (g[5]+(t%1), ))))
+    return before
+
+startup_time_stamp = time_stamp()
+
 class Before:
 
     def __init__(self, storage, before=None):
         if before is None:
-            t = time.time()
-            g = time.gmtime(t)
-            before = repr(ZODB.TimeStamp.TimeStamp(*(g[:5] + (g[5]+(t%1), ))))
+            before = time_stamp()
         else:
             assert isinstance(before, basestring)
             if len(before) > 8:
@@ -39,7 +45,6 @@
                     assert len(t) <= 3
                     d += map(int, t[:2]) + map(float, t[2:3])
                 before = repr(ZODB.TimeStamp.TimeStamp(*d))
-            
         self.storage = storage
         self.before = before
 
@@ -149,5 +154,11 @@
 
     def open(self):
         base = self.config.base.open()
+        before = self.config.before
+        if isinstance(before, basestring):
+            if before.lower() == 'now':
+                self.config.before = None
+            elif before.lower() == 'startup':
+                self.config.before = startup_time_stamp
         return Before(base, self.config.before)
     

Modified: zc.beforestorage/trunk/src/zc/beforestorage/component.xml
===================================================================
--- zc.beforestorage/trunk/src/zc/beforestorage/component.xml	2008-03-05 12:48:41 UTC (rev 84479)
+++ zc.beforestorage/trunk/src/zc/beforestorage/component.xml	2008-03-05 19:06:13 UTC (rev 84480)
@@ -10,11 +10,15 @@
 
     <key name="before" datatype="string" required="no">
       <description>
-        The time before which data will be read from the base storage.
-        This is of the form: YYYY-MM-DDTHH:MM:SS.SSS, where trailing
-        time data is optional. That is: YYYY-MM-DDTHH:MM:SS,
-        YYYY-MM-DDTHH:MM, YYYY-MM-DDTHH, and YYYY-MM-DD, are all valid
-        forms. 
+        The time before which data will be read from the base storage.  This is
+        of the form: YYYY-MM-DDTHH:MM:SS.SSS, where trailing time data is
+        optional. That is: YYYY-MM-DDTHH:MM:SS, YYYY-MM-DDTHH:MM,
+        YYYY-MM-DDTHH, and YYYY-MM-DD, are all valid forms.   Also valid is
+        the case-insensitive string 'now', which is the same as not passing an
+        argument.  Also, the case-insensitive argument 'startup' opens the
+        storage as of the time at module load.  This is to prevent a possible
+        window ibetween the opening of the underlying filestorage and the
+        opening of the beforestorage.
       </description>
     </key>
   </sectiontype>

Modified: zc.beforestorage/trunk/src/zc/beforestorage/tests.py
===================================================================
--- zc.beforestorage/trunk/src/zc/beforestorage/tests.py	2008-03-05 12:48:41 UTC (rev 84479)
+++ zc.beforestorage/trunk/src/zc/beforestorage/tests.py	2008-03-05 19:06:13 UTC (rev 84480)
@@ -14,8 +14,8 @@
 import time, unittest
 from zope.testing import doctest
 import zope.testing.setupstack
+import zc.beforestorage
 
-
     
 def setUp(test):
     zope.testing.setupstack.setUpDirectory(test)
@@ -30,6 +30,7 @@
         lambda : setattr(time, 'time', old_timetime)
         )
     time.time = timetime
+    zc.beforestorage.startup_time_stamp = zc.beforestorage.time_stamp()
 
     
 def test_suite():



More information about the Checkins mailing list