Commit 07888d97 by willmcgugan@gmail.com

Applied patch to sftp that searches for ssh keys in default locations

parent dccbc1f3
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
fs.wrapfs.hidefs 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 ...@@ -12,23 +12,24 @@ from fs.errors import ResourceNotFoundError
import re import re
import fnmatch import fnmatch
class HideFS(WrapFS): class HideFS(WrapFS):
"""FS wrapper that hides resources if they match a wildcard(s). """FS wrapper that hides resources if they match a wildcard(s).
For example, to hide all pyc file and subversion directories from a filesystem:: For example, to hide all pyc file and subversion directories from a filesystem::
hide_fs = HideFS(my_fs, "*.pyc", ".svn") 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] self._hide_wildcards = [re.compile(fnmatch.translate(wildcard)) for wildcard in hide_wildcards]
super(HideFS, self).__init__(wrapped_fs) 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) return any(any(wildcard.match(part) for wildcard in self._hide_wildcards)
for part in iteratepath(path)) for part in iteratepath(path))
def _encode(self, path): def _encode(self, path):
if self._should_hide(path): if self._should_hide(path):
raise ResourceNotFoundError(path) raise ResourceNotFoundError(path)
...@@ -42,12 +43,12 @@ class HideFS(WrapFS): ...@@ -42,12 +43,12 @@ class HideFS(WrapFS):
return False return False
return super(HideFS, self).exists(path) return super(HideFS, self).exists(path)
def listdir(self, path="", *args, **kwargs): def listdir(self, path="", *args, **kwargs):
entries = super(HideFS, self).listdir(path, *args, **kwargs) entries = super(HideFS, self).listdir(path, *args, **kwargs)
entries = [entry for entry in entries if not self._should_hide(entry)] entries = [entry for entry in entries if not self._should_hide(entry)]
return entries return entries
if __name__ == "__main__": if __name__ == "__main__":
from fs.osfs import OSFS from fs.osfs import OSFS
hfs = HideFS(OSFS('~/projects/pyfilesystem'), "*.pyc", ".svn") hfs = HideFS(OSFS('~/projects/pyfilesystem'), "*.pyc", ".svn")
hfs.tree() hfs.tree()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment