[CMF-checkins] CVS: CMF - DirectoryView.py:1.6

Martijn Pieters mj@digicool.com
Tue, 10 Apr 2001 16:10:31 -0400 (EDT)


Update of /cvs-repository/CMF/CMFCore
In directory korak:/tmp/cvs-serv31387/CMFCore

Modified Files:
	DirectoryView.py 
Log Message:
Issue PTK(242)[]: Reloading Directory Views

Made Directory View objects auto-reload in Zope Debug mode when the
directory they represent has changed.



--- Updated File DirectoryView.py in package CMF --
--- DirectoryView.py	2001/04/10 15:52:09	1.5
+++ DirectoryView.py	2001/04/10 20:10:29	1.6
@@ -89,8 +89,7 @@
 import Globals
 from Globals import HTMLFile, Persistent
 import os
-from os import path
-from os import listdir
+from os import path, listdir, stat
 from Acquisition import aq_inner, aq_parent, aq_base
 from string import split, rfind, strip
 from App.Common import package_home
@@ -136,6 +135,7 @@
 
 class DirectoryInformation:
     data = None
+    _v_last_read = 0
 
     def __init__(self, expanded_fp, minimal_fp):
         self.filepath = minimal_fp
@@ -183,9 +183,18 @@
         return types
 
     def getContents(self, registry):
-        if self.data is None:
+        changed = 0
+        if Globals.DevelopmentMode:
+            try: mtime = stat(expandpath(self.filepath))[8]
+            except: mtime = 0
+            if mtime != self._v_last_read:
+                self._v_last_read = mtime
+                changed = 1
+
+        if self.data is None or changed:
             try:
-                self.data, self.objects = self.prepareContents(registry)
+                self.data, self.objects = self.prepareContents(registry,
+                    register_subdirs=changed)
             except:
                 # DEBUG
                 import traceback
@@ -195,7 +204,7 @@
                 self.objects = ()
         return self.data, self.objects
 
-    def prepareContents(self, registry):
+    def prepareContents(self, registry, register_subdirs=0):
         # Creates objects for each file.
         fp = expandpath(self.filepath)
         data = {}
@@ -208,9 +217,14 @@
             e_filepath = path.join(self.filepath, entry)
             e_fp = expandpath(e_filepath)
             if path.isdir(e_fp):
-                # Add a subdirectory only if it was
-                # previously registered.
+                # Add a subdirectory only if it was previously registered,
+                # unless register_subdirs is set.
                 info = registry.getDirectoryInfo(e_filepath)
+                if info is None and register_subdirs:
+                    # Register unknown subdirs
+                    if entry not in ('CVS', 'SVN', '.', '..'):
+                        registry.registerDirectoryByPath(e_fp)
+                        info = registry.getDirectoryInfo(e_filepath)
                 if info is not None:
                     mt = types.get(entry)
                     t = None