mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-05 23:51:21 +00:00
27 lines
687 B
Python
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()
|