-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwatcher.py
47 lines (32 loc) · 999 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
42
43
44
45
46
import subprocess
import time
task = None
def start_evince():
global task
focus_window_id = subprocess.Popen('xdotool getactivewindow'.split(),
stdout=subprocess.PIPE).communicate()[0].decode('utf-8').strip()
task = subprocess.Popen('evince build/thesis.pdf', shell=True)
time.sleep(0.1)
bash(f'xdotool windowfocus {focus_window_id}')
bash(f'xdotool windowactivate {focus_window_id}')
def restart_evince():
global task
task.terminate()
start_evince()
def bash(cmd):
subprocess.call(cmd.split(), stdout=subprocess.DEVNULL)
def build():
print("Change detected! Rebuilding...")
bash('bash build.sh skip')
print("Build done!")
restart_evince()
print('Creating initial build...')
bash('bash build.sh')
print('Starting PDF viewer...')
start_evince()
try:
while True:
bash('inotifywait -qr --event modify .')
build()
except KeyboardInterrupt:
print('Stopping watcher...')