diff options
author | willmcgugan@gmail.com <willmcgugan@gmail.com@67cdc799-7952-0410-af00-57a81ceafa0f> | 2012-07-03 15:46:20 +0000 |
---|---|---|
committer | willmcgugan@gmail.com <willmcgugan@gmail.com@67cdc799-7952-0410-af00-57a81ceafa0f> | 2012-07-03 15:46:20 +0000 |
commit | e347d5acf74819b8cc36f3fcd179e7f0ccfe7196 (patch) | |
tree | d4491779cbbba5ca3697168e97d76e5ac3fc40fa /fs/wrapfs | |
parent | 8b2fa273a272a4b8841c9e712e53f0532e572728 (diff) | |
download | pyfilesystem-e347d5acf74819b8cc36f3fcd179e7f0ccfe7196.tar.gz |
Applied patch to sftp that searches for ssh keys in default locations
git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@793 67cdc799-7952-0410-af00-57a81ceafa0f
Diffstat (limited to 'fs/wrapfs')
-rw-r--r-- | fs/wrapfs/hidefs.py | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/fs/wrapfs/hidefs.py b/fs/wrapfs/hidefs.py index 094d75f..c0adf32 100644 --- a/fs/wrapfs/hidefs.py +++ b/fs/wrapfs/hidefs.py @@ -2,7 +2,7 @@ fs.wrapfs.hidefs ================ -Removes resources from a directory listing if they match a given set of wildcards +Removes resources from a directory listing if they match a given set of wildcards """ @@ -12,23 +12,24 @@ from fs.errors import ResourceNotFoundError import re import fnmatch + class HideFS(WrapFS): """FS wrapper that hides resources if they match a wildcard(s). - + For example, to hide all pyc file and subversion directories from a filesystem:: - + hide_fs = HideFS(my_fs, "*.pyc", ".svn") - + """ - - def __init__(self, wrapped_fs, *hide_wildcards): + + def __init__(self, wrapped_fs, *hide_wildcards): self._hide_wildcards = [re.compile(fnmatch.translate(wildcard)) for wildcard in hide_wildcards] super(HideFS, self).__init__(wrapped_fs) - - def _should_hide(self, path): + + def _should_hide(self, path): return any(any(wildcard.match(part) for wildcard in self._hide_wildcards) for part in iteratepath(path)) - + def _encode(self, path): if self._should_hide(path): raise ResourceNotFoundError(path) @@ -42,12 +43,12 @@ class HideFS(WrapFS): return False return super(HideFS, self).exists(path) - def listdir(self, path="", *args, **kwargs): - entries = super(HideFS, self).listdir(path, *args, **kwargs) - entries = [entry for entry in entries if not self._should_hide(entry)] + def listdir(self, path="", *args, **kwargs): + entries = super(HideFS, self).listdir(path, *args, **kwargs) + entries = [entry for entry in entries if not self._should_hide(entry)] return entries if __name__ == "__main__": from fs.osfs import OSFS hfs = HideFS(OSFS('~/projects/pyfilesystem'), "*.pyc", ".svn") - hfs.tree()
\ No newline at end of file + hfs.tree() |