2018-02-12 15:01:24 +00:00
|
|
|
from watchdog.observers import Observer
|
|
|
|
from watchdog.events import FileSystemEventHandler
|
|
|
|
|
2018-02-12 15:43:30 +00:00
|
|
|
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
|
2018-02-13 14:02:48 +00:00
|
|
|
from tfw.util import RateLimiter
|
2018-02-12 15:43:30 +00:00
|
|
|
|
|
|
|
from tfw.config.logs import logging
|
|
|
|
log = logging.getLogger(__name__)
|
2018-02-12 15:01:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-13 13:55:33 +00:00
|
|
|
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'}})
|
|
|
|
|
|
|
|
|
2018-02-12 15:01:24 +00:00
|
|
|
class DirectoryMonitor:
|
|
|
|
def __init__(self, directory):
|
|
|
|
self.observer = Observer()
|
2018-02-13 13:55:33 +00:00
|
|
|
self.observer.schedule(WebideReloadEventHandler(), directory, recursive=True)
|
2018-02-12 15:01:24 +00:00
|
|
|
|
|
|
|
def watch(self):
|
|
|
|
self.observer.start()
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
self.observer.stop()
|
|
|
|
self.observer.join()
|