[Checkins] SVN: zc.beforestorage/branches/satchit-before-from-file-option/src/zc/beforestorage/ Changed approach to change as little as possible in the Before storage implementation.

Satchidanand Haridas satchit at zope.com
Thu Dec 9 17:02:53 EST 2010


Log message for revision 118781:
  Changed approach to change as little as possible in the Before storage implementation.
  
  - The "before_from_file" is set directly on the instance instead of passing it to its constructor thus avoiding a change in API.
  
  

Changed:
  U   zc.beforestorage/branches/satchit-before-from-file-option/src/zc/beforestorage/README.txt
  U   zc.beforestorage/branches/satchit-before-from-file-option/src/zc/beforestorage/__init__.py

-=-
Modified: zc.beforestorage/branches/satchit-before-from-file-option/src/zc/beforestorage/README.txt
===================================================================
--- zc.beforestorage/branches/satchit-before-from-file-option/src/zc/beforestorage/README.txt	2010-12-09 21:24:59 UTC (rev 118780)
+++ zc.beforestorage/branches/satchit-before-from-file-option/src/zc/beforestorage/README.txt	2010-12-09 22:02:53 UTC (rev 118781)
@@ -269,7 +269,9 @@
 
     >>> storage.close()
 
-This will continue to happen until we remove the file.
+This will continue to happen until we remove the file. The "before_from_file"
+path is stored on the storage itself, so applications that use it have access
+to it.
 
     >>> os.remove(storage.before_from_file)
 

Modified: zc.beforestorage/branches/satchit-before-from-file-option/src/zc/beforestorage/__init__.py
===================================================================
--- zc.beforestorage/branches/satchit-before-from-file-option/src/zc/beforestorage/__init__.py	2010-12-09 21:24:59 UTC (rev 118780)
+++ zc.beforestorage/branches/satchit-before-from-file-option/src/zc/beforestorage/__init__.py	2010-12-09 22:02:53 UTC (rev 118781)
@@ -13,7 +13,6 @@
 ##############################################################################
 
 import datetime
-import os
 import os.path
 import time
 
@@ -36,16 +35,7 @@
 
 class Before:
 
-    def __init__(self, storage, before=None, before_from_file=None):
-        if before_from_file:
-            if os.path.exists(before_from_file):
-                f = open(before_from_file)
-                before = f.read()
-            else:
-                f = open(before_from_file, 'w')
-                before = get_utcnow().replace(microsecond=0).isoformat()
-                f.write(before)
-            f.close()
+    def __init__(self, storage, before=None):
         if before is None:
             before = time_stamp()
         else:
@@ -64,7 +54,6 @@
                 before = repr(ZODB.TimeStamp.TimeStamp(*d))
         self.storage = storage
         self.before = before
-        self.before_from_file = before_from_file
         if ZODB.interfaces.IBlobStorage.providedBy(storage):
             self.loadBlob = storage.loadBlob
             self.temporaryDirectory = storage.temporaryDirectory
@@ -73,6 +62,7 @@
 
             zope.interface.alsoProvides(self, ZODB.interfaces.IBlobStorage)
 
+
     def close(self):
         self.storage.close()
 
@@ -189,12 +179,23 @@
             raise ValueError(
                 'Only one of "before" or "before-from-file" options '
                 'can be specified, not both')
-        if isinstance(before, basestring):
+        if before and 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, self.config.before_from_file)
+        elif before_from_file:
+            if os.path.exists(before_from_file):
+                f = open(before_from_file)
+                self.config.before = f.read()
+            else:
+                f = open(before_from_file, 'w')
+                self.config.before = get_utcnow().replace(microsecond=0).isoformat()
+                f.write(self.config.before)
+            f.close()
+        before_storage = Before(base, self.config.before)
+        before_storage.before_from_file = self.config.before_from_file
+        return before_storage
 
 
 



More information about the checkins mailing list