[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Content/Folder/Views/VFS - FolderView.py:1.2

Stephan Richter srichter@cbu.edu
Mon, 23 Dec 2002 03:16:07 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Content/Folder/Views/VFS
In directory cvs.zope.org:/tmp/cvs-serv26132/Zope/App/OFS/Content/Folder/Views/VFS

Modified Files:
	FolderView.py 
Log Message:
Implemented VFS views for the Local Service Manager. You can now traverse
into it up to Packages. 

Since Jim did not tell me what he wanted to do in a Package, I did not 
add much there, so that all Services are shown as directories now. The 
only binding I implemented was for the ZPTTemplate, which works fine so
that you can add ZPTs via VFS now. I could imagine doing the same for 
Module, but other than that Package is rather boring from a VFS point of
view.

Of course we could do some "magic" and display a text (file content) 
representation of the various services, but I do not know how useful this 
would be.


=== Zope3/lib/python/Zope/App/OFS/Content/Folder/Views/VFS/FolderView.py 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/App/OFS/Content/Folder/Views/VFS/FolderView.py:1.1	Fri Dec 20 05:31:47 2002
+++ Zope3/lib/python/Zope/App/OFS/Content/Folder/Views/VFS/FolderView.py	Mon Dec 23 03:15:36 2002
@@ -15,7 +15,11 @@
 
 $Id$
 """
+import datetime
+zerotime = datetime.datetime.fromtimestamp(0)
 
+from Zope.ComponentArchitecture import getAdapter
+from Zope.App.DublinCore.IZopeDublinCore import IZopeDublinCore
 from Zope.App.OFS.Container.Views.VFS.VFSContainerView import \
      VFSContainerView
 
@@ -25,3 +29,39 @@
     __implments__ = VFSContainerView.__implements__
 
     _directory_type = 'Folder'
+
+    def _getServiceManagerStat(self):
+        """Get the stat information of the local service manager."""
+        # XXX ServiceManager does not use the DublinCore to keep track of its
+        # creation and modification times, so we use the data of the Folder
+        # right now.
+        dc = getAdapter(self.context, IZopeDublinCore)
+        if dc is not None:
+            created = dc.created
+            modified = dc.modified
+        else:
+            created = zerotime
+            modified = zerotime
+        if modified is None:
+            modified = created
+        dir_mode = 16384 + 504
+        uid = "nouser"
+        gid = "nogroup"
+        return (dir_mode, 0, 0, 0, uid, gid, 4096, modified, modified,
+                created)
+
+
+    def exists(self, name):
+        'See Zope.Publisher.VFS.IVFSDirectoryPublisher.IVFSDirectoryPublisher'
+        if self.context.hasServiceManager() and name == '++etc++Services':
+            return True
+        return super(FolderView, self).exists(name)
+
+
+    def listdir(self, with_stats=0, pattern='*'):
+        'See Zope.Publisher.VFS.IVFSDirectoryPublisher.IVFSDirectoryPublisher' 
+        result = super(FolderView, self).listdir(with_stats, pattern)
+        if self.context.hasServiceManager():
+            result = [('++etc++Services', self._getServiceManagerStat())] \
+                     + result
+        return result