summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrfkelly0 <rfkelly0@67cdc799-7952-0410-af00-57a81ceafa0f>2009-05-05 06:19:10 +0000
committerrfkelly0 <rfkelly0@67cdc799-7952-0410-af00-57a81ceafa0f>2009-05-05 06:19:10 +0000
commitc65eec8a1227d97fce643e2995f21834c83a1b1c (patch)
tree28af60376e3505c18f42a7f9c95bb8c385719851
parent3e3d79eb3186e960757aef1a4d54dff9bebbea52 (diff)
downloadpyfilesystem-c65eec8a1227d97fce643e2995f21834c83a1b1c.tar.gz
MountFS compatability with latest test suite
git-svn-id: http://pyfilesystem.googlecode.com/svn/branches/rfk-ideas@133 67cdc799-7952-0410-af00-57a81ceafa0f
-rw-r--r--fs/mountfs.py75
1 files changed, 39 insertions, 36 deletions
diff --git a/fs/mountfs.py b/fs/mountfs.py
index e00d2f6..09223a0 100644
--- a/fs/mountfs.py
+++ b/fs/mountfs.py
@@ -4,27 +4,32 @@ from base import *
from objecttree import ObjectTree
from memoryfs import MemoryFS
-class MountFS(FS):
- """A filesystem that delegates to other filesystems."""
+class DirMount(object):
+ def __init__(self, path, fs):
+ self.path = path
+ self.fs = fs
- class DirMount(object):
- def __init__(self, path, fs):
- self.path = path
- self.fs = fs
+ def __str__(self):
+ return "Mount point: %s"%self.path
- def __str__(self):
- return "Mount point: %s"%self.path
- class FileMount(object):
- def __init__(self, path, open_callable, info_callable=None):
- self.open_callable = open_callable
- def no_info_callable(path):
- return {}
- self.info_callable = info_callable or no_info_callable
+class FileMount(object):
+ def __init__(self, path, open_callable, info_callable=None):
+ self.open_callable = open_callable
+ def no_info_callable(path):
+ return {}
+ self.info_callable = info_callable or no_info_callable
+
+
+class MountFS(FS):
+ """A filesystem that delegates to other filesystems."""
+
+ DirMount = DirMount
+ FileMount = FileMount
- def __init__(self, thread_syncronize=True):
- FS.__init__(self, thread_syncronize=thread_syncronize)
+ def __init__(self, thread_synchronize=True):
+ FS.__init__(self, thread_synchronize=thread_synchronize)
self.mount_tree = ObjectTree()
def __str__(self):
@@ -66,7 +71,7 @@ class MountFS(FS):
try:
fs, mount_path, delegate_path = self._delegate(path)
if fs is None:
- raise ResourceNotFoundError("NO_RESOURCE", path)
+ raise ResourceNotFoundError(path)
if fs is self:
object = self.mount_tree.get(path, None)
@@ -82,7 +87,7 @@ class MountFS(FS):
try:
fs, mount_path, delegate_path = self._delegate(path)
if fs is None:
- return ResourceNotFoundError("NO_RESOURCE", path)
+ return ResourceNotFoundError(path)
if fs is self:
object = self.mount_tree.get(path, None)
@@ -92,7 +97,7 @@ class MountFS(FS):
finally:
self._lock.release()
- def listdir(self, path="/", wildcard=None, full=False, absolute=False, hidden=True, dirs_only=False, files_only=False):
+ def listdir(self, path="/", wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False):
self._lock.acquire()
try:
@@ -100,7 +105,7 @@ class MountFS(FS):
fs, mount_path, delegate_path = self._delegate(path)
if fs is None:
- raise ResourceNotFoundError("NO_DIR", path)
+ raise DirectoryNotFoundError(path)
if fs is self:
if files_only:
@@ -112,7 +117,6 @@ class MountFS(FS):
wildcard,
full,
absolute,
- hidden,
dirs_only,
files_only)
else:
@@ -120,7 +124,6 @@ class MountFS(FS):
wildcard=wildcard,
full=False,
absolute=False,
- hidden=hidden,
dirs_only=dirs_only,
files_only=files_only)
if full or absolute:
@@ -134,14 +137,14 @@ class MountFS(FS):
finally:
self._lock.release()
- def makedir(self, path, mode=0777, recursive=False, allow_recreate=False):
+ def makedir(self, path, recursive=False, allow_recreate=False):
path = normpath(path)
self._lock.acquire()
try:
fs, mount_path, delegate_path = self._delegate(path)
if fs is self:
- raise UnsupportedError("UNSUPPORTED", msg="Can only makedir for mounted paths" )
- return fs.makedir(delegate_path, mode, recursive=recursive, allow_recreate=allow_recreate)
+ raise UnsupportedError("make directory", msg="Can only makedir for mounted paths" )
+ return fs.makedir(delegate_path, recursive=recursive, allow_recreate=allow_recreate)
finally:
self._lock.release()
@@ -158,7 +161,7 @@ class MountFS(FS):
fs, mount_path, delegate_path = self._delegate(path)
if fs is None:
- raise ResourceNotFoundError("NO_FILE", path)
+ raise FileNotFoundError(path)
return fs.open(delegate_path, mode, **kwargs)
@@ -190,9 +193,9 @@ class MountFS(FS):
path = normpath(path)
fs, mount_path, delegate_path = self._delegate(path)
if fs is None:
- raise ResourceNotFoundError("NO_FILE", path)
+ raise FileNotFoundError(path)
if fs is self:
- raise UnsupportedError("UNSUPPORTED", msg="Can only remove paths within a mounted dir" )
+ raise UnsupportedError("remove file", msg="Can only remove paths within a mounted dir")
return fs.remove(delegate_path)
finally:
@@ -207,10 +210,10 @@ class MountFS(FS):
fs, mount_path, delegate_path = self._delegate(path)
if fs is None or fs is self:
- raise OperationFailedError("REMOVEDIR_FAILED", path, msg="Can not removedir for an un-mounted path")
+ raise ResourceInvalidError(path, msg="Can not removedir for an un-mounted path")
if not force and not fs.isdirempty(delegate_path):
- raise OperationFailedError("REMOVEDIR_FAILED", "Directory is not empty: %(path)s")
+ raise DirectoryNotEmptyError("Directory is not empty: %(path)s")
return fs.removedir(delegate_path, recursive, force)
@@ -228,7 +231,7 @@ class MountFS(FS):
fs2, mount_path2, delegate_path2 = self._delegate(dst)
if fs1 is not fs2:
- raise OperationFailedError("RENAME_FAILED", src)
+ raise OperationFailedError("rename resource", path=src)
if fs1 is not self:
return fs1.rename(delegate_path1, delegate_path2)
@@ -240,11 +243,11 @@ class MountFS(FS):
object2 = self.mount_tree.get(path_dst, None)
if object1 is None:
- raise NoResourceError("NO_RESOURCE", src)
+ raise ResourceNotFoundError(src)
# TODO!
- raise UnsupportedError("UNSUPPORTED", src)
+ raise UnsupportedError("rename resource", path=src)
finally:
self._lock.release()
@@ -280,7 +283,7 @@ class MountFS(FS):
fs, mount_path, delegate_path = self._delegate(path)
if fs is None:
- raise ResourceNotFoundError("NO_RESOURCE", path)
+ raise ResourceNotFoundError(path)
if fs is self:
if self.isfile(path):
@@ -297,13 +300,13 @@ class MountFS(FS):
fs, mount_path, delegate_path = self._delegate(path)
if fs is None:
- raise ResourceNotFoundError("NO_FILE", path)
+ raise FileNotFoundError(path)
if fs is self:
object = self.mount_tree.get(path, None)
if object is None or isinstance(object, dict):
- raise ResourceNotFoundError("NO_FILE", path)
+ raise FileNotFoundError(path)
size = self.mount_tree[path].info_callable(path).get("size", None)
return size