forked from iamgreaser/iceball
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genmanual.py
123 lines (97 loc) · 2.37 KB
/
genmanual.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
# HTML doc generator by GreaseMonkey, 2013. Public domain.
# Contents of said manual are also public domain, except where otherwise specified.
import os
ICEBALL_W_VER = "Iceball (pre-)0.1"
def mktag(name):
def _f1(*args, **kwargs):
s = "<" + name
for k in kwargs:
v = kwargs[k]
s += " " + k + "=\"" + v + "\""
# TODO: ensure this remains valid HTML
if len(args) == 0:
s += " />"
return s
s += ">"
for v in args:
s += "\n" + v
s += "\n</" + name + ">"
return s
return _f1
m_html = mktag("html")
m_head = mktag("head")
m_title = mktag("title")
m_body = mktag("body")
m_hr = mktag("hr")
m_h1 = mktag("h1")
m_h2 = mktag("h2")
m_h3 = mktag("h3")
m_h4 = mktag("h4")
m_h5 = mktag("h5")
m_h6 = mktag("h6")
mgrp_h = [m_h1, m_h2, m_h3, m_h4, m_h5, m_h6]
m_p = mktag("p")
m_ul = mktag("ul")
m_li = mktag("li")
m_b = mktag("b")
m_i = mktag("i")
m_u = mktag("u")
m_tt = mktag("tt")
m_a = mktag("a")
def mkpage(name):
print "Generating", name
try:
nl = name.split("/")
if len(nl) > 1:
os.makedirs("MANUAL/" + "/".join(nl[:-1]))
else:
os.makedirs("MANUAL")
except OSError:
pass
BODY = None
try:
fp = open("msrc/" + name + ".py", "rb")
exec fp.read().replace("\r\n","\n").replace("\r","")
fp.close()
except IOError:
print "ERROR:", name, "- IOError"
return False
fp = open("MANUAL/" + name + ".html", "wb")
fp.write(BODY.replace("\n","\r\n"))
fp.close()
return True
def gen_list(l, pbase="", level=1):
ul_data = None
list_data = []
for name, page, sl in l:
if sl:
if ul_data != None:
list_data.append(m_ul(*ul_data))
ul_data = None
list_data.append(mgrp_h[level-1](name))
list_data += gen_list(sl, pbase if page == None else pbase + page, level+1)
else:
if ul_data == None:
ul_data = []
pg_pass = page != None and mkpage(pbase + page)
licontent = name if not pg_pass else m_a(name, href = pbase + page + ".html")
ul_data.append(m_li(licontent))
if ul_data != None:
list_data.append(m_ul(*ul_data))
return list_data
def gen_lua_api_docs(l):
list_data = []
for rets, name, args, optargs, isimp, tags in l:
s = name + "("
if rets:
s = ", ".join(rets) + " = " + s
l2 = []
for n in args:
l2.append(n)
for n, v in optargs:
l2.append(n + " = " + v)
s += ", ".join(l2) + "):"
list_data.append(m_h2(m_tt(s)))
list_data += tags
return list_data
mkpage("index")