summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbtimby <btimby@67cdc799-7952-0410-af00-57a81ceafa0f>2012-04-23 19:58:07 +0000
committerbtimby <btimby@67cdc799-7952-0410-af00-57a81ceafa0f>2012-04-23 19:58:07 +0000
commitcdc8c72116aa953f3c78119610231b7c61928ab6 (patch)
tree99f3c3e61d91e97507c25c0a8a7c8644da61ad07
parentfe86e23b130112ee5930ffb30e1d3f159f11874b (diff)
downloadpyfilesystem-cdc8c72116aa953f3c78119610231b7c61928ab6.tar.gz
Take advantage of MountFS.close(), allow turning auto_mount off.
git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@784 67cdc799-7952-0410-af00-57a81ceafa0f
-rw-r--r--fs/contrib/archivefs.py39
1 files changed, 20 insertions, 19 deletions
diff --git a/fs/contrib/archivefs.py b/fs/contrib/archivefs.py
index c88d46c..be55e03 100644
--- a/fs/contrib/archivefs.py
+++ b/fs/contrib/archivefs.py
@@ -195,15 +195,15 @@ class ArchiveFS(FS):
class ArchiveMountFS(mountfs.MountFS):
'''A subclass of MountFS that automatically identifies archives. Once identified
archives are mounted in place of the archive file.'''
- def __init__(self, rootfs, **kwargs):
- super(ArchiveMountFS, self).__init__(**kwargs)
+ def __init__(self, rootfs, auto_mount=True):
+ self.auto_mount = auto_mount
+ super(ArchiveMountFS, self).__init__(auto_close=True)
self.rootfs = rootfs
self.mountdir('/', rootfs)
def __del__(self):
- # Umount everything that we mounted.
- for mountpoint in self.mount_tree.keys():
- self.unmount(mountpoint)
+ # Close automatically.
+ self.close()
def ismount(self, path):
try:
@@ -213,20 +213,21 @@ class ArchiveMountFS(mountfs.MountFS):
return type(object) is mountfs.MountFS.DirMount
def _delegate(self, path):
- for ppath in recursepath(path)[1:]:
- # Don't mount again...
- if self.ismount(ppath):
- break
- if libarchive.is_archive_name(ppath):
- # It looks like an archive, try mounting it.
- full_path = self.rootfs.getsyspath(ppath)
- try:
- self.mountdir(ppath, ArchiveFS(full_path, 'r'))
- except:
- pass # Must NOT have been an archive after all
- # Stop recursing path, we support just one archive per path!
- # No nested archives yet!
- break
+ if self.auto_mount:
+ for ppath in recursepath(path)[1:]:
+ # Don't mount again...
+ if self.ismount(ppath):
+ break
+ if libarchive.is_archive_name(ppath):
+ # It looks like an archive, try mounting it.
+ full_path = self.rootfs.getsyspath(ppath)
+ try:
+ self.mountdir(ppath, ArchiveFS(full_path, 'r'))
+ except:
+ pass # Must NOT have been an archive after all
+ # Stop recursing path, we support just one archive per path!
+ # No nested archives yet!
+ break
return super(ArchiveMountFS, self)._delegate(path)
# TODO: probably need to override move(), movedir() and any other methods