mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 16:41:32 +00:00
Allow listening to inotify events in additional directories using IdeEH
This commit is contained in:
parent
6489e4452e
commit
0038663bc6
@ -15,10 +15,12 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class DirectoryMonitor(ObserverMixin):
|
class DirectoryMonitor(ObserverMixin):
|
||||||
def __init__(self, directory):
|
def __init__(self, directories):
|
||||||
ObserverMixin.__init__(self)
|
ObserverMixin.__init__(self)
|
||||||
self.eventhandler = IdeReloadWatchdogEventHandler()
|
self.eventhandler = IdeReloadWatchdogEventHandler()
|
||||||
self.observer.schedule(self.eventhandler, directory, recursive=True)
|
for directory in directories:
|
||||||
|
self.observer.schedule(self.eventhandler, directory, recursive=True)
|
||||||
|
|
||||||
self.pause, self.resume = self.eventhandler.pause, self.eventhandler.resume
|
self.pause, self.resume = self.eventhandler.pause, self.eventhandler.resume
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -98,17 +98,24 @@ class IdeEventHandler(EventHandlerBase, MonitorManagerMixin):
|
|||||||
By default all files in the directory specified in __init__ are displayed
|
By default all files in the directory specified in __init__ are displayed
|
||||||
on the fontend. Note that this is a stateful component.
|
on the fontend. Note that this is a stateful component.
|
||||||
|
|
||||||
|
When any file in the selected directory changes they are automatically refreshed
|
||||||
|
on the frontend (this is done by listening to inotify events).
|
||||||
|
|
||||||
This EventHandler accepts messages that have a data["command"] key specifying
|
This EventHandler accepts messages that have a data["command"] key specifying
|
||||||
a command to be executed.
|
a command to be executed.
|
||||||
The API of each command is documented in their respective handlers.
|
The API of each command is documented in their respective handlers.
|
||||||
"""
|
"""
|
||||||
def __init__(self, key, directory, allowed_directories, selected_file=None, exclude=None):
|
def __init__(self, key, directory, allowed_directories, selected_file=None, exclude=None,
|
||||||
|
additional_watched_directories=None):
|
||||||
"""
|
"""
|
||||||
:param key: the key this instance should listen to
|
:param key: the key this instance should listen to
|
||||||
:param directory: working directory which the EventHandler should serve files from
|
:param directory: working directory which the EventHandler should serve files from
|
||||||
:param allowed_directories: list of directories that can be switched to using the selectdir command
|
:param allowed_directories: list of directories that can be switched to using the selectdir command
|
||||||
:param selected_file: file that is selected by default
|
:param selected_file: file that is selected by default
|
||||||
:param exclude: list of filenames that should not appear between files (for *.o, *.pyc, etc.)
|
:param exclude: list of filenames that should not appear between files (for *.o, *.pyc, etc.)
|
||||||
|
:param additional_watched_directories: refresh the selected file when files change in these directories
|
||||||
|
(the working directory is watched by default, this is useful for
|
||||||
|
symlinks and such)
|
||||||
"""
|
"""
|
||||||
super().__init__(key)
|
super().__init__(key)
|
||||||
try:
|
try:
|
||||||
@ -116,7 +123,11 @@ class IdeEventHandler(EventHandlerBase, MonitorManagerMixin):
|
|||||||
selected_file=selected_file, exclude=exclude)
|
selected_file=selected_file, exclude=exclude)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
raise EnvironmentError(f'No file(s) in IdeEventHandler working_directory "{directory}"!')
|
raise EnvironmentError(f'No file(s) in IdeEventHandler working_directory "{directory}"!')
|
||||||
MonitorManagerMixin.__init__(self, DirectoryMonitor, self.filemanager.workdir)
|
|
||||||
|
self.watched_directories = [self.filemanager.workdir]
|
||||||
|
if additional_watched_directories:
|
||||||
|
self.watched_directories.extend(additional_watched_directories)
|
||||||
|
MonitorManagerMixin.__init__(self, DirectoryMonitor, self.watched_directories)
|
||||||
|
|
||||||
self.commands = {'read': self.read,
|
self.commands = {'read': self.read,
|
||||||
'write': self.write,
|
'write': self.write,
|
||||||
|
@ -7,10 +7,10 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class MonitorManagerMixin:
|
class MonitorManagerMixin:
|
||||||
def __init__(self, monitor_type, directory):
|
def __init__(self, monitor_type, directories):
|
||||||
self._monitor_type = monitor_type
|
self._monitor_type = monitor_type
|
||||||
self._monitor = None
|
self._monitor = None
|
||||||
self._monitored_directory = directory
|
self._monitored_directories = directories
|
||||||
self.reload_monitor()
|
self.reload_monitor()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -23,5 +23,5 @@ class MonitorManagerMixin:
|
|||||||
self._monitor.stop()
|
self._monitor.stop()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
LOG.debug('Working directory was removed – ignoring...')
|
LOG.debug('Working directory was removed – ignoring...')
|
||||||
self._monitor = self._monitor_type(self._monitored_directory)
|
self._monitor = self._monitor_type(self._monitored_directories)
|
||||||
self._monitor.watch() # This runs on a separate thread
|
self._monitor.watch() # This runs on a separate thread
|
||||||
|
Loading…
Reference in New Issue
Block a user