forked from svn2github/wxPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildAPIHelpBook.py
More file actions
195 lines (149 loc) · 5.53 KB
/
Copy pathBuildAPIHelpBook.py
File metadata and controls
195 lines (149 loc) · 5.53 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
import htmllib, formatter, string, os, pprint, types, sys, glob
api_name = sys.argv[1] #'wxpyapi'
api_path = sys.argv[2] #'./docs/api/'
header_hhx = '''<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML>
<head>
<meta name="GENERATOR" content="BuildAPIHelpBook">
</HEAD><BODY>
<OBJECT type="text/site properties">
<param name="ImageType" value="Folder">
</OBJECT>
'''
entry_hhx = '''<LI> <OBJECT type="text/sitemap">
<param name="Local" value="%s">
<param name="Name" value="%s">
</OBJECT>
'''
file_hhp = '''[OPTIONS]
Compatibility=1.1
Full-text search=Yes
Contents file=%(n)s.hhc
Compiled file=%(n)s.chm
Default Window=wxHelp
Default topic=index.html
Index file=%(n)s.hhk
Title=wxPython API Documentation
[WINDOWS]
wxHelp=,"%(n)s.hhc","%(n)s.hhk","index.html",,,,,,0x2420,,0x380e,,,,,0,,,
[FILES]
'''
def read_segment(fn, start, end):
data = open(fn).read()
begin = data.find(start)+len(start)
return data[begin:data.find(end, begin)]
#-------------------------------------------------------------------------------
def build_project():
hhp = file_hhp % {'n' : api_name}
def doglob(mask):
st = ''
for name in glob.glob(os.path.join(api_path, mask)):
name = os.path.split(name)[-1]
st += name + '\n'
return st
hhp += doglob("*.html")
hhp += doglob("*.css")
open(os.path.join(api_path, api_name+'.hhp'), 'w').write(hhp)
#-------------------------------------------------------------------------------
def build_contents():
def traverse(l, r):
for i in l:
if type(i) is types.ListType:
r.append('<UL>'+os.linesep)
traverse(i, r)
r.append('</UL>'+os.linesep)
elif type(i) is types.TupleType:
r.append(entry_hhx%i)
else:
raise Exception, 'Unhandled type: %s'%type(i)
data = read_segment(os.path.join(api_path, 'trees.html'),
'<!-- =========== START OF CLASS HIERARCHY =========== -->',
'<!-- =========== START OF NAVBAR =========== -->')
p = APIContentsParser(formatter.NullFormatter(formatter.NullWriter()))
p.feed(data)
class_hierarchy = []
traverse(p.current, class_hierarchy)
data = read_segment(os.path.join(api_path, 'wx-module.html'),
'<!-- =========== START OF SUBMODULES =========== -->',
'<!-- =========== START OF CLASSES =========== -->')
p = APIContentsParser(formatter.NullFormatter(formatter.NullWriter()))
p.feed(data)
submodules = []
traverse(p.current, submodules)
hhc = header_hhx+\
'<UL>'+os.linesep+entry_hhx%('wx-module.html', 'Submodules')+\
''.join(submodules)+'</UL>'+os.linesep+\
'<UL>'+os.linesep+entry_hhx%('trees.html', 'Class Hierarchy')+\
''.join(class_hierarchy)+'</UL>'+os.linesep
open(os.path.join(api_path, api_name+'.hhc'), 'w').write(hhc)
class APIContentsParser(htmllib.HTMLParser):
def __init__(self, formatter, verbose=0):
htmllib.HTMLParser.__init__(self, formatter, verbose)
self.contents = []
self.history = []
self.current = self.contents
self.cur_href = None
self.li_a_cnt = 0
def start_li(self, attrs):
self.li_a_cnt = 0
def start_a(self, attrs):
self.li_a_cnt += 1
if self.li_a_cnt == 1:
if attrs[0][0] == 'href':
self.cur_href = attrs[0][1]
def end_a(self):
self.cur_href = None
def start_code(self, attrs):
self.save_bgn()
def end_code(self):
text = string.strip(self.save_end())
if self.cur_href and text:
self.current.append( (self.cur_href, text) )
def start_ul(self, attrs):
self.history.append(self.current)
self.current = []
def end_ul(self):
c = self.history.pop()
c.append(self.current)
self.current = c
#-------------------------------------------------------------------------------
def build_keywords():
data = read_segment(os.path.join(api_path, 'indices.html'),
'<!-- =========== START OF IDENTIFIER INDEX =========== -->',
'<!-- =========== START OF NAVBAR =========== -->')
p = APIIndicesParser(formatter.NullFormatter(formatter.NullWriter()))
p.feed(data)
hhk = header_hhx+ '<UL>'+os.linesep+\
''.join([entry_hhx%(u, k) for u, k in p.indices])+os.linesep+'</UL>'
open(os.path.join(api_path, api_name+'.hhk'), 'w').write(hhk)
class APIIndicesParser(htmllib.HTMLParser):
def __init__(self, formatter, verbose=0):
htmllib.HTMLParser.__init__(self, formatter, verbose)
self.indices = []
self.cur_href = None
self.tr_a_cnt = 0
def start_tr(self, attrs):
self.tr_a_cnt = 0
def end_tr(self):
self.tr_a_cnt = 0
def start_a(self, attrs):
self.tr_a_cnt += 1
if self.tr_a_cnt == 1:
if attrs[0][0] == 'href':
self.cur_href = attrs[0][1]
def end_a(self):
self.cur_href = None
def start_code(self, attrs):
self.save_bgn()
def end_code(self):
text = string.strip(self.save_end())
if self.cur_href and text:
self.indices.append( (self.cur_href, text) )
#-------------------------------------------------------------------------------
if __name__ == '__main__':
print 'Building project...'
build_project()
print 'Building contents...'
build_contents()
print 'Building keywords...'
build_keywords()