-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwatcher.py
39 lines (30 loc) · 820 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import time
from watchdog.observers import Observer
from handler import FileEventHandler
class FileWatcher:
def __init__(self, src_path, patterns):
self._src_path = src_path
self._handler = FileEventHandler(patterns=patterns)
self._observer = Observer()
def run(self):
self.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
self.stop()
def start(self):
self._schedule()
self._observer.start()
def stop(self):
self._observer.stop()
self._observer.join()
def _schedule(self):
self._observer.schedule(
self._handler,
self._src_path,
recursive=True
)