diff options
Diffstat (limited to 'fs/mountfs.py')
-rw-r--r-- | fs/mountfs.py | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/fs/mountfs.py b/fs/mountfs.py index 41c75b8..18f6f88 100644 --- a/fs/mountfs.py +++ b/fs/mountfs.py @@ -8,12 +8,12 @@ For example, lets say we have two filesystems containing config files and resour [config_fs] |-- config.cfg - `-- defaults.cfg + `-- defaults.cfg [resources_fs] |-- images | |-- logo.jpg - | `-- photo.jpg + | `-- photo.jpg `-- data.dat We can combine these filesystems in to a single filesystem with the following code:: @@ -31,7 +31,7 @@ This will create a single filesystem where paths under `config` map to `config_f | `-- defaults.cfg `-- resources |-- images - | |-- logo.jpg + | |-- logo.jpg | `-- photo.jpg `-- data.dat @@ -39,7 +39,7 @@ Now both filesystems can be accessed with the same path structure:: print combined_fs.getcontents('/config/defaults.cfg') read_jpg(combined_fs.open('/resources/images/logo.jpg') - + """ from fs.base import * @@ -51,14 +51,14 @@ from fs import _thread_synchronize_default class DirMount(object): def __init__(self, path, fs): self.path = path - self.fs = fs + self.fs = fs def __str__(self): return "<DirMount %s, %s>" % (self.path, self.fs) - + def __repr__(self): return "<DirMount %s, %s>" % (self.path, self.fs) - + def __unicode__(self): return u"<DirMount %s, %s>" % (self.path, self.fs) @@ -77,7 +77,7 @@ class MountFS(FS): _meta = { 'virtual': True, 'read_only' : False, 'unicode_paths' : True, - 'case_insensitive_paths' : False, + 'case_insensitive_paths' : False, } DirMount = DirMount @@ -86,7 +86,7 @@ class MountFS(FS): def __init__(self, auto_close=True, thread_synchronize=_thread_synchronize_default): self.auto_close = auto_close super(MountFS, self).__init__(thread_synchronize=thread_synchronize) - self.mount_tree = PathMap() + self.mount_tree = PathMap() def __str__(self): return "<%s [%s]>" % (self.__class__.__name__,self.mount_tree.items(),) @@ -128,11 +128,11 @@ class MountFS(FS): def close(self): # Explicitly closes children if requested if self.auto_close: - for mount in self.mount_tree.itervalues(): + for mount in self.mount_tree.itervalues(): mount.fs.close() # Free references (which may incidently call the close method of the child filesystems) - self.mount_tree.clear() - super(MountFS, self).close() + self.mount_tree.clear() + super(MountFS, self).close() def getsyspath(self, path, allow_none=False): fs, _mount_path, delegate_path = self._delegate(path) @@ -142,7 +142,7 @@ class MountFS(FS): else: raise NoSysPathError(path=path) return fs.getsyspath(delegate_path, allow_none=allow_none) - + def getpathurl(self, path, allow_none=False): fs, _mount_path, delegate_path = self._delegate(path) if fs is self or fs is None: @@ -160,7 +160,7 @@ class MountFS(FS): return "Mount dir" else: return "Mounted file" - return "Mounted dir, maps to path %s on %s" % (delegate_path, str(fs)) + return "Mounted dir, maps to path %s on %s" % (delegate_path or '/', str(fs)) @synchronize def isdir(self, path): @@ -283,7 +283,7 @@ class MountFS(FS): if not delegate_path: if allow_recreate: return - else: + else: raise DestinationExistsError(path, msg="Can not create a directory that already exists (try allow_recreate=True): %(path)s") return fs.makedir(delegate_path, recursive=recursive, allow_recreate=allow_recreate) @@ -396,9 +396,9 @@ class MountFS(FS): @synchronize def mountdir(self, path, fs): """Mounts a host FS object on a given path. - + :param path: A path within the MountFS - :param fs: A filesystem object to mount + :param fs: A filesystem object to mount """ path = abspath(normpath(path)) @@ -408,11 +408,11 @@ class MountFS(FS): @synchronize def mountfile(self, path, open_callable=None, info_callable=None): """Mounts a single file path. - + :param path: A path within the MountFS :param open_callable: A callable that returns a file-like object :param info_callable: A callable that returns a dictionary with information regarding the file-like object - + """ self.mount_tree[path] = MountFS.FileMount(path, callable, info_callable) |