-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto.py
executable file
·45 lines (34 loc) · 1021 Bytes
/
auto.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
#!/bin/env python3
import sys
import pyinotify
import subprocess
import os
from time import time, sleep
class EventHandler(pyinotify.ProcessEvent):
def process_IN_CREATE(self, event):
make()
def process_IN_MODIFY(self, event):
make()
last_compile = 0
target = sys.argv[1] if len(sys.argv) == 2 else ""
def make():
global last_compile
global target
if time() - last_compile > 1:
if target:
os.system(f"make {target} -j 8")
else:
os.system(f"make -j 8")
print("---------------------------------------------------------------------------------")
last_compile = time()
os.system("make clean")
if target:
os.system(f"make {target} -j 8")
else:
os.system(f"make -j 8")
print("---------------------------------------------------------------------------------")
handler = EventHandler()
watch_manager = pyinotify.WatchManager()
notifier = pyinotify.Notifier(watch_manager, handler)
wdd = watch_manager.add_watch("./src/", pyinotify.IN_CREATE | pyinotify.IN_MODIFY, rec=True)
notifier.loop()