[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server/VFS - IReadFileSystem.py:1.1.2.5 IWriteFileSystem.py:1.1.2.5 OSFileSystem.py:1.1.2.13 PublisherFileSystem.py:1.1.2.4 UnixFileSystem.py:1.1.2.5

Stephan Richter srichter@cbu.edu
Tue, 9 Apr 2002 12:12:33 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Server/VFS
In directory cvs.zope.org:/tmp/cvs-serv4334/Server/VFS

Modified Files:
      Tag: Zope3-Server-Branch
	IReadFileSystem.py IWriteFileSystem.py OSFileSystem.py 
	PublisherFileSystem.py UnixFileSystem.py 
Log Message:
Check in my big mess of stuff, which is working towards making FTP work 
together with the Publisher. I will keep working on startup now, so that 
we can test easier. 

This is basically a check-in, so that Shane can see what I have done last 
night. Please do not expect anything towork, since this is more than just
work in progress... it is a prototype to get FTP running via Publisher!


=== Zope3/lib/python/Zope/Server/VFS/IReadFileSystem.py 1.1.2.4 => 1.1.2.5 ===
         """
 
-    def listdir(path, long=0):
-        """Return a listing of the directory at 'path' The empty string
-        indicates the current directory.  If 'long' is set, instead
-        return a list of (name, stat_info) tuples
+    def listdir(path, with_stats=0, pattern='*'):
+        """Return a listing of the directory at 'path' The empty
+           string indicates the current directory.  If 'with_stats' is set,
+           instead return a list of (name, stat_info) tuples. All file
+           names are filtered by the pattern, which is epected to be a regular
+           filesystem search pattern.
         """
         return list(tuple(str, str))
-
-    def longify(path, stat):
-        """Return a 'long' representation of the filename
-           [for the output of the LIST command]
-        """
 
     def readfile(path, mode, outstream, start=0, end=-1):
         """Outputs the file at path to a stream.


=== Zope3/lib/python/Zope/Server/VFS/IWriteFileSystem.py 1.1.2.4 => 1.1.2.5 ===
     """
 
-    def chmod(path, mode):
-        """Change the access permissions of a file.
-        """
-
-    def chown(path, uid, gid):
-        """Change the owner and group id of path to numeric uid and gid.
-        """
-
-    def link(src, dst):
-        """Create a heard link to a file.
-        """
-
     def mkdir(path, mode=777):
         """Create a directory.
         """
 
-    def mkfifo(path, mode=777):
-        """Create a FIFO (a POSIX named pipe).
-        """
-
     def remove(path):
         """Remove a file. Same as unlink.
         """
@@ -57,10 +41,6 @@
 
     def rename(old, new):
         """Rename a file or directory.
-        """
-
-    def symlink(src, dst):
-        """Create a symbolic link at dst pointing to src.
         """
 
     def writefile(path, mode, instream, start=0):


=== Zope3/lib/python/Zope/Server/VFS/OSFileSystem.py 1.1.2.12 => 1.1.2.13 ===
 $Id$
 """
-
 import os
 import re
 import stat
 import time
+import fnmatch
 
-from IReadFileSystem import IReadFileSystem
-from IWriteFileSystem import IWriteFileSystem
+from IPosixFileSystem import IPosixFileSystem
 
 
-class OSFileSystem:
+class OSFileSystem(object):
     """Generic OS FileSystem implementation.
 
        The root of this file system is a string describing the path
        to the directory used as root.
     """
 
-    __implements__ = IReadFileSystem, IWriteFileSystem
+    __implements__ = IPosixFileSystem
 
     path_module = os.path
 
@@ -42,10 +41,43 @@
     def __init__ (self, root):
         self.root = root
 
-
     ############################################################
     # Implementation methods for interface
-    # Zope.Server.VFS.IReadFileSystem.IReadFileSystem
+    # Zope.Server.VFS.IPosixFileSystem.IPosixFileSystem
+
+    def chmod(self, path, mode):
+        'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
+        p = self.translate (path)
+        return os.chmod(p, mode)
+
+
+    def chown(self, path, uid, gid):
+        'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
+        p = self.translate (path)
+        return os.chown(p, uid, gid)
+
+
+    def link(self, src, dst):
+        'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
+        src = self.translate(src)
+        dst = self.translate(dst)
+        return os.link(src, dst)
+
+
+    def mkfifo(self, path, mode=6*2**6):
+        'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
+        return os.mkfifo(path, mode)
+
+
+    def symlink(self, src, dst):
+        'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
+        src = self.translate(src)
+        dst = self.translate(dst)
+        return os.symlink(src, dst)
+
+
+    ######################################
+    # from: Zope.Server.VFS.IReadFileSystem.IReadFileSystem
 
     def exists(self, path):
         'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
@@ -65,14 +97,16 @@
         return self.path_module.isfile(p)
 
 
-    def listdir(self, path, long=0):
+    def listdir(self, path, with_stats=0, pattern='*'):
         'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
         p = self.translate(path)
-        # I think we should glob, but limit it to the current
-        # directory only.
+        # list the directory's files
         ld = os.listdir(p)
+        # filter them using the pattern
+        ld = filter(lambda f, p=pattern, fnm=fnmatch.fnmatch: fnm(f, p), ld)
+        # sort them alphabetically
         ld.sort()
-        if not long:
+        if not with_stats:
             result = ld
         else:
             result = []
@@ -80,13 +114,8 @@
                 path = self.path_module.join(p, file)
                 stat = safe_stat(path)
                 if stat is not None:
-                    result.append(self.longify(file, safe_stat(path)))
-        return '\r\n'.join(result) + '\r\n'
-
-
-    def longify(self, path, stat_info):
-        'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
-        return unix_longify(path, stat_info)
+                    result.append((file, stat))
+        return result
 
 
     def readfile(self, path, mode, outstream, start=0, end=-1):
@@ -112,31 +141,9 @@
         p = self.translate(path)
         return os.stat(p)
 
-    #
-    ############################################################
-
-    ############################################################
-    # Implementation methods for interface
-    # Zope.Server.VFS.IWriteFileSystem.
-
-    def chmod(self, path, mode):
-        'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
-        p = self.translate (path)
-        return os.chmod(p, mode)
-
-
-    def chown(self, path, uid, gid):
-        'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
-        p = self.translate (path)
-        return os.chown(p, uid, gid)
-
-
-    def link(self, src, dst):
-        'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
-        src = self.translate(src)
-        dst = self.translate(dst)
-        return os.link(src, dst)
 
+    ######################################
+    # from: Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem
 
     def mkdir(self, path, mode=6*2**6):
         'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
@@ -144,11 +151,6 @@
         return os.mkdir(p, mode)
 
 
-    def mkfifo(self, path, mode=6*2**6):
-        'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
-        return os.mkfifo(path, mode)
-
-
     def remove(self, path):
         'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
         p = self.translate (path)
@@ -168,13 +170,6 @@
         return os.rename(old, new)
 
 
-    def symlink(self, src, dst):
-        'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
-        src = self.translate(src)
-        dst = self.translate(dst)
-        return os.symlink(src, dst)
-
-
     def writefile(self, path, mode, instream, start=0):
         'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
         p = self.translate(path)
@@ -198,7 +193,6 @@
         f.close()
         if remove:
             os.remove(p)
-        
 
     #
     ############################################################
@@ -239,77 +233,6 @@
     def __repr__ (self):
         return '<Unix-Style Root:%s>' % self.root
 
-
-months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
-          'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
-
-mode_table = {
-        '0':'---',
-        '1':'--x',
-        '2':'-w-',
-        '3':'-wx',
-        '4':'r--',
-        '5':'r-x',
-        '6':'rw-',
-        '7':'rwx'
-        }
-
-
-def unix_longify (file, stat_info):
-        # for now, only pay attention to the lower bits
-
-    import pwd, grp
-
-    try: username = pwd.getpwuid(int(stat_info[stat.ST_UID]))[0]
-    except: username = stat_info[stat.ST_UID]
-
-    try: grpname = grp.getgrgid(int(stat_info[stat.ST_GID]))[0]
-    except: grpname = stat_info[stat.ST_GID]
-
-
-    mode = ('%o' % stat_info[stat.ST_MODE])[-3:]
-    mode = ''.join(map (lambda x: mode_table[x], mode))
-    if stat.S_ISDIR (stat_info[stat.ST_MODE]):
-        dirchar = 'd'
-    else:
-        dirchar = '-'
-    date = ls_date (long(time.time()), stat_info[stat.ST_MTIME])
-    return '%s%s %3d %-8s %-8s %8d %s %s' % (
-            dirchar,
-            mode,
-            stat_info[stat.ST_NLINK],
-            username,
-            grpname,
-            stat_info[stat.ST_SIZE],
-            date,
-            file
-            )
-
-
-def ls_date (now, t):
-    """Emulate the unix 'ls' command's date field.  it has two formats
-       - if the date is more than 180 days in the past, then it's like
-       this: Oct 19 1995 otherwise, it looks like this: Oct 19 17:33
-    """
-    try:
-        info = time.gmtime(t)
-    except:
-        info = time.gmtime(0)
-
-    # 15,600,000 == 86,400 * 180
-    if (now - t) > 15600000:
-        return '%s %2d  %d' % (
-                months[info[1]-1],
-                info[2],
-                info[0]
-                )
-    else:
-        return '%s %2d %02d:%02d' % (
-                months[info[1]-1],
-                info[2],
-                info[3],
-                info[4]
-                )
 
 
 def safe_stat (path):


=== Zope3/lib/python/Zope/Server/VFS/PublisherFileSystem.py 1.1.2.3 => 1.1.2.4 ===
 import time
 
+from cStringIO import StringIO
+
 from IReadFileSystem import IReadFileSystem
 from IWriteFileSystem import IWriteFileSystem
 
@@ -33,10 +35,11 @@
 
     __implements__ = IReadFileSystem, IWriteFileSystem
 
+    path_module = os.path
     request_factory = None
 
 
-    def __init__ (self, root):
+    def __init__ (self, root, persona):
         self.root = root
 
 
@@ -48,25 +51,29 @@
         env['command'] = command
         env['path'] = path
 
-        request = self.request_factory(StringIO(''), StringIO(''), env)
+        request = self.request_factory(StringIO(''), StringIO(), env)
+        resp = request._response
         publish(request)
-        return request.getResponse().getResult()
+        print resp.getResult()
+        return resp.getResult()
 
 
     ############################################################
     # Implementation methods for interface
-    # Zope.Server.VFS.IReadFileSystem.IReadFileSystem
+    # Zope.Server.VFS.IReadFileSystem.
 
     def exists(self, path):
         'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
         path = self.translate(path)
-        return self._execute(path, 'exists')
-
+        path, file = os.path.split(path)
+        env = {'name': file}
+        return self._execute(path, 'exists', env)
+    
 
     def isdir(self, path):
         'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
         path = self.translate(path)
-        return self._execute(path, 'isdir')
+        return self._execute(path, 'isdir', env)
 
 
     def isfile(self, path):
@@ -75,29 +82,22 @@
         return self._execute(path, 'isfile')
 
 
-    def listdir(self, path, long=0):
+    def listdir(self, path, with_stats=0, pattern='*'):
         'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
         path = self.translate(path)
-        # Returns a list of Wrapper objects representing the objects
-        # Also, the Wrapper object should contain *all* stat information
-        ld = self._execute(path, 'listdir')
-        ld.sort()
-        if not long:
-            result = ld
-        else:
-            result = map(self.longify, ld)
-        return '\r\n'.join(result) + '\r\n'
-
-
-    def longify(self, (path, stat_info)):
-        'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
-        return unix_longify (path, stat_info)
+        env = {'with_stats' : with_stats,
+               'pattern' : pattern}
+        return self._execute(path, 'listdir', env)
 
 
-    def open(self, path, mode):
+    def readfile(self, path, mode, outstream, start=0, end=-1):
         'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
         path = self.translate(path)
-        return self._execute(path, 'open', {'mode': mode})
+        env = {'mode'      : mode,
+               'outstream' : outstream,
+               'start'     : start,
+               'end'       : end}
+        return self._execute(path, 'read', env)
 
 
     def stat(self, path):
@@ -112,70 +112,60 @@
     # Implementation methods for interface
     # Zope.Server.VFS.IWriteFileSystem.
 
-    def chmod(self, path, mode):
-        'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
-        p = self.translate (path)
-        return os.chmod(p, mode)
-
-
-    def chown(self, path, uid, gid):
-        'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
-        p = self.translate (path)
-        raise NotImplementedError('This function is not implemented.')
-
-
-    def link(self, src, dst):
+    def mkdir(self, path, mode=777):
         'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
-        src = self.translate(src)
-        dst = self.translate(dst)
-        raise NotImplementedError('This function is not implemented.')
-
-
-    def mkdir(self, path, mode=6*2**6):
-        'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
-        p = self.translate(path)
-
+        path = self.translate(path)
+        path, dir = os.path.split(path)
+        env = {'name': dir}
+        return self._execute(path, 'mkdir', env)
 
-    def mkfifo(self, path, mode=6*2**6):
-        'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
-        raise NotImplementedError('This function is not implemented.')
 
     def remove(self, path):
         'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
-        p = self.translate (path)
+        path = self.translate(path)
+        path, name = os.path.split(path)
+        env = {'name': file}
+        return self._execute(path, 'remove', env)
 
 
     def rmdir(self, path):
         'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
-        p = self.translate (path)
+        path = self.translate(path)
+        path, dir = os.path.split(path)
+        env = {'name': dir}
+        return self._execute(path, 'rmdir', env)
 
 
     def rename(self, old, new):
         'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
         old = self.translate(old)
         new = self.translate(new)
+        path0, old = os.path.split(old)
+        path1, new = os.path.split(new)
+        assert path0 == path1
+        env = {'old' : old,
+               'new' : new}
+        return self._execute(path0, 'rename', env)
 
-
-    def symlink(self, src, dst):
-        'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
-        src = self.translate(src)
-        dst = self.translate(dst)
-        raise NotImplementedError('This function is not implemented.')
-
-
-    def unlink(self, path):
+    def writefile(self, path, mode, instream, start=0):
         'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
-        pass
+        path = self.translate(path)
+        env = {'mode'      : mode,
+               'outstream' : outstream,
+               'start'     : start,
+               'end'       : end}
+        return self._execute(path, 'write', env)
 
 
-    def write(self, fd, data):
+    def check_writable(self, path, mode):
         'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
-        pass
+        path = self.translate(path)
+        env = {'mode': mode}
+        return self._execute(path, 'check_writable', env)        
 
     #
     ############################################################
 
-
     # utility methods
 
     def normalize (self, path):
@@ -203,91 +193,9 @@
         # Prepare for joining with root
         if path[0] == '/':
             path = path[1:]
-        # Join path with root
-        path = self.path_module.join(self.root, path)
+
         return path
 
 
     def __repr__ (self):
-        return '<Publisher-FileSystem Root:%s>' % self.root
-
-
-
-
-months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
-          'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
-
-mode_table = {
-        '0':'---',
-        '1':'--x',
-        '2':'-w-',
-        '3':'-wx',
-        '4':'r--',
-        '5':'r-x',
-        '6':'rw-',
-        '7':'rwx'
-        }
-
-
-def unix_longify (file, stat_info):
-        # for now, only pay attention to the lower bits
-
-    import pwd, grp
-
-    try: username = pwd.getpwuid(int(stat_info[stat.ST_UID]))[0]
-    except: username = stat_info[stat.ST_UID]
-
-    try: grpname = grp.getgrgid(int(stat_info[stat.ST_GID]))[0]
-    except: grpname = stat_info[stat.ST_GID]
-
-
-    mode = ('%o' % stat_info[stat.ST_MODE])[-3:]
-    mode = ''.join(map (lambda x: mode_table[x], mode))
-    if stat.S_ISDIR (stat_info[stat.ST_MODE]):
-        dirchar = 'd'
-    else:
-        dirchar = '-'
-    date = ls_date (long(time.time()), stat_info[stat.ST_MTIME])
-    return '%s%s %3d %-8s %-8s %8d %s %s' % (
-            dirchar,
-            mode,
-            stat_info[stat.ST_NLINK],
-            username,
-            grpname,
-            stat_info[stat.ST_SIZE],
-            date,
-            file
-            )
-
-
-def ls_date (now, t):
-    """Emulate the unix 'ls' command's date field.  it has two formats
-       - if the date is more than 180 days in the past, then it's like
-       this: Oct 19 1995 otherwise, it looks like this: Oct 19 17:33
-    """
-    try:
-        info = time.gmtime(t)
-    except:
-        info = time.gmtime(0)
-
-    # 15,600,000 == 86,400 * 180
-    if (now - t) > 15600000:
-        return '%s %2d  %d' % (
-                months[info[1]-1],
-                info[2],
-                info[0]
-                )
-    else:
-        return '%s %2d %02d:%02d' % (
-                months[info[1]-1],
-                info[2],
-                info[3],
-                info[4]
-                )
-
-
-def safe_stat (path):
-    try:
-        return os.stat(path)
-    except:
-        return None
+        return '<Publisher-FileSystem Root:Data.fs>'


=== Zope3/lib/python/Zope/Server/VFS/UnixFileSystem.py 1.1.2.4 => 1.1.2.5 ===
 
     # Get process information
-    PROCESS_UID                = os.getuid()
+    PROCESS_UID         = os.getuid()
     PROCESS_EUID        = os.geteuid()
-    PROCESS_GID                = os.getgid()
+    PROCESS_GID         = os.getgid()
     PROCESS_EGID        = os.getegid()
 
 
     def __init__ (self, root, persona=(None, None)):
-        super(SchizophrenicUnixFileSystem, self).__init__(root, wd)
+        super(SchizophrenicUnixFileSystem, self).__init__(root)
         self.persona = persona