[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server/VFS - IReadFileSystem.py:1.1.2.1 IWriteFileSystem.py:1.1.2.1 OSFileSystem.py:1.1.2.2 UnixFileSystem.py:1.1.2.2 ZODBFileSystem.py:1.1.2.2 IFileSystem.py:NONE
Stephan Richter
srichter@cbu.edu
Tue, 2 Apr 2002 11:57:26 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Server/VFS
In directory cvs.zope.org:/tmp/cvs-serv3472
Modified Files:
Tag: Zope3-Server-Branch
OSFileSystem.py UnixFileSystem.py ZODBFileSystem.py
Added Files:
Tag: Zope3-Server-Branch
IReadFileSystem.py IWriteFileSystem.py
Removed Files:
Tag: Zope3-Server-Branch
IFileSystem.py
Log Message:
Issue 48: Comment
Some changes to the FileSystem implementation. I added some more
functionality to the interfaces, so that we can truely map a Filesystem.
Most of the ideas for the new methods came from the os and os.path module.
Until now the Filesystem was also able to store state, which has been re-
moved now. The state should be stored in some other object, such as the
channel in the case of a FTP server.
I am going to write the tests now, so the code should be functional later
today.
=== Added File Zope3/lib/python/Zope/Server/VFS/IReadFileSystem.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: IReadFileSystem.py,v 1.1.2.1 2002/04/02 16:57:25 srichter Exp $
"""
from Interface import Interface
class IReadFileSystem(Interface):
"""We want to provide a complete wrapper around any and all read
filesystem operations.
Opening files for reading, and listing directories, should
return a producer.
Note: A file system should *not* store any state!
"""
def exists(path):
"""Test whether a path exists.
"""
def isdir(path):
"""Test whether a path is a directory.
"""
def isfile(path):
"""Test whether a path is a file.
"""
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
"""
return list(tuple(str, str))
def longify(path):
"""Return a 'long' representation of the filename
[for the output of the LIST command]
"""
def open(path, mode):
"""Return an open file object.
"""
return file
def stat(path):
"""Return the equivalent of os.stat() on the given path:
(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)
"""
=== Added File Zope3/lib/python/Zope/Server/VFS/IWriteFileSystem.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: IWriteFileSystem.py,v 1.1.2.1 2002/04/02 16:57:25 srichter Exp $
"""
from Interface import Interface
class IWriteFileSystem(Interface):
"""We want to provide a complete wrapper around any and all write
filesystem operations.
Notes:
- A file system should *not* store any state!
- Most of the commands copy the functionality given in os.
"""
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():
"""Create a FIFO (a POSIX named pipe).
"""
def remove():
"""Remove a file. Same as unlink.
"""
def rmdir(path):
"""Remove a directory.
"""
def rename(old, new):
"""Rename a file or directory.
"""
def symlink(src, dst):
"""Create a symbolic link at dst pointing to src.
"""
def unlink(path):
"""Remove file. Same as remove.
"""
def write(fd, data):
"""Write the data to a file descriptor.
Returns the number of bytes written.
"""
return int
=== Zope3/lib/python/Zope/Server/VFS/OSFileSystem.py 1.1.2.1 => 1.1.2.2 ===
"""
-import os, re
+import os
+import re
import stat
import time
-from IFileSystem import IFileSystem
+from IReadFileSystem import IReadFileSystem
+from IWriteFileSystem import IWriteFileSystem
class OSFileSystem:
"""Generic OS FileSystem implementation.
+
+ The root of this file system is a string describing the path
+ to the directory used as root.
"""
- __implements__ = IFileSystem
+ __implements__ = IReadFileSystem, IWriteFileSystem
path_module = os.path
- # set this to zero if you want to disable pathname globbing.
- # [we currently don't glob, anyway]
- do_globbing = 1
-
- def __init__ (self, root, wd='/'):
+
+ def __init__ (self, root):
self.root = root
- self.wd = wd
+
############################################################
# Implementation methods for interface
- # Zope.Server.VFS.IFileSystem
+ # Zope.Server.VFS.IReadFileSystem.IReadFileSystem
- def current_directory(self):
- 'See Zope.Server.VFS.IFileSystem.IFileSystem'
- return self.wd
+ def exists(self, path):
+ 'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
+ p = self.normalize (self.path_module.join (self.wd, path))
+ return self.path_module.exists(self.translate(p))
+
+
+ def isdir(self, path):
+ 'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
+ p = self.normalize(self.path_module.join (self.wd, path))
+ return self.path_module.isdir(self.translate(p))
+
+
+ def isfile(self, path):
+ 'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
+ p = self.normalize(self.path_module.join(self.wd, path))
+ return self.path_module.isfile(self.translate(p))
def listdir(self, path, long=0):
- 'See Zope.Server.VFS.IFileSystem.IFileSystem'
+ 'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
p = self.translate (path)
# I think we should glob, but limit it to the current
# directory only.
@@ -67,81 +82,99 @@
return list_producer (result, 1, self.longify)
+ def longify(self, path):
+ 'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
+ return unix_longify (path, stat_info)
+
+
def open(self, path, mode):
- 'See Zope.Server.VFS.IFileSystem.IFileSystem'
- p = self.translate (path)
- return open (p, mode)
+ 'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
+ p = self.translate(path)
+ return open(p, mode)
- # XXX: implement a cache w/timeout for stat()
def stat(self, path):
- 'See Zope.Server.VFS.IFileSystem.IFileSystem'
+ 'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
p = self.translate(path)
return os.stat (p)
+ #
+ ############################################################
- def isdir(self, path):
- 'See Zope.Server.VFS.IFileSystem.IFileSystem'
- p = self.normalize (self.path_module.join (self.wd, path))
- return self.path_module.isdir (self.translate(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 isfile(self, path):
- 'See Zope.Server.VFS.IFileSystem.IFileSystem'
- p = self.normalize (self.path_module.join (self.wd, path))
- return self.path_module.isfile (self.translate(p))
+ def chown(self, path, uid, gid):
+ 'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
+ p = self.translate (path)
+ return os.chown(p, uid, gid)
- def cwd(self, path):
- 'See Zope.Server.VFS.IFileSystem.IFileSystem'
- p = self.normalize (self.path_module.join (self.wd, path))
- translated_path = self.translate(p)
- if not self.path_module.isdir (translated_path):
- return 0
- else:
- old_dir = os.getcwd()
- # temporarily change to that directory, in order
- # to see if we have permission to do so.
- try:
- can = 0
- try:
- os.chdir (translated_path)
- can = 1
- self.wd = p
- except:
- pass
- finally:
- if can:
- os.chdir (old_dir)
- return can
+ 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 cdup(self):
- 'See Zope.Server.VFS.IFileSystem.IFileSystem'
- return self.cwd('..')
+ def mkdir(self, path, mode=777):
+ 'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
+ p = self.translate (path)
+ return os.mkdir(p)
- def longify(self, path):
- 'See Zope.Server.VFS.IFileSystem.IFileSystem'
- return unix_longify (path, stat_info)
- #
- ############################################################
+ def mkfifo(self):
+ 'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
+ return os.mkfifo()
-
- def unlink (self, path):
- p = self.translate (path)
- return os.unlink (p)
-
- def mkdir (self, path):
+
+ def remove(self):
+ 'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
p = self.translate (path)
- return os.mkdir (p)
-
- def rmdir (self, path):
+ return os.remove(p)
+
+
+ def rmdir(self, path):
+ 'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
p = self.translate (path)
- return os.rmdir (p)
+ return os.rmdir(p)
+
+
+ def rename(self, old, new):
+ 'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
+ old = self.translate(old)
+ new = self.translate(new)
+ 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 unlink(self, path):
+ 'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
+ p = self.translate(path)
+ return os.unlink(p)
+
+
+ def write(self, fd, data):
+ 'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
+ return os.write(fd, data)
+
+ #
+ ############################################################
+
-
# utility methods
def normalize (self, path):
@@ -163,6 +196,7 @@
p = self.normalize(self.path_module.join(self.wd, path))
p = self.normalize(self.path_module.join(self.root, p[1:]))
return p
+
def __repr__ (self):
return '<Unix-Style FS Root:%s CWD:%s>' % (self.root, self.wd)
=== Zope3/lib/python/Zope/Server/VFS/UnixFileSystem.py 1.1.2.1 => 1.1.2.2 ===
- def __init__ (self, root, wd='/', persona=(None, None)):
+ def __init__ (self, root, persona=(None, None)):
super(SchizophrenicUnixFileSystem, self).__init__(root, wd)
self.persona = persona
@@ -61,28 +61,10 @@
############################################################
# Implementation methods for interface
- # Zope.Server.VFS.IFileSystem
-
- def cwd (self, path):
- 'See Zope.Server.VFS.IFileSystem.IFileSystem'
- try:
- self.become_persona()
- return super(SchizophrenicUnixFileSystem, self).cwd(path)
- finally:
- self.become_nobody()
-
-
- def cdup (self, path):
- 'See Zope.Server.VFS.IFileSystem.IFileSystem'
- try:
- self.become_persona()
- return super(SchizophrenicUnixFileSystem, self).cdup()
- finally:
- self.become_nobody()
-
+ # Zope.Server.VFS.IReadFileSystem.IReadFileSystem
def open (self, filename, mode):
- 'See Zope.Server.VFS.IFileSystem.IFileSystem'
+ 'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
try:
self.become_persona()
return super(SchizophrenicUnixFileSystem, self).open(filename,
@@ -92,7 +74,7 @@
def listdir (self, path, long=0):
- 'See Zope.Server.VFS.IFileSystem.IFileSystem'
+ 'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
try:
self.become_persona()
return super(SchizophrenicUnixFileSystem, self).listdir(path, long)
=== Zope3/lib/python/Zope/Server/VFS/ZODBFileSystem.py 1.1.2.1 => 1.1.2.2 ===
import time
-from IFileSystem import IFileSystem
+from IReadFileSystem import IReadFileSystem
+from IWriteFileSystem import IWriteFileSystem
+
from ListProducer import ListProducer
-from Zope.App.Traversing.ITraverser import ITraverser
-from Zope.ComponentArchitecture import getAdapter
-from Zope.App.OFS.Container.IContainer import IContainer
+from IZODBDirectory import IZODBDirectory
from Zope.ContextWrapper import wrapper
class ZODBFileSystem:
- """Generic OS FileSystem implementation.
+ """Generic ZODB FileSystem implementation.
"""
- __implements__ = IFileSystem
+ __implements__ = IReadFileSystem, IWriteFileSystem
+
+
+ container_interface = IDirectory
+
+
+ def __init__ (self, zodb):
+ self._zodb = zodb
- def __init__ (self, publication, init_path='/'):
- self._publication = publication
- self._current = publication.traverse(init_path)
############################################################
# Implementation methods for interface
- # Zope.Server.VFS.IFileSystem
-
- def current_directory(self):
- 'See Zope.Server.VFS.IFileSystem.IFileSystem'
- traverser = getAdapter(self._current, ITraverser)
- return '/' + '/'.join(traverser.getPhysicalPath())
+ # Zope.Server.VFS.IReadFileSystem.IReadFileSystem
def listdir(self, path, long=0):
@@ -88,29 +87,6 @@
path = self.normalize('/'.join (self.current_directory(), path))
object = self._publication.traverse(path)
return not IContainer.isImplementedBy(object)
-
-
- def cwd(self, path):
- 'See Zope.Server.VFS.IFileSystem.IFileSystem'
- path = self.normalize('/'.join (self.wd, path))
- path = self.translate(path)
- try:
- self._current = self._publication.traverse(path)
- return 1
- except:
- return 0
-
-
- def cdup(self):
- 'See Zope.Server.VFS.IFileSystem.IFileSystem'
-
- parent = wrapper.getContext(self._current)
-
- if parent is not None:
- self._current = parent
- return 1
- else:
- return 0
def longify(self, object):
=== Removed File Zope3/lib/python/Zope/Server/VFS/IFileSystem.py ===