forked from riscvarchive/risc-v-getting-started-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
live.py
48 lines (34 loc) · 1.23 KB
/
live.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
#!/usr/bin/env python
sourcedir = 'source/'
builddir = 'build/'
def livehtml():
from livereload import Server, shell
server = Server()
server.watch(sourcedir, 'make html')
server.serve(root=builddir+'html',open_url=True)
def livepdf():
import inotifyx, sys, os, time, subprocess
sys.path.insert(0,sourcedir)
from conf import basic_filename
subprocess.call(['xdg-open',builddir+'latex/'+basic_filename+'.pdf'])
fd = inotifyx.init()
try:
wd = inotifyx.add_watch(fd, sourcedir, inotifyx.IN_CLOSE_WRITE)
try:
while True:
events = []
events += inotifyx.get_events(fd,0)
time.sleep(1)
events += inotifyx.get_events(fd,0)
names = set()
for event in events:
if event.name and event.name[-3:-1] != 'sw' and event.name[-1] != '!':
names.add(sourcedir + event.name)
if len(names) > 0:
print '%s modified' % ','.join(names)
env = dict(os.environ)
subprocess.call(['make','latexpdf'], env=env)
except KeyboardInterrupt:
pass
finally:
os.close(fd)