[Zope-CVS] CVS: Products/FileCacheManager - FileCacheManager.py:1.15

Chris McDonough chrism at plope.com
Sat Aug 28 20:53:09 EDT 2004


Update of /cvs-repository/Products/FileCacheManager
In directory cvs.zope.org:/tmp/cvs-serv5339

Modified Files:
	FileCacheManager.py 
Log Message:
Add user-settable tempfile path and remove some well-meaning exception handlers that tended to obscure problems.


=== Products/FileCacheManager/FileCacheManager.py 1.14 => 1.15 ===
--- Products/FileCacheManager/FileCacheManager.py:1.14	Thu Aug 19 14:16:29 2004
+++ Products/FileCacheManager/FileCacheManager.py	Sat Aug 28 20:53:09 2004
@@ -39,11 +39,13 @@
         ) + RAMCacheManager.manage_options
         )
 
+    _tempfile_path = ''
     
-    def __init__(self, ob_id, path='/tmp', title=''):
+    def __init__(self, ob_id, path='/tmp', tpath='', title=''):
         # based on RAMCacheManager
         self.id = ob_id
         self._dir = path
+        self._tempfile_path = tpath
         self.title = title
         self._naming_expr_text = ''
         self._settings = {
@@ -63,11 +65,9 @@
         except KeyError:
             cache = FileCache()
 
-            try:
-                cache.setDir(self._dir)
-                cache.setNamingExpression(self._naming_expr_text)
-            except ValueError:
-                pass
+            cache.setDir(self._dir)
+            cache.setTempfileDir(self._tempfile_path)
+            cache.setNamingExpression(self._naming_expr_text)
 
             caches[cacheid] = cache
 
@@ -80,16 +80,26 @@
 
         return cache.getDir()
 
+    security.declareProtected(view_management_screens, 'getTempfileDir')
+    def getTempfileDir(self):
+        """ Return the temporary directory path """
+        cache = self.ZCacheManager_getCache()
+
+        return cache.getTempfileDir()
+
     security.declareProtected(change_cache_managers, 'setDir')
     def setDir(self, path):
         """ Set the cache directory path """
         cache = self.ZCacheManager_getCache()
+        cache.setDir(path)
+        self._dir = path
 
-        try:
-            cache.setDir(path)
-            self._dir = path
-        except ValueError:
-            pass
+    security.declareProtected(change_cache_managers, 'setDir')
+    def setTempfileDir(self, path):
+        """ Set the tempfile directory path """
+        cache = self.ZCacheManager_getCache()
+        cache.setTempfileDir(path)
+        self._tempfile_path = path
 
     security.declareProtected(view_management_screens, 'getNamingExpression')
     def getNamingExpression(self):
@@ -100,26 +110,20 @@
     def setNamingExpression(self, naming_expression_text=''):
         """ Set a naming expression for filesystem files """
         cache = self.ZCacheManager_getCache()
-        error = cache.setNamingExpression(naming_expression_text)
-        if not error:
-            self._naming_expr_text = naming_expression_text
-
-        return error
+        cache.setNamingExpression(naming_expression_text)
+        self._naming_expr_text = naming_expression_text
 
     security.declareProtected(change_cache_managers, 'manage_edit')
-    def manage_edit(self, path='/tmp', naming_expression_text='', REQUEST=None):
+    def manage_edit(self, path='/tmp', tpath='',
+                    naming_expression_text='', REQUEST=None):
         """ Edit the filesystem-related values """
-        msg = self.setNamingExpression(naming_expression_text)
-
-        if not msg:
-            if os.access(path, os.W_OK):
-                msg = 'Changes saved.'
-                self.setDir(path)
-            else:
-                msg = 'Invalid directory "%s"' % path
+        self.setNamingExpression(naming_expression_text)
+        self.setDir(path)
+        self.setTempfileDir(tpath)
 
         if REQUEST is not None:
-            return self.manage_fs(self, REQUEST, manage_tabs_message=msg)
+            return self.manage_fs(
+                self, REQUEST, manage_tabs_message='Changes saved')
 
 
 InitializeClass(FileCacheManager)
@@ -127,18 +131,13 @@
 
 manage_addFileCacheManagerForm = PageTemplateFile('www/addFCM', globals())
 
-def manage_addFileCacheManager(self, id, path='/tmp', title='', REQUEST=None):
+def manage_addFileCacheManager(self, id, path='/tmp', tpath='',
+                               title='', REQUEST=None):
     """ Adds a FileCacheManager to the folder. """
     # Test to see that we can write into the place we got as the cache dir
-    if os.access(path, os.W_OK):
-        self._setObject(id, FileCacheManager(id, path, title))
-        msg = 'FileCacheManager created.'
-    else:
-        msg = 'Invalid directory path "%s"' % path
-        if REQUEST is None:
-            raise(IOError, msg)
+    self._setObject(id, FileCacheManager(id, path, tpath, title))
 
     if REQUEST is not None:
-        REQUEST.set('manage_tabs_message', msg)
+        REQUEST.set('manage_tabs_message', 'File Cache Manager created')
         return self.manage_main(self, REQUEST)
 



More information about the Zope-CVS mailing list