[Zope-CVS] CVS: Products/FileCacheManager - FileCacheManager.py:1.5
Jens Vagelpohl
jens at dataflake.org
Fri Aug 13 07:33:49 EDT 2004
Update of /cvs-repository/Products/FileCacheManager
In directory cvs.zope.org:/tmp/cvs-serv4132
Modified Files:
FileCacheManager.py
Log Message:
- add getters and setters for the filesystem path
- allow setting the filesystem path from the add form
=== Products/FileCacheManager/FileCacheManager.py 1.4 => 1.5 ===
--- Products/FileCacheManager/FileCacheManager.py:1.4 Fri Aug 13 05:20:55 2004
+++ Products/FileCacheManager/FileCacheManager.py Fri Aug 13 07:33:18 2004
@@ -20,13 +20,12 @@
class FileCache(RAMCache):
"""A cache that caches to the filesystem """
- _dir='/tmp' # XXX make configurable
-
- def __init__(self):
+ def __init__(self, path='/tmp'):
# cache maps physical paths to files.
self.cache=OOBTree.OOBTree()
self.writelock = allocate_lock()
self.next_cleanup = 0
+ self.setDir(path)
self._makeDirs()
def _fileName(self, ob):
@@ -37,10 +36,14 @@
fn = os.path.join(self._dir, hashed[:2], hashed)
return fn
+ def getDir(self):
+ """ Retrieve the filesystem directory used for caching """
+ return self._dir
+
def setDir(self, dir):
- """ Set the dir to use for caching on the filesystem."""
- # XXX make this configurable
- self._dir = '/tmp'
+ """ Set the filesystem diriectory to use for caching """
+ self._dir = dir
+ self._makeDirs()
def ZCache_invalidate(self, ob):
""" Invalidates the cache entries that apply to ob.
@@ -112,8 +115,7 @@
LOG('DiskCacheManger', ERROR, 'IOError writing file', error=msg)
def _makeDirs(self):
- """ make sure we have somewhere to put files.
- XXX must be sure to run this anytime _dir is changed """
+ """ Make sure we have somewhere to put files. """
chars = '0123456789abcdef'
for char in chars:
for char2 in chars:
@@ -131,11 +133,11 @@
meta_type = 'File Cache Manager'
- _dir = '/tmp' # XXX make configurable
- def __init__(self, ob_id, title=''):
+ def __init__(self, ob_id, path='/tmp', title=''):
# based on RAMCacheManager
self.id = ob_id
+ self._dir = path
self.title = title
self._settings = {
'threshold': 1000,
@@ -153,21 +155,52 @@
return caches[cacheid]
except KeyError:
cache = FileCache()
+
try:
cache.setDir(self._dir)
except ValueError:
pass
+
caches[cacheid] = cache
+
return cache
+ def getDir(self):
+ """ Return the cache directory path """
+ cache = self.ZCacheManager_getCache()
+
+ return cache.getDir()
+
+
+ def setDir(self, path):
+ """ Set the cache directory path """
+ cache = self.ZCacheManager_getCache()
+
+ try:
+ cache.setDir(path)
+ self._dir = path
+ except ValueError:
+ pass
+
manage_addFileCacheManagerForm = PageTemplateFile('www/addFCM', globals())
-def manage_addFileCacheManager(self, id, title='', REQUEST=None):
- 'Adds a FileCacheManager to the folder.'
- self._setObject(id, FileCacheManager(id, title))
+def manage_addFileCacheManager(self, id, path='/tmp', title='', REQUEST=None):
+ """ Adds a FileCacheManager to the folder. """
+ test_path = os.path.join(path, 'test.txt')
+ try:
+ fd = open(test_path, 'w')
+ self._setObject(id, FileCacheManager(id, path, title))
+ msg = 'FileCacheManager created.'
+ fd.close()
+ os.unlink(test_path)
+ except IOError:
+ msg = 'Invalid directory path "%s"' % path
+ if REQUEST is None:
+ raise(IOError, msg)
if REQUEST is not None:
+ REQUEST.set('manage_tabs_message', msg)
return self.manage_main(self, REQUEST)
More information about the Zope-CVS
mailing list