mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 21:11:32 +00:00
Refactor SourceCodeEventHandler blacklisting to use unix pattern matching
This commit is contained in:
parent
1b87863997
commit
aa54e40f14
@ -1,5 +1,7 @@
|
|||||||
from os.path import isfile, join, relpath, exists, isdir
|
from os.path import isfile, join, relpath, exists, isdir
|
||||||
from glob import glob
|
from glob import glob
|
||||||
|
from fnmatch import fnmatchcase
|
||||||
|
from collections import Iterable
|
||||||
|
|
||||||
from tfw.event_handler_base import TriggerlessEventHandler
|
from tfw.event_handler_base import TriggerlessEventHandler
|
||||||
from tfw.components.directory_monitor import DirectoryMonitor
|
from tfw.components.directory_monitor import DirectoryMonitor
|
||||||
@ -9,8 +11,8 @@ log = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class FileManager:
|
class FileManager:
|
||||||
def __init__(self, working_directory, selected_file=None, exclude=()):
|
def __init__(self, working_directory, selected_file=None, exclude=None):
|
||||||
self._exclude, self.exclude = None, *exclude
|
self._exclude, self.exclude = None, exclude
|
||||||
self._workdir, self.workdir = None, working_directory
|
self._workdir, self.workdir = None, working_directory
|
||||||
self._filename, self.filename = None, selected_file or self.files[0]
|
self._filename, self.filename = None, selected_file or self.files[0]
|
||||||
|
|
||||||
@ -19,7 +21,9 @@ class FileManager:
|
|||||||
return self._exclude
|
return self._exclude
|
||||||
|
|
||||||
@exclude.setter
|
@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
|
self._exclude = exclude
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -46,7 +50,7 @@ class FileManager:
|
|||||||
def files(self):
|
def files(self):
|
||||||
return [self._relpath(file) for file in glob(join(self._workdir, '**/*'), recursive=True)
|
return [self._relpath(file) for file in glob(join(self._workdir, '**/*'), recursive=True)
|
||||||
if isfile(file) and
|
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
|
@property
|
||||||
def file_contents(self):
|
def file_contents(self):
|
||||||
|
@ -40,7 +40,7 @@ toggle_next.button_state = False
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
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 = TerminadoEventHandler(key='shell')
|
||||||
terminado.historymonitor.subscribe_callback(cenator)
|
terminado.historymonitor.subscribe_callback(cenator)
|
||||||
terminado.historymonitor.subscribe_callback(selectdir)
|
terminado.historymonitor.subscribe_callback(selectdir)
|
||||||
|
Loading…
Reference in New Issue
Block a user