[Checkins] SVN: zc.beforestorage/branches/satchit-before-from-file-option/src/zc/beforestorage/ record the "before_from_file" so that the path is accessible by applications that make use of it.
Satchidanand Haridas
satchit at zope.com
Thu Dec 9 15:49:46 EST 2010
Log message for revision 118775:
record the "before_from_file" so that the path is accessible by applications that make use of it.
Refactoring.
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 16:49:18 UTC (rev 118774)
+++ zc.beforestorage/branches/satchit-before-from-file-option/src/zc/beforestorage/README.txt 2010-12-09 20:49:45 UTC (rev 118775)
@@ -250,7 +250,51 @@
>>> storage.close()
+If we restart the storage, the value from the file will be used.
+ >>> storage = ZODB.config.storageFromString("""
+ ...
+ ... %%import zc.beforestorage
+ ...
+ ... <before>
+ ... before-from-file %s
+ ... <filestorage>
+ ... path my.fs
+ ... </filestorage>
+ ... </before>
+ ... """ % before_file)
+
+ >>> storage
+ <Before: my.fs before 1990-01-01 11:11:00.000000>
+
+ >>> storage.close()
+
+This will continue to happen until we remove the file.
+
+ >>> os.remove(storage.before_from_file)
+
+ >>> os.path.exists(before_file)
+ False
+
+If we restart the storage again, a new file will be created.
+
+ >>> storage = ZODB.config.storageFromString("""
+ ...
+ ... %%import zc.beforestorage
+ ...
+ ... <before>
+ ... before-from-file %s
+ ... <filestorage>
+ ... path my.fs
+ ... </filestorage>
+ ... </before>
+ ... """ % before_file)
+
+ >>> storage
+ <Before: my.fs before 2008-01-01 15:00:00.000000>
+
+ >>> storage.close()
+
Note that unlike the "before" option, the "before-from-file" file cannot
contain special values such as "now" or "startup".
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 16:49:18 UTC (rev 118774)
+++ zc.beforestorage/branches/satchit-before-from-file-option/src/zc/beforestorage/__init__.py 2010-12-09 20:49:45 UTC (rev 118775)
@@ -13,6 +13,7 @@
##############################################################################
import datetime
+import os
import os.path
import time
@@ -35,7 +36,16 @@
class Before:
- def __init__(self, storage, before=None):
+ 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()
if before is None:
before = time_stamp()
else:
@@ -54,6 +64,7 @@
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
@@ -62,7 +73,6 @@
zope.interface.alsoProvides(self, ZODB.interfaces.IBlobStorage)
-
def close(self):
self.storage.close()
@@ -179,21 +189,12 @@
raise ValueError(
'Only one of "before" or "before-from-file" options '
'can be specified, not both')
- if before and isinstance(before, basestring):
+ if isinstance(before, basestring):
if before.lower() == 'now':
self.config.before = None
elif before.lower() == 'startup':
self.config.before = startup_time_stamp
- 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()
- return Before(base, self.config.before)
+ return Before(base, self.config.before, self.config.before_from_file)
More information about the checkins
mailing list