2011-09-10 11:13:51 +02:00
|
|
|
#! /usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
# Thomas Nagy, 2006-2010 (ita)
|
|
|
|
|
|
|
|
"""
|
|
|
|
call 'waf --targets=waf.pdf' or use 'waf list' to see the targets available
|
|
|
|
"""
|
|
|
|
|
|
|
|
VERSION='0.0.1'
|
|
|
|
APPNAME='wafdocs'
|
|
|
|
|
|
|
|
import os, re, shutil
|
2014-11-16 21:35:01 +01:00
|
|
|
from waflib import TaskGen
|
2011-09-10 11:13:51 +02:00
|
|
|
|
|
|
|
top = '.'
|
|
|
|
out = 'build'
|
|
|
|
|
|
|
|
re_xi = re.compile('''^(include|image)::([^.]*.(txt|\\{PIC\\}))\[''', re.M)
|
|
|
|
def ascii_doc_scan(self):
|
|
|
|
p = self.inputs[0].parent
|
|
|
|
node_lst = [self.inputs[0]]
|
|
|
|
seen = []
|
|
|
|
depnodes = []
|
|
|
|
while node_lst:
|
|
|
|
nd = node_lst.pop(0)
|
|
|
|
if nd in seen: continue
|
|
|
|
seen.append(nd)
|
|
|
|
|
|
|
|
code = nd.read()
|
|
|
|
for m in re_xi.finditer(code):
|
|
|
|
name = m.group(2)
|
|
|
|
if m.group(3) == '{PIC}':
|
|
|
|
|
|
|
|
ext = '.eps'
|
|
|
|
if self.generator.rule.rfind('A2X') > 0:
|
|
|
|
ext = '.png'
|
|
|
|
|
|
|
|
k = p.find_resource(name.replace('{PIC}', ext))
|
|
|
|
if k:
|
|
|
|
depnodes.append(k)
|
|
|
|
else:
|
|
|
|
k = p.find_resource(name)
|
|
|
|
if k:
|
|
|
|
depnodes.append(k)
|
|
|
|
node_lst.append(k)
|
|
|
|
return [depnodes, ()]
|
|
|
|
|
|
|
|
import re
|
|
|
|
def scansize(self):
|
2014-11-16 13:23:58 +01:00
|
|
|
|
|
|
|
base, _, ext = self.inputs[0].name.partition('.')
|
|
|
|
|
|
|
|
name = 'image::%s\\{PIC\\}\\[.*,(width|height)=(\\d+)' % base
|
2011-09-10 11:13:51 +02:00
|
|
|
re_src = re.compile(name)
|
|
|
|
lst = self.inputs[0].parent.get_src().ant_glob('*.txt')
|
|
|
|
for x in lst:
|
|
|
|
m = re_src.search(x.read())
|
|
|
|
if m:
|
|
|
|
val = str(int(1.6 * int(m.group(2))))
|
|
|
|
if m.group(1) == 'width':
|
|
|
|
w = val
|
|
|
|
h = "800"
|
|
|
|
else:
|
|
|
|
w = "800"
|
|
|
|
h = val
|
|
|
|
|
|
|
|
if ext == 'eps':
|
|
|
|
code = '-geometry %sx%s' % (w, h)
|
|
|
|
elif ext == 'dia':
|
|
|
|
if m.group(1) == 'width':
|
|
|
|
h = ''
|
|
|
|
else:
|
|
|
|
w = ''
|
|
|
|
code = '--size %sx%s' % (w, h)
|
2014-11-16 13:23:58 +01:00
|
|
|
elif ext == 'semd':
|
|
|
|
if m.group(1) == 'width':
|
|
|
|
code = '--width=%s' % w
|
|
|
|
else:
|
|
|
|
code = '--height=%s' % h
|
2011-09-10 11:13:51 +02:00
|
|
|
else:
|
|
|
|
code = '-Gsize="%s,%s"' % (w, h)
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
return ([], '')
|
|
|
|
|
|
|
|
return ([], code)
|
|
|
|
|
|
|
|
def options(opt):
|
|
|
|
opt.add_option('--exe', action='store_true', default=False, help='Execute the program after it is compiled')
|
|
|
|
|
|
|
|
def configure(conf):
|
|
|
|
conf.find_program('a2x', var='A2X')
|
|
|
|
conf.find_program('asciidoc', var='ADOC')
|
2015-04-26 18:03:45 +02:00
|
|
|
#conf.find_program('dia', var='DIA')
|
2011-09-10 11:13:51 +02:00
|
|
|
conf.find_program('convert', var='CONVERT')
|
|
|
|
conf.find_program('source-highlight', var='SOURCE_HIGHLIGHT')
|
2012-04-02 01:57:38 +02:00
|
|
|
conf.find_program('dot')
|
2015-04-26 20:40:28 +02:00
|
|
|
conf.find_program('dblatex')
|
2015-04-26 20:36:48 +02:00
|
|
|
try:
|
|
|
|
conf.find_program('semantik-d')
|
|
|
|
except conf.errors.ConfigurationError:
|
|
|
|
conf.env.SEMANTIK_D = conf.path.find_node('semd_wrapper.py').abspath()
|
2011-09-10 11:13:51 +02:00
|
|
|
|
|
|
|
def build(bld):
|
|
|
|
|
2012-09-05 01:19:53 +02:00
|
|
|
#bld(features='subst', is_copy=True, source='asciidoc-dblatex.sty asciidoc-dblatex.xsl', target='asciidoc-dblatex.sty asciidoc-dblatex.xsl')
|
2011-09-10 11:13:51 +02:00
|
|
|
|
|
|
|
for x in bld.path.ant_glob('*.eps'):
|
2012-04-02 01:57:38 +02:00
|
|
|
bld(features='subst', source=x.name, target=x.name, is_copy=True)
|
2011-09-10 11:13:51 +02:00
|
|
|
bld(rule='${CONVERT} ${bld.raw_deps[tsk.uid()]} -density 600 ${SRC} ${TGT}', source=x, target=x.change_ext('.png'), scan=scansize)
|
|
|
|
|
|
|
|
for x in bld.path.ant_glob('*.dot'):
|
2012-04-02 01:57:38 +02:00
|
|
|
tg = bld(rule='${DOT} -Teps -o${TGT} ${SRC}', source=x, target=x.change_ext('.eps'))
|
|
|
|
tg = bld(rule='${DOT} -Tpng -o${TGT} ${SRC}', source=x, target=x.change_ext('.png'), scan=scansize)
|
2011-09-10 11:13:51 +02:00
|
|
|
#tg = bld(rule='${CONVERT} ${bld.raw_deps[tsk.uid()]} ${SRC} ${TGT}', source=x.change_ext('.eps'), target=x.change_ext('.png'), scan=scansize)
|
|
|
|
|
2014-11-16 13:23:58 +01:00
|
|
|
for x in bld.path.ant_glob('*.semd'):
|
|
|
|
bld(rule='${SEMANTIK_D} ${SRC[0].abspath()} -o ${TGT[0].abspath()}', source=x, target=x.change_ext('.svg'))
|
|
|
|
bld(rule='${SEMANTIK_D} ${SRC[0].abspath()} -o ${TGT[0].abspath()}', source=x, target=x.change_ext('.pdf'))
|
2014-11-16 21:35:01 +01:00
|
|
|
bld(rule='${SEMANTIK_D} ${SIZEPARAMS} ${SRC[0].abspath()} -o ${TGT[0].abspath()}', source=x, target=x.change_ext('.png'), features="sizer")
|
2011-09-10 11:13:51 +02:00
|
|
|
|
|
|
|
for x in bld.path.ant_glob('pics/*.png'):
|
2012-04-02 01:57:38 +02:00
|
|
|
bld(features='subst', source=x, target=x.name, is_copy=True)
|
2011-09-10 11:13:51 +02:00
|
|
|
|
2012-04-02 01:57:38 +02:00
|
|
|
for x in bld.path.ant_glob('callouts/*.png'):
|
|
|
|
bld(features='subst', source=x.name, target=x.name, is_copy=True, path=x.parent)
|
2011-09-10 11:13:51 +02:00
|
|
|
|
2012-04-02 01:57:38 +02:00
|
|
|
#bld(rule='mkdir -p ${SRC[0].parent.get_bld().abspath()} && cp ${SRC} ${SRC[0].parent.get_bld().abspath()}',
|
|
|
|
# source=bld.path.ant_glob('callouts/*.png'))
|
|
|
|
|
|
|
|
for x in 'shishell.lang symbols.lang default.style lang.map waf.css'.split():
|
|
|
|
bld(features='subst', source=x, target=x, is_copy=True)
|
2011-09-10 11:13:51 +02:00
|
|
|
|
2015-04-26 17:09:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
with open('../../waflib/Context.py', 'r') as f:
|
|
|
|
version = re.compile('WAFVERSION=[\'"]([^\'"]+)', re.M).search(f.read()).group(1)
|
|
|
|
def sfun(tsk, text):
|
|
|
|
return text.replace('{version}', version)
|
|
|
|
for x in bld.path.ant_glob('*.txt'):
|
|
|
|
bld(features='subst', source=x, target=x.change_ext('_.txt'), subst_fun=sfun)
|
|
|
|
|
2011-09-10 11:13:51 +02:00
|
|
|
bld.add_group() # separator, the documents may require any of the pictures from above
|
|
|
|
|
|
|
|
bld(rule='${ADOC} -a icons=true -a stylesheet=${SRC[1].abspath()} -a iconsdir=. -a toc -d book -o ${TGT} ${SRC[0].abspath()}',
|
2015-04-26 17:09:01 +02:00
|
|
|
source='waf_.txt waf.css', target='index.html', scan=ascii_doc_scan)
|
2011-09-10 11:13:51 +02:00
|
|
|
|
2015-04-26 17:09:01 +02:00
|
|
|
bld(rule='${A2X} -L -a toc --icons-dir=. --icons -d book -f pdf --dblatex-opts "-s ${SRC[1].abspath()} -p ${SRC[2].abspath()} -o ${TGT}" ${SRC[0].bldpath()}',
|
2015-04-06 14:46:55 +02:00
|
|
|
shell=True,
|
2015-04-26 17:09:01 +02:00
|
|
|
source='waf_.txt asciidoc-dblatex.sty asciidoc-dblatex.xsl', target='waf.pdf', scan=ascii_doc_scan)
|
2011-09-10 11:13:51 +02:00
|
|
|
|
2015-04-06 14:46:55 +02:00
|
|
|
#bld(rule='ln -sf single.html index.html', shell=True)
|
2011-09-10 11:13:51 +02:00
|
|
|
|
|
|
|
if bld.options.exe:
|
|
|
|
def exe(ctx):
|
2015-04-06 14:46:55 +02:00
|
|
|
bld.exec_command('firefox build/index.html')
|
2011-09-10 11:13:51 +02:00
|
|
|
bld.add_post_fun(exe)
|
|
|
|
|
2014-11-16 21:35:01 +01:00
|
|
|
@TaskGen.feature('sizer')
|
|
|
|
@TaskGen.after_method('process_rule')
|
|
|
|
def process_sizes(self):
|
|
|
|
|
|
|
|
try:
|
|
|
|
tbl = self.bld.size_table
|
|
|
|
except AttributeError:
|
|
|
|
tbl = self.bld.size_table = make_size_table(self)
|
|
|
|
|
|
|
|
base, _, ext = self.tasks[0].outputs[0].name.partition('.')
|
|
|
|
if ext == 'png' and base in tbl:
|
|
|
|
self.env.SIZEPARAMS = "--%s=%s" % tbl[base]
|
|
|
|
|
|
|
|
@TaskGen.taskgen_method
|
|
|
|
def make_size_table(self):
|
|
|
|
name = 'image::(.*?)\\{PIC\\}\\[.*,(width|height)=(\\d+)'
|
|
|
|
re_src = re.compile(name)
|
|
|
|
|
|
|
|
tbl = {}
|
|
|
|
|
|
|
|
lst = self.path.ant_glob('*.txt')
|
|
|
|
for x in lst:
|
|
|
|
for m in re.finditer(re_src, x.read()):
|
|
|
|
tbl[m.group(1)] = (m.group(2), m.group(3))
|
|
|
|
|
|
|
|
return tbl
|
|
|
|
|
2011-09-10 11:13:51 +02:00
|
|
|
"""
|
2012-09-05 01:19:53 +02:00
|
|
|
For vim highlighting:
|
2011-09-10 11:13:51 +02:00
|
|
|
cp vim/syntax/asciidoc.vim /usr/share/vim/site/syntax/
|
|
|
|
cp vim/ftdetect/asciidoc_filetype.vim /usr/share/vim/site/ftdetect/
|
|
|
|
|
|
|
|
When adding an eps from a svg file, convert it with inscape first
|
|
|
|
convert (imagemagick) does not process svg files too well
|
|
|
|
|
|
|
|
colors:
|
|
|
|
yellow fffea6
|
|
|
|
green aef9a5
|
|
|
|
blue d2d5ff
|
|
|
|
"""
|
|
|
|
|