-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgen_docs.py
More file actions
245 lines (225 loc) · 7.14 KB
/
gen_docs.py
File metadata and controls
245 lines (225 loc) · 7.14 KB
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
"""
This is an attempt to generate an api for pywright. Old method of methodically
tracking everything just doesn't cut it!
"""
#import stuff to get started
import os,sys
engine = open("core/libengine.py").read().split("\n")
core = open("core/core.py").read().split("\n")
sys.path.insert(0,"core")
import libengine
import core
import inspect
import re
def write_cat(c):
s = ""
if isinstance(c,libengine.VALUE):
s = c.name
if isinstance(c,libengine.COMBINED):
s = "["+c.name+"]"
if isinstance(c,libengine.KEYWORD):
s = c.name+"=VALUE"
if isinstance(c,libengine.TOKEN):
s = "<i>"+c.name+"</i>"
if isinstance(c,libengine.ETC):
s = "("+c.name+")"
if isinstance(c,libengine.CHOICE):
s = "<"+" OR ".join([write_cat(c) for c in c.options])+">"
s += " "
return s
def expand_cat(cats):
options = []
for c in cats:
if isinstance(c,libengine.CHOICE):
options.extend(expand_cat(c.options))
else:
options.append(c)
return options
def make_doc(txt):
while 1:
m = re.search("<\w*?>",txt)
if not m:
break
ot = txt[m.start():m.end()]
nt = '<a href="#%(x)s">%(x)s</a>'%{"x":ot[1:-1]}
txt = txt.replace(ot,nt)
txt = txt.replace("{{{","<br><pre style='background-color:#eeeeff;padding:5px;border-width:1px;border-style:solid'>")
txt = txt.replace("}}}","</pre>")
txt = re.sub("\n *\n","<br><br>",txt)
s = "<p>"
s+=txt
s += "</p>"
return s
def make_func_block(func):
s = "<div style='background-color:#eeeeee;padding:10px'>"
if not func.__doc__:
return
s += """<a name="%(fname)s"><p>
<b>%(fname)s</b> %(cats)s
</p>"""%{"fname":func.name[0],"cats":"".join([write_cat(c) for c in func.cat])}
if func.cat:
s+="<table><tr><th>Name</th><th>Description</th><th>Default value</th></tr>"
for c in expand_cat(func.cat):
if not hasattr(c,"name"):
continue
s+="<tr><td>"+c.name+"</td><td>"+c.description+"</td>"
if c.default is not None:
s+="<td>"+str(c.default)+"</td></tr>"
#~ else:
#~ s+="<td style='background-color:#bababa'></td>"
s+="</table>"
s+=make_doc(func.__doc__)
s+="</div>"
s+="<br><br>"
return s
commands = {}
funcs = {}
#First, get all commands. This is relatively easy. Relatively...
scr = libengine.Script
for fname in dir(scr):
if not fname.startswith("_"):
continue
if fname.startswith("__"):
continue
if fname == "_gchildren":
continue
func = getattr(scr,fname)
if hasattr(func,"ftype") and func.__doc__:
list = funcs.get(func.ftype,[])
list.append(func)
func.name[0] = fname[1:]
funcs[func.ftype] = list
def desig(line):
code = "{%s}"%line[5:].strip()
d = eval(code)
if d.get('args',None):
d['args'] = [libengine.VALUE(*x) for x in d['args']]
return d
def addmfunc(d):
class x:
pass
fu = x()
fu.name = [d['name']]
fu.type = d['type']
fu.__doc__ = d['desc']
fu.cat = d['args']
list = funcs.get(d['type'],[])
list.append(fu)
funcs[d['type']] = list
for macro in os.listdir("core/macros/"):
d = {}
mf = open("core/macros/"+macro)
for line in mf.read().split("\n"):
if d:
d["name"] = line.split(" ")[1]
addmfunc(d)
d = {}
if line.startswith("#@sig"):
d = desig(line)
textmacros = """sfx play a sound effect
sound set the clicking noise for each text character printed
delay set delay between letters
spd set how fast letters are added
_fullspeed add all characters after that in a single frame
_endfullspeed return to animated printing",
wait set to 'manual' to print letters at a consistent speed, set to 'auto' to alter the delay based on punctuation
center center all text
type set color to green, style to center, and clicking sound to typewritter
next erase textbox instantly
tbon turn on testimony blinking graphic
tboff turn off testimony blinking graphic
e set emotion of speaking character
f white flash on the screen. {f}={f 3}. {f 10} - longer flash. {f 3 ff0000} - flash the screen red (html colorcode)
s shake the screen
p pause
c sets the color"""
for line in textmacros.split("\n"):
if not line.strip(): continue
print line.strip()
command,desc = line.strip().split(" ",1)
d = {"type":"text/commands","args":[],"desc":desc,"name":command}
addmfunc(d)
f = open("docs/index.html","w")
f.write("<html>")
f.write("""<style type='text/css'>
table
{
border-collapse:collapse;
}
table, th, td
{
border: 1px solid black;
font-size: 12px;
}
th
{
background-color:#88ff88;
}</style>""")
f.write("<body style='width:640px;background-color:#cccccc'>")
f.write("<div style=''>")
f.write("<h2>Command Categories</h2>")
for group in funcs:
f.write("<a href=#"+group+">"+group+"</a><br>")
f.write("</div><br><br><br><br><br><hr><h3>Commands</h3><div style=''>")
for group in funcs:
f.write("<a name='"+group+"'>")
f.write("<h2>Category: "+group+"</h2>")
for func in funcs[group]:
f.write(make_func_block(func))
f.write("</div>")
f.write("</body></html>")
def find_variables():
variables = {}
classes = {}
for fn in ["core/core.py","core/libengine.py"]:
cur_class = ""
class_tab_level = 0
cur_func = ""
func_tab_level = 0
f = open(fn)
lines = f.read().split("\n")
f.close()
tab_level = 0
for si,l in enumerate(lines):
if l.strip().startswith("#"):
continue
tab_level = l.rsplit(" ",1)[0].count(" ")
if l.strip().startswith("class "):
cur_class = re.findall("class \w*",l)[0]
print cur_class
class_tab_level = tab_level
else:
if cur_class and tab_level <= class_tab_level:
cur_class = ""
if l.strip().startswith("def "):
cur_func = l.strip().split(" ",1)[1].split("(",1)[0]
func_tab_level = tab_level
else:
if cur_func and tab_level <= func_tab_level:
cur_func = ""
if 'variables.get("' in l or 'variables["' in l:
variable = l.strip()
variable = re.findall('\"(.*?)\"',l)
if not variable:
continue
variable = variable[0]
li = variables.get(variable,[])
li.append((cur_class,cur_func,fn,si))
variables[variable] = li
li = classes.get(cur_class,[])
li.append((variable,cur_func,fn,si))
classes[cur_class] = li
return variables,classes
variables,classes = find_variables()
f = open("docs/variables.txt","w")
for c in classes.items():
f.write("%s:\n"%c[0])
for var in c[1]:
f.write(" %s - %s (%s %s)\n"%var)
f.close()
f = open("docs/variables2.txt","w")
for c in variables.items():
f.write("%s:\n"%c[0])
for var in c[1]:
f.write(" %s - %s (%s %s)\n"%var)
f.close()