Commit dccbc1f3 by willmcgugan

Fixes for hide fs

parent 1086125b
...@@ -170,9 +170,6 @@ class FS(object): ...@@ -170,9 +170,6 @@ class FS(object):
else: else:
self._lock = DummyLock() self._lock = DummyLock()
def __repr__(self):
return self.__str__()
def __del__(self): def __del__(self):
if not getattr(self, 'closed', True): if not getattr(self, 'closed', True):
try: try:
......
...@@ -45,6 +45,7 @@ from fs.filelike import FileWrapper ...@@ -45,6 +45,7 @@ from fs.filelike import FileWrapper
class EVENT(object): class EVENT(object):
"""Base class for change notification events.""" """Base class for change notification events."""
def __init__(self,fs,path): def __init__(self,fs,path):
super(EVENT, self).__init__()
self.fs = fs self.fs = fs
if path is not None: if path is not None:
path = abspath(normpath(path)) path = abspath(normpath(path))
......
...@@ -7,7 +7,8 @@ Removes resources from a directory listing if they match a given set of wildcard ...@@ -7,7 +7,8 @@ Removes resources from a directory listing if they match a given set of wildcard
""" """
from fs.wrapfs import WrapFS from fs.wrapfs import WrapFS
from fs.path import basename from fs.path import iteratepath
from fs.errors import ResourceNotFoundError
import re import re
import fnmatch import fnmatch
...@@ -16,7 +17,7 @@ class HideFS(WrapFS): ...@@ -16,7 +17,7 @@ class HideFS(WrapFS):
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::
HideFS(my_fs, "*.pyc", ".svn") hide_fs = HideFS(my_fs, "*.pyc", ".svn")
""" """
...@@ -24,16 +25,23 @@ class HideFS(WrapFS): ...@@ -24,16 +25,23 @@ class HideFS(WrapFS):
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, name): def _should_hide(self, path):
name = basename(name) return any(any(wildcard.match(part) for wildcard in self._hide_wildcards)
return any(wildcard.match(name) for wildcard in self._hide_wildcards) for part in iteratepath(path))
def _encode(self, path): def _encode(self, path):
if self._should_hide(path):
raise ResourceNotFoundError(path)
return path return path
def _decode(self, path): def _decode(self, path):
return path return path
def exists(self, path):
if self._should_hide(path):
return False
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)]
......
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