-
Notifications
You must be signed in to change notification settings - Fork 5
/
watcher.py
41 lines (30 loc) · 899 Bytes
/
watcher.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import time
from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler
class ScriptModifiedHandler(PatternMatchingEventHandler):
patterns = ['*.py']
def __init__(self):
super(ScriptModifiedHandler, self).__init__()
# you can add some init code here
def process(self, event):
print(event.src_path, event.event_type)
def on_modified(self, event):
self.process(event)
def on_moved(self, event):
pass
def on_deleted(self, event):
pass
def on_created(self, event):
pass
if __name__ == '__main__':
observer = Observer()
path = '.'
event_handler = ScriptModifiedHandler()
observer.schedule(event_handler, path, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()