-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbuild.py
55 lines (42 loc) · 1.87 KB
/
build.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
"""
Builds PDF files for practice exams and sample problems (both blank and
solution). Uses Lyx 2.3 with LuaTex internally. Results will be placed in
build subdirectory. Probably only works on Windows.
"""
import os
import shutil
__author__ = "Ruben Acuna"
__copyright__ = "Copyright 2019, Ruben Acuna"
build_folder = os.sep + "build"
cwd = os.getcwd()
tex_toolchain = "pdf5" #LuaTex
lyx_bin = "Lyx"
# preparation
if not os.path.isdir(build_folder):
os.mkdir(build_folder)
#TODO: clean up old build folder if exists
# build
lyx_filenames = [x for x in os.listdir(".") if x.endswith(".lyx")]
for lyx_filename in lyx_filenames:
blank_out_filename = cwd + build_folder + os.sep + lyx_filename[:-3] + "pdf"
soln_out_filename = cwd + build_folder + os.sep + lyx_filename[:-4] + "_soln.pdf"
# reference: https://wiki.lyx.org/FAQ/ImportExport
blank_para = "-x \"command-sequence branch-activate blank; branch-deactivate soln\"" + " --export-to " + tex_toolchain + " " + blank_out_filename + " " + lyx_filename
soln_para = ("-x \"command-sequence branch-activate soln; branch-deactivate blank\" --export-to %s %s %s" % (tex_toolchain, soln_out_filename, lyx_filename))
if "_opt_" in lyx_filename:
continue
cmd_blank = lyx_bin + " " + blank_para
os.system(cmd_blank)
if "exam" not in lyx_filename:
cmd_soln = lyx_bin + " " + soln_para
os.system(cmd_soln)
#copy code samples folder
shutil.copytree(cwd + os.sep + "code_samples", cwd + build_folder + os.sep + "code_samples")
#copy handouts folder
shutil.copytree(cwd + os.sep + "handouts", cwd + build_folder + os.sep + "handouts")
#copy .md and .txt files from root
root_files = os.listdir(".")
for file_name in root_files:
if file_name.endswith(".txt") or file_name.endswith(".md"):
shutil.copy(file_name, os.path.join(cwd + build_folder, file_name))