-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwatchdog_python.py
executable file
·55 lines (44 loc) · 1.38 KB
/
watchdog_python.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
import os
import sys
import time
from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler
def when_file_changed(filename):
cls()
filename = os.path.abspath(filename)
print(filename)
package = ""
basename = os.path.basename(filename)
if not basename.startswith("test_"):
package = basename.replace(".py", "")
filename = filename.replace(basename, "tests/unit/test_" + basename)
else:
package = basename.replace(".py", "")
package = package.replace("test_", "")
cmd = "nosetests --with-coverage --cover-erase " \
"--cover-package={package} -v {filename}".format(**locals())
os.system(cmd)
def cls():
os.system('cls' if os.name == 'nt' else 'clear')
class ModifiedHandler(PatternMatchingEventHandler):
patterns = ["*.py"]
def on_created(self, event):
when_file_changed(event.src_path)
def on_any_event(self, event):
pass
def on_modified(self, event):
pass
if __name__ == '__main__':
args = sys.argv[1:]
event_handler = ModifiedHandler()
observer = Observer()
observer.schedule(event_handler,
path=args[1] if args else '.', recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()