Commit dccbc1f3 by willmcgugan

Fixes for hide fs

parent 1086125b
......@@ -170,9 +170,6 @@ class FS(object):
else:
self._lock = DummyLock()
def __repr__(self):
return self.__str__()
def __del__(self):
if not getattr(self, 'closed', True):
try:
......
......@@ -45,6 +45,7 @@ from fs.filelike import FileWrapper
class EVENT(object):
"""Base class for change notification events."""
def __init__(self,fs,path):
super(EVENT, self).__init__()
self.fs = fs
if path is not None:
path = abspath(normpath(path))
......
......@@ -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.path import basename
from fs.path import iteratepath
from fs.errors import ResourceNotFoundError
import re
import fnmatch
......@@ -16,7 +17,7 @@ class HideFS(WrapFS):
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):
self._hide_wildcards = [re.compile(fnmatch.translate(wildcard)) for wildcard in hide_wildcards]
super(HideFS, self).__init__(wrapped_fs)
def _should_hide(self, name):
name = basename(name)
return any(wildcard.match(name) for wildcard in self._hide_wildcards)
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)
return path
def _decode(self, 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):
entries = super(HideFS, self).listdir(path, *args, **kwargs)
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