forked from BNLIF/wire-cell-docs
/
wscript
98 lines (72 loc) · 3.18 KB
/
wscript
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# -*- python -*-
### Guidance on using this wscript
## 1) make a local web area and get a copy of the web site
# cd ~/public_html
# git clone git@github.com:WireCell/wirecell.github.io
## 2) Come back here
# cd /path/to/work
# git clone git@github.com:WireCell/wire-cell-docs
# cd wire-cell-docs/manuals
## 3) Configure to install into local web site
# ./waf configure --prefix=~/public_html/wirecell.github.io
# ./waf -j1 build install
## 4) Check results are good, commit and push
# cd ~/public_html
# git commit -am "..."
# git push
### note, you probably MUST run waf in serial mode (-j1) as multiple
### emacsen may fight over locking the package installation directory.
import os
import shutil
def org2x(what, main="manual"):
# org-publish's cache is apparently broken for arbitrary include depths!
# Sneak in this work-around. Waf handles the dependencies anyways. More
# info at:
# http://lists.gnu.org/archive/html//emacs-orgmode/2015-11/msg00620.html
broken = os.path.expanduser("~/.org-timestamps/wct-%s-%s.cache" % (main, what))
if os.path.exists(broken):
os.unlink(broken)
return """${EMACS} --quick --batch -l ${SRC[1].abspath()} --eval '(org-publish-project "wct-%s-%s")'""" % (main, what)
def epubify(task):
bldnode = task.outputs[0].parent
figsdir = os.path.join(bldnode.abspath(), 'figs')
# gotta do a hack to bring the figs into file system scope
if not os.path.exists(figsdir):
os.makedirs(figsdir)
svgs = [i.abspath() for i in task.inputs[2:] if i.abspath().endswith('.svg')]
for svg in svgs:
shutil.copy(svg, figsdir)
cmd = "pandoc -o %s --toc-depth=2 -N %s %s" % (task.outputs[0].abspath(),
task.inputs[0].abspath(),
task.inputs[1].abspath())
return task.exec_command(cmd)
def configure(cfg):
cfg.find_program('emacs', var='EMACS')
def build(bld):
manual_org = bld.path.ant_glob("manual.org")
index_org = bld.path.ant_glob("index.org")
publish_el = bld.path.ant_glob("publish.el")
rest_org = [p for p in bld.path.ant_glob("*.org") if p not in manual_org+index_org]
styledir = bld.path.find_dir("styles")
figsdir = bld.path.find_dir("figs")
figsrc = figsdir.ant_glob('**/*.svg')
for ext in ["html", "md"]: # also pdf
srcs = manual_org + publish_el + rest_org
bld(source=srcs, target="manual.{ext}".format(ext=ext),
rule=org2x(ext), install_path='${PREFIX}')
# stand-alone index
bld(source=index_org+publish_el, target="index.html",
rule=org2x("html", "index"), install_path='${PREFIX}')
# EPUB
epubsrc = [ bld.path.find_or_declare("manual.md"),
bld.path.find_resource("epub-title.txt")]
epubsrc += figsrc
bld(source=epubsrc, target="manual.epub",
rule=epubify,
install_path='${PREFIX}')
# style directory
bld.install_files('${PREFIX}/styles', styledir.ant_glob('**'),
cwd=styledir, relative_trick=True)
# figs directory
bld.install_files('${PREFIX}/figs', figsrc,
cwd=figsdir, relative_trick=True)