-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdirectorymonitor.py
More file actions
27 lines (21 loc) · 830 Bytes
/
Copy pathdirectorymonitor.py
File metadata and controls
27 lines (21 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import watchdog
import watchdog.events
import watchdog.observers
class EventListener(watchdog.events.FileSystemEventHandler):
'''Event listener skeleton, meant to be derived from'''
def on_any_event(self, event):
pass
class DirectoryMonitor:
'''Simple class to monitor changes starting at a given root directory in the filesystem.'''
def __init__(self, rootpath, eventhandler):
self.__rootpath = rootpath
self.__observer = watchdog.observers.Observer()
self.__eventHandler = eventhandler
def run(self):
print "monitoring %s" % self.__rootpath
self.__observer.schedule(self.__eventHandler, self.__rootpath, recursive=True)
self.__observer.start()
def stop(self):
self.__observer.stop()
def join(self):
self.__observer.join()