# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright 2015-2018 by Exopy Authors, see AUTHORS for more details.
#
# Distributed under the terms of the BSD license.
#
# The full license is in the file LICENCE, distributed with this software.
# -----------------------------------------------------------------------------
"""Collections of useful watchdog file system observers.
"""
from watchdog.events import (FileSystemEventHandler, FileCreatedEvent,
FileDeletedEvent, FileMovedEvent)
[docs]class SystematicFileUpdater(FileSystemEventHandler):
"""Simple watchdog handler calling always the same function no matter the
event
"""
def __init__(self, handler):
self.handler = handler
[docs] def on_created(self, event):
"""Called on creation of a file.
"""
super(SystematicFileUpdater, self).on_created(event)
if isinstance(event, FileCreatedEvent):
self.handler()
[docs] def on_deleted(self, event):
"""Called on deletion of a file.
"""
super(SystematicFileUpdater, self).on_deleted(event)
if isinstance(event, FileDeletedEvent):
self.handler()
[docs] def on_moved(self, event):
"""Called on displacement of a file.
"""
super(SystematicFileUpdater, self).on_moved(event)
if isinstance(event, FileMovedEvent):
self.handler()