-
Notifications
You must be signed in to change notification settings - Fork 69
/
generate.py
executable file
·81 lines (65 loc) · 2.72 KB
/
generate.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3
import os
import shutil
from jinja2 import Environment, FileSystemLoader
from subprocess import Popen, PIPE
ref_map = {
'business-cards': ['http://www.ctan.org/tex-archive/macros/latex/contrib/bizcard'],
'cheatsheet': ['http://www.stdout.org/~winston/latex/'],
'ieee-1.8': [
'http://www.ctan.org/tex-archive/macros/latex2e/contrib/IEEEtran/',
'https://code.google.com/p/mobilecps/source/browse/#svn%2Ftrunk%2Fprojects%2Fhamilton_turner%2Fpapers'
],
'cv': ['https://github.com/bamos/cv'],
'nips': ['https://nips.cc/Conferences/2015/PaperInformation/StyleFiles'],
'presentation': ['https://github.com/bamos/beamer-snippets'],
'poster': ['http://www.brian-amberg.de/uni/poster/']
}
env = Environment(loader=FileSystemLoader("website-templates"),
block_start_string='~{', block_end_string='}~',
variable_start_string='~{{', variable_end_string='}}~')
shutil.rmtree("dist", ignore_errors=True)
shutil.copytree("static", "dist")
shutil.copytree("latex-templates", "dist/templates")
templates_dir = "dist/templates"
def runCmd(cmdStr):
p = Popen(cmdStr.split(), stdout=PIPE, stderr=PIPE)
out = p.communicate()
ret = p.poll()
if ret:
print("Error: Command returned nonzero: {}.".format(ret))
print("===Stdout:\n{}".format(out[0].decode()))
print("===Stderr:\n{}".format(out[1].decode()))
raise Exception("Command returned nonzero: {}.".format(ret))
templates = []
for d in sorted(os.listdir(templates_dir)):
print("====", d)
pdf = "templates/" + d + "/" + d + ".pdf"
png = "templates/" + d + "/" + d + ".png"
src = "https://github.com/bamos/latex-templates/tree/master/latex-templates/{}".format(
d)
tar = "templates/" + d + ".tar"
runCmd("tar -C dist/templates -cf dist/{} {}".format(tar, d))
full_d = templates_dir + "/" + d
runCmd("make -C {}".format(full_d))
if not os.path.isfile("dist/" + pdf):
for f_name in os.listdir("dist/templates/" + d):
if f_name.endswith(".pdf"):
pdf = "templates/" + d + "/" + f_name
png = "templates/" + d + "/" + f_name[0:-4] + ".png"
break
if not os.path.isfile("dist/" + pdf):
raise Exception("Unable to find pdf.")
runCmd('convert -flatten -density 300 -trim {}[0] -quality 100 -resize 600 {}'.format(
"dist/" + pdf, "dist/" + png
))
ref = None
if d in ref_map:
ref = ref_map[d]
templates.append({
'fname': d, 'pdf': pdf, 'png': png, 'tar': tar, 'src': src, 'ref': ref
})
with open("dist/index.html", "w") as idx_f:
idx_f.write(env.get_template("index.jinja.html").render(
templates=templates
))