contentmonster/classes/doghandler.py

29 lines
929 B
Python
Raw Normal View History

2021-11-22 10:14:38 +00:00
from watchdog.events import FileSystemEventHandler
import os.path
2021-11-22 10:14:38 +00:00
class DogHandler(FileSystemEventHandler):
def __init__(self, directory, queue, *args, **kwargs):
print("Initialized")
2021-11-22 10:14:38 +00:00
super().__init__(*args, **kwargs)
self._directory = directory
2021-11-22 10:14:38 +00:00
self._queue = queue
def dispatch(self, event):
if not event.is_directory:
super().dispatch(event)
2021-11-22 10:14:38 +00:00
def on_created(self, event):
self._queue.put((self._directory, os.path.basename(event.src_path)))
2021-11-22 10:14:38 +00:00
def on_modified(self, event):
self._queue.put((self._directory, os.path.basename(event.src_path)))
2021-11-22 10:14:38 +00:00
def on_moved(self, event):
self._queue.put((self._directory, os.path.basename(event.src_path)))
self._queue.put((self._directory, os.path.basename(event.dest_path)))
2021-11-22 10:14:38 +00:00
def on_deleted(self, event):
self._queue.put((self._directory, os.path.basename(event.src_path)))