baseimage-tutorial-framework/lib/tfw/components/directory_monitor.py
2018-02-12 17:01:23 +01:00

33 lines
923 B
Python

from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
from tfw.config.logs import logging
log = logging.getLogger(__name__)
class WebideReloadEventHandler(FileSystemEventHandler):
def __init__(self):
super().__init__()
self.uplink = ServerUplinkConnector()
def on_modified(self, event):
log.debug(event)
anchor = 'anchor_webide'
self.uplink.send(anchor, {'anchor': anchor,
'data': {'command': 'reload'}})
class DirectoryMonitor:
def __init__(self, directory):
self.observer = Observer()
self.observer.schedule(WebideReloadEventHandler(), directory, recursive=True)
def watch(self):
self.observer.start()
def stop(self):
self.observer.stop()
self.observer.join()