Compare commits
No commits in common. "FileObserver" and "master" have entirely different histories.
FileObserv
...
master
45
__init__.py
45
__init__.py
@ -40,8 +40,6 @@ import os
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from watchdog.observers import Observer
|
|
||||||
from watchdog.events import FileSystemEventHandler
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -128,49 +126,6 @@ def filelist(path='.', expression='*', rekursive=True):
|
|||||||
return li
|
return li
|
||||||
|
|
||||||
|
|
||||||
class FileObserver(FileSystemEventHandler):
|
|
||||||
OBSERVE_MODIFIED = 1
|
|
||||||
OBSERVE_CREATED = 2
|
|
||||||
OBSERVE_DELETED = 4
|
|
||||||
OBSERVE_ALL = OBSERVE_MODIFIED | OBSERVE_CREATED | OBSERVE_DELETED
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
#
|
|
||||||
self.__callbacks__ = {}
|
|
||||||
#
|
|
||||||
self.observer = Observer()
|
|
||||||
self.observer.start()
|
|
||||||
|
|
||||||
def observe(self, filepath, when, callback, *args, **kwargs):
|
|
||||||
if filepath not in self.__callbacks__:
|
|
||||||
self.__callbacks__[filepath] = []
|
|
||||||
self.__callbacks__[filepath].append( (when, callback, args, kwargs) )
|
|
||||||
self.observer.schedule(self, path=os.path.dirname(filepath), recursive=True)
|
|
||||||
|
|
||||||
def __callback_logic__(self, etype, event):
|
|
||||||
if event.src_path in self.__callbacks__:
|
|
||||||
for when, cb, args, kwargs in self.__callbacks__[event.src_path]:
|
|
||||||
if when & etype != 0:
|
|
||||||
cb(event, *args, **kwargs)
|
|
||||||
# TODO: LOG
|
|
||||||
|
|
||||||
def on_modified(self, event):
|
|
||||||
self.__callback_logic__(self.OBSERVE_MODIFIED, event)
|
|
||||||
|
|
||||||
def on_created(self, event):
|
|
||||||
self.__callback_logic__(self.OBSERVE_CREATED, event)
|
|
||||||
|
|
||||||
def on_deleted(self, event):
|
|
||||||
self.__callback_logic__(self.OBSERVE_DELETED, event)
|
|
||||||
|
|
||||||
def stop(self):
|
|
||||||
self.observer.stop()
|
|
||||||
|
|
||||||
def join(self):
|
|
||||||
self.observer.join()
|
|
||||||
|
|
||||||
|
|
||||||
def is_writeable(path):
|
def is_writeable(path):
|
||||||
"""
|
"""
|
||||||
Method to get the Information, if a file or folder is writable.
|
Method to get the Information, if a file or folder is writable.
|
||||||
|
@ -1 +0,0 @@
|
|||||||
watchdog
|
|
Loading…
x
Reference in New Issue
Block a user