forked from insertinterestingnamehere/numerical_computing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_util.py
38 lines (30 loc) · 1.06 KB
/
make_util.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
import os
import subprocess
def substlab(template, lab_path, lab_file):
"""Read template and substitute labs"""
with open(template, 'r') as temp:
t = temp.readlines()
i = t.index('%TEMPLATE_INSERT\n')
t.insert(i+1, '\\subimport{{{0}/}}{{{1}}}\n'.format(lab_path.replace('\\', '/'), lab_file))
return t
def getDirs(root):
return set([x for x in os.listdir(root) if os.path.isdir(x)])
def run_latex(template, msg=True):
if msg:
print "Running XeLaTeX on {}".format(template)
ret = subprocess.Popen(['xelatex', '-halt-on-error', template],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
stdout = ret.communicate()[0]
return ret
def run_biber(template, msg=True):
if msg:
print "Running Biber on {}".format(template)
_t = os.path.splitext(template)[0]
ret = subprocess.Popen(['biber', _t])
stdout = ret.communicate()[0]
return ret
run_seq = [run_latex,
run_biber,
run_latex,
run_latex]