summaryrefslogtreecommitdiffstats
path: root/wscript
blob: 127ec2e1e40f48892a64446a3b27404643aebf46 (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#! /usr/bin/env python
# encoding: utf-8
# hhaim, 2014 (IL) base on WAF book

"""
call 'waf --targets=waf.pdf' or use 'waf list' to see the targets available
"""

VERSION='0.0.1'
APPNAME='wafdocs'

import os, re, shutil
import shlex
import subprocess


top = '.'
out = 'build'

re_xi = re.compile('''^(include|image)::([^.]*.(asciidoc|\\{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):
	name = 'image::%s\\{PIC\\}\\[.*,(width|height)=(\\d+)' % self.inputs[0].name[:-4]
	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

			ext = self.inputs[0].name[-3:]
			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)
			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('asciidoc', path='/usr/local/bin/', var='ASCIIDOC')
	pass;

def convert_to_pdf(task):
    input_file = task.outputs[0].abspath()
    out_dir = task.outputs[0].parent.get_bld().abspath()
    os.system('a2x --no-xmllint -v -f pdf  -d  article %s -D %s ' %(task.inputs[0].abspath(),out_dir ) )
    return (0)

def convert_to_pdf_book(task):
    input_file = task.outputs[0].abspath()
    out_dir = task.outputs[0].parent.get_bld().abspath()
    os.system('a2x --no-xmllint -v -f pdf  -d book %s -D %s ' %(task.inputs[0].abspath(),out_dir ) )
    return (0)


def ensure_dir(f):
    if not os.path.exists(f):
        os.makedirs(f)
	

def my_copy(task):
    input_file=task.outputs[0].abspath()
    out_dir=task.outputs[0].parent.get_bld().abspath()
    ensure_dir(out_dir)
    shutil.copy2(input_file, out_dir+ os.sep+task.outputs[0].name)
    return (0)


def do_visio(bld):
	for x in bld.path.ant_glob('visio\\*.vsd'):
		tg = bld(rule='${VIS} -i ${SRC} -o ${TGT} ', source=x, target=x.change_ext('.png'))

def build_cp_docs (trex_src_dir, dest_dir = "_build", builder = "html"):
    build_doc_cmd = shlex.split("/usr/local/bin/sphinx-build -b {bld} {src} {dst}".format(
        bld= builder, 
        src= ".", 
        dst= dest_dir)
        )
    bld_path = os.path.abspath( os.path.join(trex_src_dir, 'automation', 'trex_control_plane', 'doc') )
    ret_val = subprocess.call(build_doc_cmd, cwd = bld_path)
    if ret_val:
        raise RuntimeError("Build operation of control plain docs failed with return value {ret}".format(ret= ret_val))
    return


def build(bld):
	bld(rule=my_copy, target='symbols.lang')

	for x in bld.path.ant_glob('images\\**\**.png'):
        	bld(rule=my_copy, target=x)
                bld.add_group() 

	for x in bld.path.ant_glob('video\\**\**.mp4'):
        	bld(rule=my_copy, target=x)
                bld.add_group() 


	for x in bld.path.ant_glob('images\\**\**.jpg'):
		bld(rule=my_copy, target=x)
                bld.add_group() 

	bld(rule=my_copy, target='my_chart.js')

	bld.add_group() # separator, the documents may require any of the pictures from above

	bld(rule='${ASCIIDOC}  -b deckjs -o ${TGT} ${SRC[0].abspath()}',
		source='trex_config.asciidoc ', target='trex_config_guide.html', scan=ascii_doc_scan)


	bld(rule='${ASCIIDOC}  -b deckjs -o ${TGT} ${SRC[0].abspath()}',
		source='trex_preso.asciidoc ', target='trex_preso.html', scan=ascii_doc_scan)

	bld(rule='${ASCIIDOC}  -a stylesheet=${SRC[1].abspath()} -a  icons=true -a max-width=55em  -o ${TGT} ${SRC[0].abspath()}',
		source='release_notes.asciidoc waf.css', target='release_notes.html', scan=ascii_doc_scan)
                

	bld(rule='${ASCIIDOC} -a docinfo -a stylesheet=${SRC[1].abspath()} -a  icons=true -a toc2 -a max-width=55em  -d book   -o ${TGT} ${SRC[0].abspath()}',
		source='trex_book.asciidoc waf.css', target='trex_manual.html', scan=ascii_doc_scan)

        bld(rule=convert_to_pdf_book,
		source='trex_book.asciidoc waf.css', target='trex_book.pdf', scan=ascii_doc_scan)
                

	bld(rule=convert_to_pdf_book,
		source='trex_vm_manual.asciidoc waf.css', target='trex_vm_manual.pdf', scan=ascii_doc_scan)

	bld(rule=convert_to_pdf_book,
		source='trex_control_plane_peek.asciidoc waf.css', target='trex_control_plane_peek.pdf', scan=ascii_doc_scan)
	
	bld(rule=convert_to_pdf_book,
		source='trex_control_plane_design_phase1.asciidoc waf.css', target='trex_control_plane_design_phase1.pdf', scan=ascii_doc_scan)

	bld(rule='${ASCIIDOC}   -a stylesheet=${SRC[1].abspath()} -a  icons=true -a toc2 -a max-width=55em  -o ${TGT} ${SRC[0].abspath()}',
		source='trex_vm_manual.asciidoc waf.css', target='trex_vm_manual.html', scan=ascii_doc_scan)

	bld(rule='${ASCIIDOC}   -a stylesheet=${SRC[1].abspath()} -a  icons=true -a toc2 -a max-width=55em  -o ${TGT} ${SRC[0].abspath()}',
		source='trex_control_plane_design_phase1.asciidoc waf.css', target='trex_control_plane_design_phase1.html', scan=ascii_doc_scan)
		
	bld(rule='${ASCIIDOC}   -a stylesheet=${SRC[1].abspath()} -a  icons=true -a toc2 -a max-width=55em  -o ${TGT} ${SRC[0].abspath()}',
		source='trex_control_plane_peek.asciidoc waf.css', target='trex_control_plane_peek.html', scan=ascii_doc_scan)