-
Notifications
You must be signed in to change notification settings - Fork 296
/
make.py
executable file
·174 lines (145 loc) · 5.05 KB
/
make.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
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
from os import system, path, mkdir
import re
import sys
from tests import tests_model
from serve import render
from build import Build
YC = 'yuicompressor-2.4.7.jar'
EXCLUDES = ['Source/Extras',
'Source/Layouts',
'Source/Options/Options.js',
'Source/Core/Fx.js',
'Source/Graph/Graph.Geom.js',
'Source/Visualizations/ForceDirected3D.js']
NATURALDOCS_VER = "1.4"
NATURALDOCS = "NaturalDocs-%s" % NATURALDOCS_VER
def main():
if 'docs' in sys.argv:
make_docs()
if 'examples' in sys.argv:
make_examples()
if 'examples-fancy' in sys.argv:
make_examples(fancy=True)
if 'build' in sys.argv:
make_build()
if 'build-fancy' in sys.argv:
make_build(fancy=True)
def make_docs():
if not path.exists(NATURALDOCS):
print "Requires NaturalDocs %s." % NATURALDOCS_VER
print "http://www.naturaldocs.org/download.html"
return
natural_docs_dir = path.join(NATURALDOCS, 'img')
if not path.exists(natural_docs_dir):
mkdir(natural_docs_dir)
if not path.exists('Docs'):
mkdir('Docs')
# If we can't use 'docstyle' then fallback to 'Default'
docstyle = 'docstyle'
if not path.exists(NATURALDOCS + '/Styles/' + docstyle + '.css'):
docstyle = 'Default'
system("perl "
+ NATURALDOCS + "/NaturalDocs -r "
+ " -i Source/"
+ " -xi " + " -xi ".join(EXCLUDES)
+ " -o HTML Docs/"
+ " -p " + NATURALDOCS
+ " -img " + NATURALDOCS + "/img"
+ " -s " + docstyle)
def make_examples(fancy=False):
if not path.exists('Examples'):
mkdir('Examples')
#clean examples folders
system("rm -rf Examples/*")
#copy css base files
system('cp -r Tests/css Examples/css')
#iterate over the examples
has_example = lambda x: 'Example' in x and x['Example']
for viz, tests in tests_model.items():
#create example folder
if filter(has_example, tests):
system('mkdir Examples/' + viz)
count = 1
for i, model in enumerate(tests):
if has_example(model):
make_example(viz, model, i, count, fancy)
count += 1
#copy some extra files
if fancy:
system('cp -r Extras/sh Examples/')
system('cp Extras/code.css Examples/css/code.css')
def make_example(viz, ex, i, count, fancy):
name = viz
stri = str(i + 1)
model = ex
title = model['Title']
extras = model['Extras'][:]
example = 'example' + str(count)
strdir = 'Examples/' + viz + '/'
if not path.exists(strdir):
mkdir(strdir)
#insert the example js file
fcommon = open('Tests/js/common.js', 'r')
ftest = open('Tests/' + viz + '/test' + stri + '.js', 'r')
fout = open(strdir + example + '.js', 'w')
fout.write('\n\n'.join([fcommon.read(), ftest.read().replace('/Tests/css',
'../css')]))
fcommon.close()
ftest.close()
fout.close()
#render the html file
includes = {
'left': getattr(render['TestCases'], viz + '/left')(model, viz, 1, 1),
'right': getattr(render['TestCases'], viz + '/test' + stri)(model),
}
fhtml = open(strdir + example + '.html', 'w')
html = render['TestCases'].baseexamples(name, title, extras, example, '',
includes, fancy).__body__
fhtml.write(html)
fhtml.close()
#create syntax highlighted code page
if fancy:
begin = re.compile("[\s]*//[\s]?init ([a-zA-Z0-9]+)[\s]*")
end = re.compile('[\s]*//[\s]?end[\s]*')
res = []
ftest = open('Tests/' + viz + '/test' + stri + '.js', 'r')
for l in ftest:
if begin.match(l):
name, lines = begin.match(l).group(1), []
for blockline in ftest:
if end.match(blockline):
break
lines.append(blockline)
res.append({
'name': name,
'code': ''.join(lines)
})
fcode = open(strdir + example + '.code.html', 'w')
html = render['TestCases'].basecode(name, title, res, example).__body__
fcode.write(html)
fcode.close()
def make_build(fancy=False):
system('rm -rf Jit/*')
print "Building Examples..."
make_examples(fancy)
system('cp -r Examples Jit/')
print "Done. Building Extras..."
system('mkdir Jit/Extras && cp Extras/excanvas.js Jit/Extras/excanvas.js')
print "Done. Building Library..."
lib = Build().build()
license = open('LICENSE', 'r').read()
f = open('Jit/jit.js', 'w')
f.write(license)
f.write(lib)
f.close()
print "Done. Compressing Library..."
f = open('Jit/jit-yc.js', 'w')
f.write(license)
f.close()
system('java -jar Extras/' + YC + ' Jit/jit.js >> Jit/jit-yc.js')
print "Done. Zipping..."
system('rm Jit.zip')
system('zip -r Jit.zip Jit/')
print "Done, I guess."
if __name__ == "__main__":
main()