[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container/Views/VFS - VFSContainerView.py:1.1.2.3

Stephan Richter srichter@cbu.edu
Wed, 10 Apr 2002 05:31:22 -0400


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

Modified Files:
      Tag: Zope3-Server-Branch
	VFSContainerView.py 
Log Message:
Okay, it finally works! We have a Publisher FTP server again. All the basic
functionalitry is there, from dir listing, file transfer to security.

I punted for now on recognizing file endings, since Jim wants to write a 
proposal for that next week. Also, I did not solve the statistical file
information problem, since this takes some more research.


=== Zope3/lib/python/Zope/App/OFS/Container/Views/VFS/VFSContainerView.py 1.1.2.2 => 1.1.2.3 ===
 """
 import fnmatch
+import time
+
+from Zope.ComponentArchitecture import getView
+from Zope.Publisher.VFS.IVFSPublisher import IVFSPublisher
+
 from Zope.Publisher.VFS.IVFSDirectoryPublisher import IVFSDirectoryPublisher
+from Zope.App.OFS.Container.IContainer import IContainer 
 
+# XXX hard coded object types.
+from Zope.App.OFS.Content.File.File import File
+from Zope.App.OFS.Folder.Folder import Folder
 
 class VFSContainerView:
 
@@ -40,6 +49,7 @@
 
     def listdir(self, with_stats=0, pattern='*'):
         'See Zope.Publisher.VFS.IVFSDirectoryPublisher.IVFSDirectoryPublisher'
+        t = time.time()
         file_list = self._container.objectIds()
         # filter them using the pattern
         file_list = list(
@@ -48,19 +58,30 @@
         # sort them alphabetically
         file_list.sort()
         if not with_stats:
-            result = ld
+            result = file_list
         else:
             result = []
             for file in file_list:
-                stat = (16893, 0, 0, 0, 0, 0, 0, 0, 0, 0)
+                obj = self._container.getObject(file)
+                size = 0
+                # XXX Should be much nicer
+                if IContainer.isImplementedBy(obj):
+                    dir_mode = 16384
+                else:
+                    dir_mode = 0
+                if hasattr(obj, 'getSize'):
+                    size = obj.getSize()
+                stat = (dir_mode, 0, 0, 0, 0, 0, size, t, t, t)
                 if stat is not None:
                     result.append((file, stat))
         return result
-        
+    
 
     def mkdir(self, name, mode=777):
         'See Zope.Publisher.VFS.IVFSDirectoryPublisher.IVFSDirectoryPublisher'
-        pass
+        if not self._container.hasObject(name):
+            obj = Folder()
+            self._container.setObject(name, obj)
 
     def remove(self, name):
         'See Zope.Publisher.VFS.IVFSDirectoryPublisher.IVFSDirectoryPublisher'
@@ -77,6 +98,21 @@
         self._container.setObject(new, obj)        
 
 
+    def writefile(self, name, mode, instream, start=0):
+        'See Zope.Publisher.VFS.IVFSDirectoryPublisher.IVFSDirectoryPublisher'
+        # XXX This should become much, much smarter later. Based on the
+        # data and the file ending, it should pick the right object type. 
+        # *** Waiting for Jim's file extension proposal and code to land ***
+        if not self._container.hasObject(name):
+            obj = File()
+            self._container.setObject(name, obj)
+        else:
+            obj = self._container.getObject(name)
+
+        vfs_view = getView(obj, 'vfs', IVFSPublisher)
+        vfs_view.write(mode, instream, start)
+
+
     ######################################
     # from: Zope.Publisher.VFS.IVFSObjectPublisher.IVFSObjectPublisher
 
@@ -90,7 +126,11 @@
 
     def stat(self):
         'See Zope.Publisher.VFS.IVFSObjectPublisher.IVFSObjectPublisher'
-        return (16893, 0, 0, 0, 0, 0, 0, 0, 0, 0)
+        dir_mode = 16384
+        t = time.time()
+        uid = 0
+        gid = 0
+        return (dir_mode+0, 0, 0, 0, uid, gid, 4096, t, t, t)
 
 
     ######################################
@@ -102,8 +142,3 @@
 
     #
     ############################################################
-
-
-    def getContext(self):
-        """ """
-        return self._container