This repository has been archived by the owner on Sep 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgendoc.py
372 lines (341 loc) · 13.4 KB
/
gendoc.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# -*- coding: windows-1251 -*-
import sys,os
if len(sys.argv) > 1:
lang = sys.argv[1]
else:
lang = "ru"
if lang == 'ru':
strings = \
{
'undocumented': 'íåäîêóìåíòðîâàí',
'Constants': 'Êîíñòàíòû',
'Start Page': 'Ñòàðòîâàÿ ñòðàíèöà',
}
else:
strings = None
def find_string(s):
if strings:
if strings.has_key(s):
return strings[s]
return s
prefix = "scraft."+lang+".doc/";
docstart = "scraft."+lang+".htm";
f = open("doctmpl.txt")
def MakeTypeHeader(opt,ident) :
s = "<h1>" + ident + "</h1>"
return s
g_types_map = {}
g_cur_type = None
g_cur_meth = None
g_cur_doc = None
g_cur_args = None
g_cur_enum = None
while True :
s = f.readline()
if len(s) <= 0 : break
s = s.strip()
if s.startswith("{{!--") : continue # skip comment
elif s.startswith("#") :
if g_cur_doc != None :
s = s[1:]
if len(g_cur_doc) and len(s):
g_cur_doc[len(g_cur_doc)-1] += s
elif len(s) or ( len(g_cur_doc) and len(g_cur_doc[len(g_cur_doc)-1]) ):
g_cur_doc.append(s)
elif s.startswith("{{") : #section
x = s.rfind("}}")
sec_opt = s[2:x].split(',')
sec_ident = s[x+2:]
#print "<<" + repr(sec_opt) + ">>" + sec_ident + "!!"
type = "#!"
value = None
optno = None
skipped = False
accs = "rw"
for m in sec_opt :
if m.startswith("type(") :
type = m[5:m.rfind(')')]
if m.startswith("value(") :
value = m[6:m.rfind(')')]
if m.startswith("opt(") :
optno = m[4:m.rfind(')')]
if m == 'readonly' or m == 'readwrite' or m == 'writeonly' :
accs = m
if type == "#void" :
type = "None"
elif type == "#integer" :
type = "Integer"
elif type == "#single" :
type = "Float"
elif type == "#object" :
type = "Any"
elif type == "#wstring" :
type = "Unicode"
elif type == "#bool" :
type = "Boolean"
elif type.startswith("#tuple") :
tuple = type.split(':')
type = "( "
for t in range(1,len(tuple)) :
if ( t > 1 ) : type += ", "
type+=tuple[t]
type += " )"
if sec_opt[0].startswith("-") :
skipped = True
sec_opt[0] = sec_opt[0][1:]
if sec_opt[0] == 'type' :
g_cur_doc = []
g_types_map[sec_ident] = {}
g_types_map[sec_ident]['opt'] = sec_opt
g_types_map[sec_ident]['methods'] = {}
g_types_map[sec_ident]['attributes'] = []
g_types_map[sec_ident]['doc'] = g_cur_doc
g_types_map[sec_ident]['skipped'] = skipped
g_cur_type = sec_ident
g_cur_attr = None
g_cur_meth = None
elif sec_opt[0] == 'method' :
g_cur_doc = []
g_cur_args = []
g_types_map[g_cur_type]['methods'][sec_ident] = (type,g_cur_args,g_cur_doc,optno,skipped)
g_cur_meth = sec_ident
g_cur_attr = None
elif sec_opt[0] == 'enum' :
g_cur_doc = []
g_cur_enum = []
g_cur_args = None
g_cur_attr = None
g_cur_meth = None
g_types_map[sec_ident] = { 'constants' : (g_cur_enum,g_cur_doc), 'skipped' : skipped }
elif sec_opt[0] == 'constant' :
opt = (sec_ident,value)
g_cur_enum.append(opt)
elif sec_opt[0] == 'param' :
g_cur_doc = []
inout = 'in'
opt = (sec_ident,type,inout,g_cur_doc)
g_cur_args.append(opt)
elif sec_opt[0] == 'attribute' :
g_cur_doc = []
opt = (sec_ident, accs, type, g_cur_doc)
g_types_map[g_cur_type]['attributes'].append(opt)
def FormatTypeRef(t) :
if g_types_map.has_key(t) :
if g_types_map[t].has_key('constants') :
return "<a class='type' href='scraft.constants.htm#"+t+"' target='right'><i>"+t+"</i></a>"
else :
return "<a class='type' href='scraft."+t+".fr.htm' target='right'><i>"+t+"</i></a>"
else :
return "<i class='type' >"+t+"</i>"
def FormatAttribute(opt) :
accs = "accs-red"
#accst = "ro"
if opt[1] == 'readwrite' :
accs = 'accs-green'
#accst = 'rw'
elif opt[1] == 'readonly' :
accs = 'accs-red'
#accst = 'ro'
elif opt[1] == 'writeonly' :
accs = 'accs-yellow'
#accst = 'wo'
s = "<td>" + FormatTypeRef(opt[2]) + "</td><td><a name='" +opt[0]+ "'>"+ opt[0] + "</a></td><td><i class='"+accs+"'>" + opt[1] + "</td>"
return s
def FormatConstant(opt) :
f = "0x%08X" % int(opt[1])
s = "<td>" + opt[0] + "</td><td align=right>" + f + "</td><td align=right><i>" + opt[1] + "</i></td>"
return s
def FormatMethod(ident,opt) :
rettype = opt[0]
args = opt[1]
doc = opt[2]
optno = opt[3]
a = "( "
if len(args) :
for i in range(len(args)) :
if optno != None and i == int(optno) :
a += "["
if ( i > 0 ) : a += ", "
aname = args[i][0]
if len(aname) == 0 : aname = "unnamed"
a += FormatTypeRef(args[i][1]) + " " + aname + ""
if optno != None :
a += "]"
a += " )"
else :
a += ")"
return FormatTypeRef(rettype) + " <a name='" + ident +"'>"+ ident + "</a>" + a
def GenHeader() :
s = ""
s += "<head>\n"
if lang == 'ru':
s += "<meta charset='windows-1251'>\n"
s += "<style>\n"
s += "table.attr-tbl td { valign: top; border-bottom: dashed #ddd 1px; border-left: dashed #ddd 1px; padding: 5 5 5 5; margin: 0 0 0 0; }\n"
s += "table.enum-tbl td { valign: top; border-bottom: dashed #ddd 1px; border-left: dashed #ddd 1px; padding: 5 5 5 5; margin: 0 0 0 0; }\n"
s += "table.idx-tbl td { valign: center; border-bottom: dashed #ddd 1px; border-left: solid #ddd 1px; }\n";
s += "td.enum-tbl-h { border-bottom: dashed #000 1px; border-left: dashed #000 1px; padding: 5 5 5 5; margin: 0 0 0 0; color: #008080; font-size: 110%; background-color: #eeffee }\n"
s += "td.attr-tbl-h { font-size: 1px; padding: 0 0 0 0; border-bottom: dashed #000 1px; }\n"
#s += "td.attr-tbl-h { font-size: 1px; border-left: solid #000 1px; border-bottom: dashed #000 1px; padding: 5 5 5 5; margin: 0 0 0 0; color: #008080; background-color: #eeffee }\n"
s += ".accs-green { color: #00aa00; }\n"
s += ".accs-red { color: #aa0000; }\n"
s += ".accs-yellow { color: #aaaa00; }\n"
s += "a.idx-tbl { text-decoration: none; color: #000 }\n"
s += "a.idx-tbl:hover { text-decoration: underline; color: #300 }\n"
s += ".type { text-decoration: none; color: #555 }\n"
s += "a.type { text-decoration: none; color: #55a }\n"
s += "a.type:hover { text-decoration: underline; color: #300 }\n"
s += ".doc-txt { color: #553355; font-style: italic; margin-left: 30px; }\n"
s += "</style>\n"
s += "</head>\n"
return s
if not os.path.exists(prefix) :
os.mkdir(prefix)
f = open(prefix+"scraft.constants.htm","w+")
f.write(GenHeader())
f.write( "<table cellspacing=0 cellpadding=3 border=0 class='enum-tbl'>\n" )
for i in sorted(g_types_map) :
if g_types_map[i].has_key('constants') :
f.write( u"<tr><td colspan=3 valign=center class='enum-tbl-h'><a name='"+i+"'><b>"+ i +"</b></a></td></tr>" )
enums = g_types_map[i]['constants'][0]
for j in enums :
f.write( "<tr>" + FormatConstant(j) + "</tr>\n" )
f.write( "</table>\n" )
f.close()
for i in sorted(g_types_map) :
if not g_types_map[i].has_key('constants') :
if g_types_map[i]['skipped'] :
continue
f = open(prefix+"scraft."+i+".htm","w+")
f_ndx = open(prefix+"scraft."+i+".ndx.htm","w+")
f_ndx.write(GenHeader())
f_ndx.write("<table cellspacing=0 cellpadding=0 border=0 class='ndx-tbl'>\n")
f.write(GenHeader())
f.write("<h2>scraft." + i +"</h2>\n")
attr = g_types_map[i]['attributes']
if len(attr) > 0 :
f.write("<table cellspacing=0 cellpadding=3 border=0 class='attr-tbl'>\n")
f.write("<tr><td colspan=3 class='attr-tbl-h'> </td></tr>\n")
for j in sorted(attr) :
if g_types_map.has_key(j[2]) :
if g_types_map[j[2]]['skipped'] :
continue
f.write("<tr>" + FormatAttribute(j) + "</tr>\n")
accs = "accs-red"
if j[1] == 'readwrite' :
accs = '#dfd'
elif j[1] == 'readonly' :
accs = '#fdd'
elif j[1] == 'writeonly' :
accs = '#dff'
f_ndx.write("<tr><td><code><b style='background-color: "+accs+"'>p</b></code> <a class='idx-tbl' href='scraft."+i+".htm#"+j[0]+"' target='left1'>" + j[0] + "</a></td></tr>\n")
f.write( "</table>\n" )
f.write( "<p></p>\n")
meth = g_types_map[i]['methods']
for j in sorted(meth) :
if meth[j][4] :
continue
f.write( "<table cellpadding=0 cellspacing=0><tr><td style='border: solid #eee 1px' >" + FormatMethod(j,meth[j]) + "</td></tr></table>\n" )
if len( meth[j][2] ) :
for l in meth[j][2] :
f.write( "<p class='doc-txt'>"+l+"</p>\n" )
else :
f.write( "<p class='doc-txt'>%s</p>\n" % find_string('undocumented'))
f_ndx.write("<tr><td><code><b style='background-color: #ddd'>m</b></code> <a class='idx-tbl' href='scraft."+i+".htm#"+j+"' target='left1'>" + j + "</a></td></tr>\n")
f.close()
f_fr = open(prefix+"scraft."+i+".fr.htm","w+")
f_fr.write("""
<frameset cols="*, 200" border="1" frameborder="yes" framespacing="0">
<frame src="scraft."""+i+""".htm" name="left1"/>
<frame src="scraft."""+i+""".ndx.htm" name="right1"/>
</frameset>
""")
f_fr.close()
f = open(prefix+"scraft.toc.htm","w+")
f.write(GenHeader())
f.write("<table cellspacing=0 cellpadding=3 border=0 class='idx-tbl' width='100%'>\n")
#f.write(" <b style='font-size: 150%'>SpriteCraft</b> <br />\n")
#f.write(" <b style='font-size: 120%'>2d game engine</b> <br /> <hr width = 100% style='border: 0; border-bottom: dashed #000 1px'> \n")
#f.write(" <a href='scraft.main.htm' target='right'>About SpriteCraft for Python</a> <br />")
f.write("<tr><td><a class='idx-tbl' href='scraft.main.htm' target='right'><b>%s</b></a></td></tr>" % find_string('Start Page'))
#f.write(" <hr width = 100% style='border: 0; border-bottom: dashed #000 1px'> \n")
f.write("<tr><td><a class='idx-tbl' href='scraft.constants.htm' target='right'>%s</a></td></tr>" % find_string('Constants'))
for i in sorted(g_types_map) :
if not g_types_map[i].has_key('constants') :
if g_types_map[i]['skipped'] :
continue
f.write("<tr><td><a class='idx-tbl' href='scraft."+i+".fr.htm' target='right'>"+i+"</a></td></tr>\n")
f.write("</table>")
f.close()
f = open("scraft."+lang+".htm","w+")
f.write("""
<frameset rows="70, *" border="1" frameborder="yes" framespacing="0" >
<frame src='"""+prefix+"""scraft.top.htm' scrolling="no" name="_topframe">
<h1>test</h1>
</frame>
<frameset cols="200, *" border="1" frameborder="yes" framespacing="0" >
<frame src='"""+prefix+"""scraft.toc.htm' />
<frame src='"""+prefix+"""scraft.main.htm' name="right"/>
</frameset>
</frameset>
""")
f.close()
f = open(prefix+"scraft_.hhc","w+t")
f.write("""<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML>
<HEAD>
<meta name="GENERATOR" content="Microsoft® HTML Help Workshop 4.1">
<!-- Sitemap 1.0 -->
</HEAD><BODY>
<OBJECT type="text/site properties">
<param name="ImageType" value="Folder">
</OBJECT>
<UL>\n""");
for i in sorted(g_types_map) :
if not g_types_map[i].has_key('constants') :
if g_types_map[i]['skipped'] :
continue
f.write("\t<LI> <OBJECT type=\"text/sitemap\">\n")
f.write("\t\t<param name=\"Name\" value=\""+i+"\">\n")
f.write("\t\t<param name=\"Local\" value=\"scraft."+i+".htm\">\n\t\t</OBJECT>\n")
f.write("""</UL>
</BODY></HTML>
""")
f.close()
f = open(prefix+"scraft_.hhk","w+t")
f.write("""<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML>
<HEAD>
<meta name="GENERATOR" content="Microsoft® HTML Help Workshop 4.1">
<!-- Sitemap 1.0 -->
</HEAD><BODY>
<UL>""")
for i in sorted(g_types_map) :
if not g_types_map[i].has_key('constants') :
if g_types_map[i]['skipped'] :
continue
meth = g_types_map[i]['methods']
for j in sorted(meth) :
f.write("\t<LI> <OBJECT type=\"text/sitemap\">\n")
f.write("\t\t<param name=\"Name\" value=\""+j+"\">\n")
f.write("\t\t<param name=\"Local\" value=\"scraft."+i+".htm#"+j+"\">\n")
#f.write("\t\t<param name=\"Name\" value=\""+i+"."+j+"\">\n")
#f.write("\t\t<param name=\"Local\" value=\"scraft."+i+".htm#"+j+"\">\n")
f.write("\t</OBJECT>")
f.write("""</UL>
</BODY></HTML>
""")
f.close()
f = open(prefix+"scraft_.hhp","w+t")
f.write("""[OPTIONS]
Compatibility=1.1 or later
Compiled file=scraft.chm
Contents file=scraft_.hhc
Display compile progress=No
Index file=scraft_.hhk
Language=0x419
[INFOTYPES]
""")
f.close()
#f = open("scraft.main.htm","w+")
#f.close()