Mercurial > pygame
annotate makeref.py @ 1849:301bc61643a9 math_module
merged changes from trunk
| author | lorenz |
|---|---|
| date | Mon, 16 Nov 2009 18:31:40 +0000 |
| parents | fdf70a7fb220 |
| children | c777771e11f1 |
| rev | line source |
|---|---|
| 627 | 1 #!/usr/bin/env python |
| 2 | |
| 3 import os, glob | |
| 4 | |
| 5 | |
| 6 def sortkey(x): | |
| 7 return os.path.basename(x).lower() | |
| 8 | |
|
632
1db7cdb9ab5a
Added a backwards fix to allow makeref.py to run on <= python2.4
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
9 def sort_list_by_keyfunc(alist, akey): |
|
1db7cdb9ab5a
Added a backwards fix to allow makeref.py to run on <= python2.4
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
10 """ sort(key=sortkey) is only in python2.4. |
|
1db7cdb9ab5a
Added a backwards fix to allow makeref.py to run on <= python2.4
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
11 this is not inplace like list.sort() |
|
1db7cdb9ab5a
Added a backwards fix to allow makeref.py to run on <= python2.4
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
12 """ |
|
1db7cdb9ab5a
Added a backwards fix to allow makeref.py to run on <= python2.4
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
13 # make a list of tupples with the key as the first. |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1503
diff
changeset
|
14 keys_and_list = list( zip(map(akey, alist), alist) ) |
|
632
1db7cdb9ab5a
Added a backwards fix to allow makeref.py to run on <= python2.4
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
15 keys_and_list.sort() |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1503
diff
changeset
|
16 alist = list( map(lambda x:x[1], keys_and_list) ) |
|
632
1db7cdb9ab5a
Added a backwards fix to allow makeref.py to run on <= python2.4
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
17 return alist |
|
1db7cdb9ab5a
Added a backwards fix to allow makeref.py to run on <= python2.4
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
18 |
|
1259
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
19 def collect_doc_files(): |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
20 # ABSPATH ONLY WORKS FOR docs_as_dict |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
21 # |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
22 # if __name__ == '__main__': Run() |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
23 # must be ran from in trunk dir |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
24 |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
25 # get files and shuffle ordering |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
26 trunk_dir = os.path.abspath(os.path.dirname(__file__)) |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
27 |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
28 src_dir = os.path.join(trunk_dir, 'src') |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
29 lib_dir = os.path.join(trunk_dir, 'lib') |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
30 |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
31 pygame_doc = os.path.join(src_dir, "pygame.doc") |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
32 |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
33 files = ( |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
34 glob.glob(os.path.join(src_dir,'*.doc')) + |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
35 glob.glob(os.path.join(lib_dir,'*.doc')) |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
36 ) |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
37 |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
38 files.remove(pygame_doc) |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
39 |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
40 #XXX: sort(key=) is only available in >= python2.4 |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
41 # files.sort(key=sortkey) |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
42 files = sort_list_by_keyfunc(files, sortkey) |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
43 |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
44 files.insert(0, pygame_doc) |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
45 |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
46 return files |
| 627 | 47 |
| 48 def Run(): | |
| 1609 | 49 |
| 50 from optparse import OptionParser | |
| 51 parser = OptionParser() | |
| 52 parser.add_option("", "--no-code-docs", dest="have_code_docs", | |
| 53 action="store_false", default=True, | |
| 54 help="No python documentation in code.") | |
| 55 (options, args) = parser.parse_args() | |
| 56 | |
|
1259
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
57 files = collect_doc_files() |
|
836
70b95d5b61a4
using os.path.join. Thanks DR0ID
Rene Dudfield <renesd@gmail.com>
parents:
821
diff
changeset
|
58 for file in files: |
|
1259
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
59 # print file |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1503
diff
changeset
|
60 print (os.path.basename(file)) |
|
1259
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
61 |
| 627 | 62 docs = [] |
| 63 pages = [] | |
| 64 for f in files: | |
| 65 name = os.path.splitext(os.path.basename(f))[0] | |
| 66 pages.append(name) | |
| 67 d = name, Doc('', open(f, "U")) | |
| 68 docs.append(d) | |
| 69 | |
|
632
1db7cdb9ab5a
Added a backwards fix to allow makeref.py to run on <= python2.4
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
70 #pages.sort(key=str.lower) |
|
1db7cdb9ab5a
Added a backwards fix to allow makeref.py to run on <= python2.4
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
71 pages = sort_list_by_keyfunc(pages, str.lower) |
|
1db7cdb9ab5a
Added a backwards fix to allow makeref.py to run on <= python2.4
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
72 |
| 627 | 73 pages.insert(0, "index") |
| 74 | |
| 75 index = {} | |
| 76 justDocs = [] | |
| 77 for name, doc in docs: | |
| 78 justDocs.append(doc) | |
| 79 MakeIndex(name, doc, index) | |
| 80 | |
| 81 for name, doc in docs: | |
|
836
70b95d5b61a4
using os.path.join. Thanks DR0ID
Rene Dudfield <renesd@gmail.com>
parents:
821
diff
changeset
|
82 fullname = os.path.join("docs","ref","%s.html") % name |
| 627 | 83 outFile = open(fullname, "w") |
| 84 outFile.write(HTMLHeader % name) | |
| 85 WritePageLinks(outFile, pages) | |
| 86 outFile.write(HTMLMid) | |
| 87 HtmlOut(doc, index, outFile) | |
| 88 outFile.write(HTMLFinish) | |
| 89 outFile.close() | |
| 1849 | 90 |
| 91 for name, doc in docs: | |
| 92 outFile = open(os.path.join("src", "doc", "%s_doc.h") % name, "w") | |
| 93 outFile.write("/* Auto generated file: with makeref.py . Docs go in src/ *.doc . */\n") | |
| 1609 | 94 WriteDocHeader(outFile, doc, options.have_code_docs) |
| 1849 | 95 outFile.write("\n\n/* Docs in a comments... slightly easier to read. */\n\n\n/*") |
|
1503
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
96 WriteDocHeaderComments(outFile, doc) |
| 1849 | 97 outFile.write("\n\n*/\n\n") |
|
1503
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
98 |
| 627 | 99 topDoc = LayoutDocs(justDocs) |
| 100 | |
|
836
70b95d5b61a4
using os.path.join. Thanks DR0ID
Rene Dudfield <renesd@gmail.com>
parents:
821
diff
changeset
|
101 outFile = open(os.path.join("docs","ref","index.html"), "w") |
| 627 | 102 outFile.write(HTMLHeader % "Index") |
| 103 WritePageLinks(outFile, pages) | |
| 104 outFile.write(HTMLMid) | |
| 105 outFile.write("<ul>\n\n") | |
| 106 WriteIndex(outFile, index, topDoc) | |
| 107 outFile.write("\n\n</ul>\n") | |
| 108 outFile.write(HTMLFinish) | |
| 109 outFile.close() | |
| 110 | |
| 111 | |
| 112 def HtmlOut(doc, index, f): | |
| 113 f.write('\n\n<a name="%s">\n' % doc.fullname) | |
| 114 f.write("<big><b>%s</big></b><br><ul>\n" % doc.fullname) | |
| 115 if doc.descr: | |
| 1849 | 116 f.write(" <i>%s</i><br>\n" % doc.descr) |
| 627 | 117 if doc.protos: |
| 118 for p in doc.protos: | |
| 119 f.write(" <tt>%s</tt><br>\n" % p) | |
| 120 if doc.kids: | |
| 121 f.write("<ul><small><table>\n") | |
| 122 for kid in doc.kids: | |
| 123 f.write(" <tr><td>%s</td><td>%s</td></tr>\n" | |
| 124 % (index.get(kid.fullname + "()"), kid.descr or "")) | |
| 125 f.write("</table></small></ul>\n") | |
| 126 if doc.docs: | |
| 127 pre = False | |
| 128 for d in doc.docs: | |
| 129 if d[0] == '*': | |
| 130 f.write("<ul>\n") | |
| 131 for li in d[1:].split('*'): | |
| 132 txt = HtmlPrettyWord(li) | |
| 133 f.write(" <li>%s</li>\n" % txt) | |
| 134 f.write("</ul>\n") | |
| 135 else: | |
| 136 txt, pre = HtmlPrettyLine(d, index, pre) | |
| 137 f.write(txt) | |
| 138 if pre: | |
| 139 f.write("</pre>\n") | |
| 140 else: | |
| 141 f.write(" <br> \n") | |
|
638
131cb70cf3a3
a mod by phillhassey to support his super duper new doc comments website
Rene Dudfield <renesd@gmail.com>
parents:
632
diff
changeset
|
142 |
|
131cb70cf3a3
a mod by phillhassey to support his super duper new doc comments website
Rene Dudfield <renesd@gmail.com>
parents:
632
diff
changeset
|
143 f.write("<!--COMMENTS:"+doc.fullname+"-->") |
| 627 | 144 f.write(" <br> \n") |
| 145 | |
| 146 if doc.kids: | |
| 147 for k in doc.kids: | |
| 148 HtmlOut(k, index, f) | |
| 149 f.write("<br></ul>\n") | |
| 150 | |
| 151 | |
| 152 | |
| 153 def HtmlPrettyWord(word): | |
| 154 if "." in word[:-1] or word.isupper(): | |
| 155 return "<tt>%s</tt>" % word | |
| 156 return word | |
| 157 | |
| 158 | |
| 159 | |
| 160 def HtmlPrettyLine(line, index, pre): | |
| 161 pretty = "" | |
| 162 | |
| 163 if line[0].isspace(): | |
| 164 if not pre: | |
| 165 pretty += "<pre>" | |
| 166 pre = True | |
| 167 elif pre: | |
| 168 pre = False | |
| 169 pretty += "</pre>" | |
| 170 | |
| 171 if not pre: | |
| 172 pretty += "<p>" | |
| 173 for word in line.split(): | |
| 174 if word[-1] in ",.": | |
| 175 finish = word[-1] | |
| 176 word = word[:-1] | |
| 177 else: | |
| 178 finish = "" | |
| 179 link = index.get(word) | |
| 180 if link: | |
| 181 pretty += "<tt>%s</tt>%s " % (link, finish) | |
| 182 elif word.isupper() or "." in word[1:-1]: | |
| 183 pretty += "<tt>%s</tt>%s " % (word, finish) | |
| 184 else: | |
| 185 pretty += "%s%s " % (word, finish) | |
| 186 pretty += "</p>\n" | |
| 187 else: | |
| 188 pretty += line + "\n" | |
| 189 return pretty, pre | |
| 190 | |
| 191 | |
| 192 | |
| 193 def WritePageLinks(outFile, pages): | |
| 194 links = [] | |
| 195 for page in pages[1:]: | |
|
975
ac7e80646aa5
Fixed typo in doc generator, added note for PixelArray
marcus
parents:
836
diff
changeset
|
196 link = '<a href="%s.html">%s</a>' % (page, page.title()) |
| 627 | 197 links.append(link) |
| 198 outFile.write(" || \n".join(links)) | |
|
641
b7d1a9cbcffb
changes from philhassey for adjustments to the design
Rene Dudfield <renesd@gmail.com>
parents:
640
diff
changeset
|
199 #outFile.write("\n</p>\n\n") |
| 627 | 200 |
| 201 | |
| 202 def MakeIndex(name, doc, index): | |
| 203 if doc.fullname: | |
|
642
07e4026ed724
added the short description to the reference index page. thanks for the suggestion Laura Creighton
Rene Dudfield <renesd@gmail.com>
parents:
641
diff
changeset
|
204 link = '<a href="%s.html#%s">%s</a> - <font size=-1>%s</font>' % (name, doc.fullname, doc.fullname, doc.descr) |
| 627 | 205 index[doc.fullname + "()"] = link |
| 206 if doc.kids: | |
| 207 for kid in doc.kids: | |
| 208 MakeIndex(name, kid, index) | |
| 209 | |
| 210 | |
| 211 def LayoutDocs(docs): | |
| 212 levels = {} | |
| 213 for doc in docs: | |
| 214 if doc.fullname: | |
| 215 topName = doc.fullname.split(".")[-1] | |
| 216 levels[topName] = doc | |
| 217 | |
| 218 top = levels["pygame"] | |
| 219 for doc in docs: | |
| 220 if doc is top: | |
| 221 continue | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1503
diff
changeset
|
222 #print (doc) |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1503
diff
changeset
|
223 if doc.fullname: |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1503
diff
changeset
|
224 parentName = doc.fullname.split(".")[-2] |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1503
diff
changeset
|
225 else: |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1503
diff
changeset
|
226 parentName = "" |
| 627 | 227 parent = levels.get(parentName) |
| 228 if parent is not None: | |
| 229 parent.kids.append(doc) | |
| 230 | |
| 231 return top | |
| 232 | |
| 233 | |
| 234 def WriteIndex(outFile, index, doc): | |
| 235 link = index.get(doc.fullname + "()", doc.fullname) | |
| 236 outFile.write("<li>%s</li>\n" % link) | |
| 237 if doc.kids: | |
| 238 outFile.write("<ul>\n") | |
| 239 sortKids = list(doc.kids) | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1503
diff
changeset
|
240 #print(sortKids) |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1503
diff
changeset
|
241 sortKids = sort_list_by_keyfunc(sortKids, lambda x: x.fullname) |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1503
diff
changeset
|
242 #sortKids = sorted( sortKids ) |
| 627 | 243 for kid in sortKids: |
| 244 WriteIndex(outFile, index, kid) | |
| 245 outFile.write("</ul>\n") | |
| 246 | |
| 247 | |
| 248 | |
| 1609 | 249 def WriteDocHeader(f, doc, have_code_docs ): |
| 627 | 250 name = doc.fullname.replace(".", "") |
| 251 name = name.replace("_", "") | |
| 252 name = name.upper() | |
| 253 defineName = "DOC_" + name | |
| 254 text = "" | |
| 1609 | 255 if have_code_docs: |
| 256 if doc.protos: | |
| 257 text = "\\n".join(doc.protos) | |
| 258 if doc.descr: | |
| 259 if text: | |
| 260 text += "\\n" | |
| 261 text += doc.descr | |
| 627 | 262 |
| 263 f.write('#define %s "%s"\n\n' % (defineName, text)) | |
| 264 | |
| 265 if doc.kids: | |
| 266 for kid in doc.kids: | |
| 1609 | 267 WriteDocHeader(f, kid, have_code_docs) |
| 627 | 268 |
|
1503
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
269 def WriteDocHeaderComments(f, doc): |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
270 name = doc.fullname |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
271 |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
272 defineName = name |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
273 text = "" |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
274 if doc.protos: |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
275 text = "\n".join(doc.protos) |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
276 if doc.descr: |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
277 if text: |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
278 text += "\n" |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
279 text += doc.descr |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
280 text = text.replace("\\n", "\n") |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
281 #f.write('\n\n/*\n%s\n %s\n\n*/' % (defineName, text)) |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
282 f.write('\n\n%s\n %s\n\n' % (defineName, text)) |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
283 |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
284 if doc.kids: |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
285 for kid in doc.kids: |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
286 WriteDocHeaderComments(f, kid) |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
287 |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
288 |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
289 |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
290 |
|
b89b475b9a74
Add easier to read versions of docs in .h file at the end.
Rene Dudfield <renesd@gmail.com>
parents:
1373
diff
changeset
|
291 |
| 627 | 292 |
| 293 class Doc(object): | |
| 294 def __init__(self, parentname, f): | |
| 295 self.kids = None | |
| 296 self.protos = [] | |
| 297 self.docs = None | |
| 298 self.descr = "" | |
| 299 self.name = "" | |
| 300 self.fullname = "" | |
| 301 self.finished = False | |
| 302 | |
| 303 curdocline = "" | |
| 304 while True: | |
| 305 line = f.readline() | |
| 306 if not line: | |
| 307 break | |
| 308 line = line.rstrip() | |
| 309 | |
| 310 if line == "<END>": | |
| 311 if curdocline: | |
| 312 self.docs.append(curdocline) | |
| 313 curdocline = "" | |
| 314 self.finished = True | |
| 315 break | |
| 316 | |
| 317 if self.kids is not None: | |
| 318 kid = Doc(self.fullname, f) | |
| 319 if kid: | |
| 320 self.kids.append(kid) | |
| 321 | |
| 322 | |
| 323 if line == "<SECTION>": | |
| 324 if curdocline: | |
| 325 self.docs.append(curdocline) | |
| 326 curdocline = "" | |
| 327 self.kids = [] | |
| 328 continue | |
| 329 | |
| 330 if line: | |
| 331 if self.docs is not None: | |
| 332 if line[0].isspace(): | |
| 333 if curdocline: | |
| 334 self.docs.append(curdocline) | |
| 335 curdocline = "" | |
| 336 self.docs.append(line) | |
| 337 else: | |
| 338 curdocline += line + " " | |
| 339 elif not self.name: | |
| 340 self.name = line | |
|
1373
d0e31483bd3b
Added a pygame.locals module page back into the docs
Lenard Lindstrom <len-l@telus.net>
parents:
1259
diff
changeset
|
341 if len(line) > 1 and line[0] == '"' and line[-1] == '"': |
|
d0e31483bd3b
Added a pygame.locals module page back into the docs
Lenard Lindstrom <len-l@telus.net>
parents:
1259
diff
changeset
|
342 self.fullname = line[1:-1] |
|
d0e31483bd3b
Added a pygame.locals module page back into the docs
Lenard Lindstrom <len-l@telus.net>
parents:
1259
diff
changeset
|
343 elif parentname: |
| 627 | 344 splitparent = parentname.split(".") |
| 345 if splitparent[-1][0].isupper(): | |
| 346 self.fullname = splitparent[-1] + "." + line | |
| 347 else: | |
| 348 self.fullname = parentname + "." + line | |
| 349 else: | |
| 350 self.fullname = line | |
| 351 elif not self.descr: | |
| 352 self.descr = line | |
| 353 else: | |
| 354 self.protos.append(line) | |
| 355 else: | |
| 356 if self.docs is not None: | |
| 357 if curdocline: | |
| 358 self.docs.append(curdocline) | |
| 359 curdocline = "" | |
| 360 elif self.name and self.kids is None: | |
| 361 self.docs = [] | |
| 362 | |
| 363 def __repr__(self): | |
| 364 return "<Doc '%s'>" % self.name | |
| 365 | |
| 366 def __nonzero__(self): | |
| 367 return self.finished | |
| 368 | |
| 369 def __cmp__(self, b): | |
| 370 return cmp(self.name.lower(), b.name.lower()) | |
| 371 | |
|
1259
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
372 def docs_as_dict(): |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
373 """ |
| 627 | 374 |
|
1259
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
375 Dict Format: |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
376 |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
377 {'pygame.rect.Rect.center': 'Rect.center: ...' ...} |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
378 |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
379 Generally works, has some workarounds, inspect results manually. |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
380 |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
381 """ |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
382 |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
383 import pygame |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
384 files = collect_doc_files() |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
385 |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
386 def make_mapping(doc, parent_name): |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
387 docs = {} |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
388 for k in doc.kids: |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
389 if k.docs: |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
390 kid_name = k.fullname |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
391 |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
392 if parent_name == 'pygame': |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
393 if hasattr(pygame.base, k.name): |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
394 kid_name = '%s.%s' % ('pygame.base', k.name) |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
395 |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
396 elif not kid_name.startswith(parent_name): |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
397 kid_name = '%s.%s' % (parent_name, kid_name) |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
398 |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
399 docs[kid_name] = '\n'.join(k.docs) |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
400 |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
401 if k.kids: |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
402 docs.update(make_mapping(k, parent_name)) |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
403 return docs |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
404 |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
405 mapping = {} |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
406 for f in files: |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
407 doc = Doc('', open(f, "U")) |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
408 mapping.update(make_mapping(doc, doc.name.lower())) |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
409 |
|
9ca221a18f66
added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk
akalias
parents:
975
diff
changeset
|
410 return mapping |
| 627 | 411 |
| 412 HTMLHeader = """ | |
| 413 <html> | |
| 414 <title>%s - Pygame Documentation</title> | |
| 415 <body bgcolor=#aaeebb text=#000000 link=#331111 vlink=#331111> | |
| 416 | |
| 417 | |
|
641
b7d1a9cbcffb
changes from philhassey for adjustments to the design
Rene Dudfield <renesd@gmail.com>
parents:
640
diff
changeset
|
418 <table cellpadding=0 cellspacing=0 border=0 style='border: 3px solid black;' width='100%%'> |
|
b7d1a9cbcffb
changes from philhassey for adjustments to the design
Rene Dudfield <renesd@gmail.com>
parents:
640
diff
changeset
|
419 <tr> |
|
b7d1a9cbcffb
changes from philhassey for adjustments to the design
Rene Dudfield <renesd@gmail.com>
parents:
640
diff
changeset
|
420 <td bgcolor='#c2fc20' style='padding: 6px;' align=center valign=center><a href='http://www.pygame.org/'><img src='../pygame_tiny.gif' border=0 width=200 height=60></a><br><b>pygame documentation</b></td> |
|
b7d1a9cbcffb
changes from philhassey for adjustments to the design
Rene Dudfield <renesd@gmail.com>
parents:
640
diff
changeset
|
421 <td bgcolor='#6aee28' style='border-left: 3px solid black; padding: 6px;' align=center valign=center> |
| 627 | 422 || |
| 423 <a href=http://www.pygame.org>Pygame Home</a> || | |
| 424 <a href=../index.html>Help Contents</a> || | |
| 425 <a href=index.html>Reference Index</a> || | |
| 426 <br> <br> | |
| 427 | |
| 428 """ | |
| 429 | |
| 430 HTMLMid = """ | |
|
641
b7d1a9cbcffb
changes from philhassey for adjustments to the design
Rene Dudfield <renesd@gmail.com>
parents:
640
diff
changeset
|
431 </td></tr></table> |
| 627 | 432 <br> |
| 433 """ | |
| 434 | |
| 435 HTMLFinish = """ | |
| 436 </body></html> | |
| 437 """ | |
| 438 | |
| 439 if __name__ == '__main__': | |
|
1373
d0e31483bd3b
Added a pygame.locals module page back into the docs
Lenard Lindstrom <len-l@telus.net>
parents:
1259
diff
changeset
|
440 Run() |
