baseimage-tutorial-framework/lib/tfw/components/directory_monitor.py

27 lines
687 B
Python

from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from tfw.message_sender import MessageSender
class MessagingEventHandler(FileSystemEventHandler):
def __init__(self):
super().__init__()
self.message_sender = MessageSender()
def on_modified(self, event):
self.message_sender.send('Watchdog', 'CECA')
class DirectoryMonitor:
def __init__(self, directory):
self.observer = Observer()
self.observer.schedule(MessagingEventHandler(), directory, recursive=True)
def watch(self):
self.observer.start()
def stop(self):
self.observer.stop()
self.observer.join()