diff --git a/lib/tfw/components/source_code_event_handler.py b/lib/tfw/components/source_code_event_handler.py index 4823333..46264cc 100644 --- a/lib/tfw/components/source_code_event_handler.py +++ b/lib/tfw/components/source_code_event_handler.py @@ -1,5 +1,7 @@ from os.path import isfile, join, relpath, exists, isdir from glob import glob +from fnmatch import fnmatchcase +from collections import Iterable from tfw.event_handler_base import TriggerlessEventHandler from tfw.components.directory_monitor import DirectoryMonitor @@ -9,8 +11,8 @@ log = logging.getLogger(__name__) class FileManager: - def __init__(self, working_directory, selected_file=None, exclude=()): - self._exclude, self.exclude = None, *exclude + def __init__(self, working_directory, selected_file=None, exclude=None): + self._exclude, self.exclude = None, exclude self._workdir, self.workdir = None, working_directory self._filename, self.filename = None, selected_file or self.files[0] @@ -19,7 +21,9 @@ class FileManager: return self._exclude @exclude.setter - def exclude(self, *exclude): + def exclude(self, exclude): + if exclude is None: return + if not isinstance(exclude, Iterable): raise TypeError('Exclude must be Iterable!') self._exclude = exclude @property @@ -46,7 +50,7 @@ class FileManager: def files(self): return [self._relpath(file) for file in glob(join(self._workdir, '**/*'), recursive=True) if isfile(file) and - not any(word in file for word in self.exclude)] + not any(fnmatchcase(file, blacklisted) for blacklisted in self.exclude)] @property def file_contents(self): diff --git a/src/demo/event_handler_main.py b/src/demo/event_handler_main.py index 730cf18..430b93b 100644 --- a/src/demo/event_handler_main.py +++ b/src/demo/event_handler_main.py @@ -40,7 +40,7 @@ toggle_next.button_state = False if __name__ == '__main__': - ide = SourceCodeEventHandler(key='webide', directory=tfwenv.WEBIDE_WD, exclude=['__pycache__']) + ide = SourceCodeEventHandler(key='webide', directory=tfwenv.WEBIDE_WD, exclude=['*.pyc']) terminado = TerminadoEventHandler(key='shell') terminado.historymonitor.subscribe_callback(cenator) terminado.historymonitor.subscribe_callback(selectdir)