1
from zope.interface import Interface, Attribute
3
class VFSError(Exception):
4
"""Base class for all VFS errors."""
6
class PermissionError(VFSError):
7
"""The user does not have permission to perform the requested operation."""
9
class NotFoundError(VFSError):
10
"""The file or directory does not exist."""
12
class AlreadyExistsError(VFSError):
13
"""The file or directory already exists."""
16
class IFileSystemNode(Interface):
24
returns a map of arbitrary metadata. As an example, here's what SFTP
25
expects (but doesn't require):
27
- C{'size'}: size of file in bytes
28
- C{'uid'}: owner of the file
29
- C{'gid'}: group owner of the file
30
- C{'permissions'}: file permissions
31
- C{'atime'}: last time the file was accessed
32
- C{'mtime'}: last time the file was modified
33
- C{'nlink'}: number of links to the file
35
Protocols that need metadata should handle the case when a particular
36
value isn't available as gracefully as possible.
39
# XXX: There should be a setMetadata, probably taking a map of the same form
40
# returned by getMetadata (although obviously keys like 'nlink' aren't
41
# settable. Something like:
42
# def setMetadata(metadata):
43
# """Sets metadata for a node.
45
# Unrecognised keys will be ignored (but invalid values for a recognised
46
# key may cause an error to be raised).
48
# Typical keys are 'permissions', 'uid', 'gid', 'atime' and 'mtime'.
50
# @param metadata: a dict, like the one getMetadata returns.
52
# osfs.OSNode implements this; other backends should be similarly updated.
58
An error is raised if the node is a directory and is not empty.
63
Renames this node to newName. newName can be in a different
64
directory. If the destination is an existing directory, an
69
class IFileSystemLeaf(IFileSystemNode):
72
Opens the file with flags. Flags should be a bitmask based on
77
"""closes this node"""
79
def readChunk(offset, length):
81
Leaf should have been previously opened with suitable flags.
82
Reads length bytes or until the end of file from this leaf from
86
def writeChunk(offset, data):
88
Leaf should have been previously opened with suitable flags.
89
Writes data to leaf from the given offset.
92
class IFileSystemContainer(IFileSystemNode):
96
returns a list of 2 element tuples
97
[ ( path, nodeObject ) ]
100
def child(childName):
102
Returns a node object for child childName
104
@raises NotFoundError if no child with that name exists.
107
def createDirectory(childName):
109
Creates a new folder named childName under this folder.
110
An error is raised if the folder already exists.
113
def createFile(childName, exclusive=True):
115
Creates a new file named childName under this folder.
117
If exclusive is True (the default), an AlreadyExistsError is raised if
118
the file already exists.
121
def exists(childName):
123
returns True if container has a child childName, False otherwise