forked from scipy-conference/scipy_proceedings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_papers.py
executable file
·67 lines (48 loc) · 1.67 KB
/
build_papers.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
#!/usr/bin/env python
import os
import sys
import shutil
import subprocess
import conf
import options
from build_paper import build_paper
output_dir = conf.output_dir
build_dir = conf.build_dir
bib_dir = conf.bib_dir
pdf_dir = conf.pdf_dir
toc_conf = conf.toc_conf
proc_conf = conf.proc_conf
dirs = conf.dirs
def paper_stats(paper_id, start):
stats = options.cfg2dict(os.path.join(output_dir, paper_id, 'paper_stats.json'))
# Write page number snippet to be included in the LaTeX output
if 'pages' in stats:
pages = stats['pages']
else:
pages = 1
stop = start + pages - 1
print '"%s" from p. %s to %s' % (paper_id, start, stop)
with open(os.path.join(output_dir, paper_id, 'page_numbers.tex'), 'w') as f:
f.write('\setcounter{page}{%s}' % start)
# Build table of contents
stats.update({'page': {'start': start,
'stop': stop}})
stats.update({'paper_id': paper_id})
return stats, stop
if __name__ == "__main__":
start = 0
toc_entries = []
options.mkdir_p(pdf_dir)
for paper_id in dirs:
build_paper(paper_id)
stats, start = paper_stats(paper_id, start + 1)
toc_entries.append(stats)
build_paper(paper_id)
src_pdf = os.path.join(output_dir, paper_id, 'paper.pdf')
dest_pdf = os.path.join(pdf_dir, paper_id+'.pdf')
shutil.copy(src_pdf, dest_pdf)
command_line = 'cd '+pdf_dir+' ; pdfannotextractor '+paper_id+'.pdf'
run = subprocess.Popen(command_line, shell=True, stdout=subprocess.PIPE)
out, err = run.communicate()
toc = {'toc': toc_entries}
options.dict2cfg(toc, toc_conf)