2021-11-22 10:14:38 +00:00
|
|
|
from watchdog.events import FileSystemEventHandler
|
|
|
|
|
2021-11-25 09:40:25 +00:00
|
|
|
import os.path
|
|
|
|
|
|
|
|
|
2021-11-22 10:14:38 +00:00
|
|
|
class DogHandler(FileSystemEventHandler):
|
2021-11-25 09:40:25 +00:00
|
|
|
def __init__(self, directory, queue, *args, **kwargs):
|
|
|
|
print("Initialized")
|
2021-11-22 10:14:38 +00:00
|
|
|
super().__init__(*args, **kwargs)
|
2021-11-25 09:40:25 +00:00
|
|
|
self._directory = directory
|
2021-11-22 10:14:38 +00:00
|
|
|
self._queue = queue
|
|
|
|
|
2021-11-25 09:40:25 +00:00
|
|
|
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):
|
2021-11-25 09:40:25 +00:00
|
|
|
self._queue.put((self._directory, os.path.basename(event.src_path)))
|
2021-11-22 10:14:38 +00:00
|
|
|
|
|
|
|
def on_modified(self, event):
|
2021-11-25 09:40:25 +00:00
|
|
|
self._queue.put((self._directory, os.path.basename(event.src_path)))
|
2021-11-22 10:14:38 +00:00
|
|
|
|
|
|
|
def on_moved(self, event):
|
2021-11-25 09:40:25 +00:00
|
|
|
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):
|
2021-11-25 09:40:25 +00:00
|
|
|
self._queue.put((self._directory, os.path.basename(event.src_path)))
|