mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-12 19:57:17 +00:00
36 lines
993 B
Python
36 lines
993 B
Python
from watchdog.observers import Observer
|
|
from watchdog.events import FileSystemEventHandler
|
|
|
|
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
|
|
from tfw.util import RateLimiter
|
|
|
|
from tfw.config.logs import logging
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
class WebideReloadEventHandler(FileSystemEventHandler):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.uplink = ServerUplinkConnector()
|
|
|
|
@RateLimiter(rate_per_second=5)
|
|
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()
|