Tim Peters | 4f109c1 | 2002-04-19 18:41:46 +0000 | [diff] [blame] | 1 | """ |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 2 | Makes the necesary files to convert from plain html of |
| 3 | Python 1.5 and 1.5.x Documentation to |
| 4 | Microsoft HTML Help format version 1.1 |
| 5 | Doesn't change the html's docs. |
| 6 | |
| 7 | by hernan.foffani@iname.com |
| 8 | no copyright and no responsabilities. |
| 9 | |
| 10 | modified by Dale Nagata for Python 1.5.2 |
| 11 | |
| 12 | Renamed from make_chm.py to prechm.py, and checked into the Python |
| 13 | project, 19-Apr-2002 by Tim Peters. Assorted modifications by Tim |
| 14 | and Fred Drake. Obtained from Robin Dunn's .chm packaging of the |
| 15 | Python 2.2 docs, at <http://alldunn.com/python/>. |
Tim Peters | 4f109c1 | 2002-04-19 18:41:46 +0000 | [diff] [blame] | 16 | """ |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 17 | |
| 18 | import sys |
| 19 | import os |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 20 | from formatter import NullWriter, AbstractFormatter |
| 21 | from htmllib import HTMLParser |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 22 | import getopt |
Tim Peters | 4545407 | 2002-04-20 20:26:26 +0000 | [diff] [blame] | 23 | import cgi |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 24 | |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 25 | usage_mode = ''' |
| 26 | Usage: make_chm.py [-c] [-k] [-p] [-v 1.5[.x]] filename |
| 27 | -c: does not build filename.hhc (Table of Contents) |
| 28 | -k: does not build filename.hhk (Index) |
| 29 | -p: does not build filename.hhp (Project File) |
| 30 | -v 1.5[.x]: makes help for the python 1.5[.x] docs |
| 31 | (default is python 1.5.2 docs) |
| 32 | ''' |
| 33 | |
Tim Peters | e6b63e6 | 2002-04-19 18:07:52 +0000 | [diff] [blame] | 34 | # Project file (*.hhp) template. 'arch' is the file basename (like |
| 35 | # the pythlp in pythlp.hhp); 'version' is the doc version number (like |
| 36 | # the 2.2 in Python 2.2). |
| 37 | # The magical numbers in the long line under [WINDOWS] set most of the |
| 38 | # user-visible features (visible buttons, tabs, etc). |
Tim Peters | dc374e0 | 2002-04-21 02:01:01 +0000 | [diff] [blame] | 39 | # About 0x10384e: This defines the buttons in the help viewer. The |
| 40 | # following defns are taken from htmlhelp.h. Not all possibilities |
| 41 | # actually work, and not all those that work are available from the Help |
| 42 | # Workshop GUI. In particular, the Zoom/Font button works and is not |
| 43 | # available from the GUI. The ones we're using are marked with 'x': |
| 44 | # |
| 45 | # 0x000002 Hide/Show x |
| 46 | # 0x000004 Back x |
| 47 | # 0x000008 Forward x |
| 48 | # 0x000010 Stop |
| 49 | # 0x000020 Refresh |
| 50 | # 0x000040 Home x |
| 51 | # 0x000080 Forward |
| 52 | # 0x000100 Back |
| 53 | # 0x000200 Notes |
| 54 | # 0x000400 Contents |
| 55 | # 0x000800 Locate x |
| 56 | # 0x001000 Options x |
| 57 | # 0x002000 Print x |
| 58 | # 0x004000 Index |
| 59 | # 0x008000 Search |
| 60 | # 0x010000 History |
| 61 | # 0x020000 Favorites |
| 62 | # 0x040000 Jump 1 |
| 63 | # 0x080000 Jump 2 |
| 64 | # 0x100000 Zoom/Font x |
| 65 | # 0x200000 TOC Next |
| 66 | # 0x400000 TOC Prev |
| 67 | |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 68 | project_template = ''' |
| 69 | [OPTIONS] |
Tim Peters | e6b63e6 | 2002-04-19 18:07:52 +0000 | [diff] [blame] | 70 | Compiled file=%(arch)s.chm |
| 71 | Contents file=%(arch)s.hhc |
| 72 | Default Window=%(arch)s |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 73 | Default topic=index.html |
| 74 | Display compile progress=No |
Tim Peters | 4f109c1 | 2002-04-19 18:41:46 +0000 | [diff] [blame] | 75 | Full text search stop list file=%(arch)s.stp |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 76 | Full-text search=Yes |
Tim Peters | e6b63e6 | 2002-04-19 18:07:52 +0000 | [diff] [blame] | 77 | Index file=%(arch)s.hhk |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 78 | Language=0x409 |
Tim Peters | e6b63e6 | 2002-04-19 18:07:52 +0000 | [diff] [blame] | 79 | Title=Python %(version)s Documentation |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 80 | |
| 81 | [WINDOWS] |
Tim Peters | e6b63e6 | 2002-04-19 18:07:52 +0000 | [diff] [blame] | 82 | %(arch)s="Python %(version)s Documentation","%(arch)s.hhc","%(arch)s.hhk",\ |
Tim Peters | dc374e0 | 2002-04-21 02:01:01 +0000 | [diff] [blame] | 83 | "index.html","index.html",,,,,0x63520,220,0x10384e,[271,372,740,718],,,,,,,0 |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 84 | |
| 85 | [FILES] |
| 86 | ''' |
| 87 | |
Tim Peters | 4545407 | 2002-04-20 20:26:26 +0000 | [diff] [blame] | 88 | contents_header = '''\ |
| 89 | <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| 90 | <HTML> |
| 91 | <HEAD> |
| 92 | <meta name="GENERATOR" content="Microsoft® HTML Help Workshop 4.1"> |
| 93 | <!-- Sitemap 1.0 --> |
| 94 | </HEAD><BODY> |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 95 | <OBJECT type="text/site properties"> |
| 96 | <param name="Window Styles" value="0x801227"> |
Tim Peters | a905363 | 2002-04-19 16:46:43 +0000 | [diff] [blame] | 97 | <param name="ImageType" value="Folder"> |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 98 | </OBJECT> |
| 99 | <UL> |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 100 | ''' |
| 101 | |
Tim Peters | 4545407 | 2002-04-20 20:26:26 +0000 | [diff] [blame] | 102 | contents_footer = '''\ |
Tim Peters | c8490c7 | 2002-04-20 21:34:34 +0000 | [diff] [blame] | 103 | </UL></BODY></HTML> |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 104 | ''' |
| 105 | |
Tim Peters | 4545407 | 2002-04-20 20:26:26 +0000 | [diff] [blame] | 106 | object_sitemap = '''\ |
| 107 | <OBJECT type="text/sitemap"> |
| 108 | <param name="Name" value="%s"> |
| 109 | <param name="Local" value="%s"> |
| 110 | </OBJECT> |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 111 | ''' |
| 112 | |
Tim Peters | 4f109c1 | 2002-04-19 18:41:46 +0000 | [diff] [blame] | 113 | # List of words the full text search facility shouldn't index. This |
| 114 | # becomes file ARCH.stp. Note that this list must be pretty small! |
| 115 | # Different versions of the MS docs claim the file has a maximum size of |
| 116 | # 256 or 512 bytes (including \r\n at the end of each line). |
| 117 | # Note that "and", "or", "not" and "near" are operators in the search |
Tim Peters | 8d62ad7 | 2002-04-20 02:56:20 +0000 | [diff] [blame] | 118 | # language, so no point indexing them even if we wanted to. |
Tim Peters | 4f109c1 | 2002-04-19 18:41:46 +0000 | [diff] [blame] | 119 | stop_list = ''' |
Tim Peters | a3b0b29 | 2002-05-02 21:59:08 +0000 | [diff] [blame^] | 120 | a and are as at |
| 121 | be but by |
| 122 | for |
| 123 | if in into is it |
| 124 | near no not |
| 125 | of on or |
| 126 | such |
| 127 | that the their then there these they this to |
| 128 | was will with |
Tim Peters | 4f109c1 | 2002-04-19 18:41:46 +0000 | [diff] [blame] | 129 | ''' |
| 130 | |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 131 | # s is a string or None. If None or empty, return None. Else tack '.html' |
| 132 | # on to the end, unless it's already there. |
| 133 | def addhtml(s): |
| 134 | if s: |
| 135 | if not s.endswith('.html'): |
| 136 | s += '.html' |
| 137 | return s |
| 138 | |
| 139 | # Convenience class to hold info about "a book" in HTMLHelp terms == a doc |
| 140 | # directory in Python terms. |
| 141 | class Book: |
| 142 | def __init__(self, directory, title, firstpage, |
| 143 | contentpage=None, indexpage=None): |
| 144 | self.directory = directory |
| 145 | self.title = title |
| 146 | self.firstpage = addhtml(firstpage) |
| 147 | self.contentpage = addhtml(contentpage) |
| 148 | self.indexpage = addhtml(indexpage) |
| 149 | |
| 150 | # Library Doc list of books: |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 151 | # each 'book' : (Dir, Title, First page, Content page, Index page) |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 152 | supported_libraries = { |
Tim Peters | c8490c7 | 2002-04-20 21:34:34 +0000 | [diff] [blame] | 153 | '2.2': |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 154 | [ |
Tim Peters | c8490c7 | 2002-04-20 21:34:34 +0000 | [diff] [blame] | 155 | Book('.', 'Main page', 'index'), |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 156 | Book('.', 'Global Module Index', 'modindex'), |
| 157 | Book('whatsnew', "What's New", 'index', 'contents'), |
| 158 | Book('tut','Tutorial','tut','node2'), |
| 159 | Book('lib','Library Reference','lib','contents','genindex'), |
| 160 | Book('ref','Language Reference','ref','contents','genindex'), |
| 161 | Book('mac','Macintosh Reference','mac','contents','genindex'), |
| 162 | Book('ext','Extending and Embedding','ext','contents'), |
| 163 | Book('api','Python/C API','api','contents','genindex'), |
| 164 | Book('doc','Documenting Python','doc','contents'), |
| 165 | Book('inst','Installing Python Modules', 'inst', 'index'), |
| 166 | Book('dist','Distributing Python Modules', 'dist', 'index'), |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 167 | ], |
| 168 | |
| 169 | '2.1.1': |
| 170 | [ |
Tim Peters | c8490c7 | 2002-04-20 21:34:34 +0000 | [diff] [blame] | 171 | Book('.', 'Main page', 'index'), |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 172 | Book('.', 'Global Module Index', 'modindex'), |
| 173 | Book('tut','Tutorial','tut','node2'), |
| 174 | Book('lib','Library Reference','lib','contents','genindex'), |
| 175 | Book('ref','Language Reference','ref','contents','genindex'), |
| 176 | Book('mac','Macintosh Reference','mac','contents','genindex'), |
| 177 | Book('ext','Extending and Embedding','ext','contents'), |
| 178 | Book('api','Python/C API','api','contents','genindex'), |
| 179 | Book('doc','Documenting Python','doc','contents'), |
| 180 | Book('inst','Installing Python Modules', 'inst', 'index'), |
| 181 | Book('dist','Distributing Python Modules', 'dist', 'index'), |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 182 | ], |
| 183 | |
| 184 | '2.0.0': |
| 185 | [ |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 186 | Book('.', 'Global Module Index', 'modindex'), |
| 187 | Book('tut','Tutorial','tut','node2'), |
| 188 | Book('lib','Library Reference','lib','contents','genindex'), |
| 189 | Book('ref','Language Reference','ref','contents','genindex'), |
| 190 | Book('mac','Macintosh Reference','mac','contents','genindex'), |
| 191 | Book('ext','Extending and Embedding','ext','contents'), |
| 192 | Book('api','Python/C API','api','contents','genindex'), |
| 193 | Book('doc','Documenting Python','doc','contents'), |
| 194 | Book('inst','Installing Python Modules', 'inst', 'contents'), |
| 195 | Book('dist','Distributing Python Modules', 'dist', 'contents'), |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 196 | ], |
| 197 | |
| 198 | # <dnagata@creo.com> Apr 17/99: library for 1.5.2 version: |
| 199 | # <hernan.foffani@iname.com> May 01/99: library for 1.5.2 (04/30/99): |
| 200 | '1.5.2': |
| 201 | [ |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 202 | Book('tut','Tutorial','tut','node2'), |
| 203 | Book('lib','Library Reference','lib','contents','genindex'), |
| 204 | Book('ref','Language Reference','ref','contents','genindex'), |
| 205 | Book('mac','Macintosh Reference','mac','contents','genindex'), |
| 206 | Book('ext','Extending and Embedding','ext','contents'), |
| 207 | Book('api','Python/C API','api','contents','genindex'), |
| 208 | Book('doc','Documenting Python','doc','contents') |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 209 | ], |
| 210 | |
| 211 | # library for 1.5.1 version: |
| 212 | '1.5.1': |
| 213 | [ |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 214 | Book('tut','Tutorial','tut','contents'), |
| 215 | Book('lib','Library Reference','lib','contents','genindex'), |
| 216 | Book('ref','Language Reference','ref-1','ref-2','ref-11'), |
| 217 | Book('ext','Extending and Embedding','ext','contents'), |
| 218 | Book('api','Python/C API','api','contents','genindex') |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 219 | ], |
| 220 | |
| 221 | # library for 1.5 version: |
| 222 | '1.5': |
| 223 | [ |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 224 | Book('tut','Tutorial','tut','node1'), |
| 225 | Book('lib','Library Reference','lib','node1','node268'), |
| 226 | Book('ref','Language Reference','ref-1','ref-2','ref-11'), |
| 227 | Book('ext','Extending and Embedding','ext','node1'), |
| 228 | Book('api','Python/C API','api','node1','node48') |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 229 | ] |
| 230 | } |
| 231 | |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 232 | # AlmostNullWriter doesn't print anything; it just arranges to save the |
| 233 | # text sent to send_flowing_data(). This is used to capture the text |
| 234 | # between an anchor begin/end pair, e.g. for TOC entries. |
| 235 | |
| 236 | class AlmostNullWriter(NullWriter): |
| 237 | |
| 238 | def __init__(self): |
| 239 | NullWriter.__init__(self) |
| 240 | self.saved_clear() |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 241 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 242 | def send_flowing_data(self, data): |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 243 | stripped = data.strip() |
| 244 | if stripped: # don't bother to save runs of whitespace |
| 245 | self.saved.append(stripped) |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 246 | |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 247 | # Forget all saved text. |
| 248 | def saved_clear(self): |
| 249 | self.saved = [] |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 250 | |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 251 | # Return all saved text as a string. |
| 252 | def saved_get(self): |
| 253 | return ' '.join(self.saved) |
| 254 | |
| 255 | class HelpHtmlParser(HTMLParser): |
| 256 | |
| 257 | def __init__(self, formatter, path, output): |
| 258 | HTMLParser.__init__(self, formatter) |
| 259 | self.path = path # relative path |
| 260 | self.ft = output # output file |
| 261 | self.indent = 0 # number of tabs for pretty printing of files |
| 262 | self.proc = False # True when actively processing, else False |
| 263 | # (headers, footers, etc) |
Tim Peters | 4545407 | 2002-04-20 20:26:26 +0000 | [diff] [blame] | 264 | # XXX This shouldn't need to be a stack -- anchors shouldn't nest. |
| 265 | # XXX See SF bug <http://www.python.org/sf/546579>. |
| 266 | self.hrefstack = [] # stack of hrefs from anchor begins |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 267 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 268 | def begin_group(self): |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 269 | self.indent += 1 |
| 270 | self.proc = True |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 271 | |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 272 | def finish_group(self): |
| 273 | self.indent -= 1 |
| 274 | # stop processing when back to top level |
| 275 | self.proc = self.indent > 0 |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 276 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 277 | def anchor_bgn(self, href, name, type): |
| 278 | if self.proc: |
Tim Peters | 4545407 | 2002-04-20 20:26:26 +0000 | [diff] [blame] | 279 | # XXX See SF bug <http://www.python.org/sf/546579>. |
Tim Peters | 4a0db06 | 2002-04-21 04:44:11 +0000 | [diff] [blame] | 280 | # XXX index.html for the 2.2.1 language reference manual contains |
Tim Peters | 4545407 | 2002-04-20 20:26:26 +0000 | [diff] [blame] | 281 | # XXX nested <a></a> tags in the entry for the section on blank |
| 282 | # XXX lines. We want to ignore the nested part completely. |
| 283 | if len(self.hrefstack) == 0: |
Tim Peters | 4a0db06 | 2002-04-21 04:44:11 +0000 | [diff] [blame] | 284 | self.saved_clear() |
| 285 | self.hrefstack.append(href) |
| 286 | |
| 287 | def anchor_end(self): |
| 288 | if self.proc: |
| 289 | # XXX See XXX above. |
| 290 | if self.hrefstack: |
| 291 | title = cgi.escape(self.saved_get(), True) |
| 292 | path = self.path + '/' + self.hrefstack.pop() |
Tim Peters | 4545407 | 2002-04-20 20:26:26 +0000 | [diff] [blame] | 293 | self.tab(object_sitemap % (title, path)) |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 294 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 295 | def start_dl(self, atr_val): |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 296 | self.begin_group() |
| 297 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 298 | def end_dl(self): |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 299 | self.finish_group() |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 300 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 301 | def do_dt(self, atr_val): |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 302 | # no trailing newline on purpose! |
| 303 | self.tab("<LI>") |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 304 | |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 305 | # Write text to output file. |
| 306 | def write(self, text): |
| 307 | self.ft.write(text) |
| 308 | |
| 309 | # Write text to output file after indenting by self.indent tabs. |
| 310 | def tab(self, text=''): |
| 311 | self.write('\t' * self.indent) |
| 312 | if text: |
| 313 | self.write(text) |
| 314 | |
| 315 | # Forget all saved text. |
| 316 | def saved_clear(self): |
| 317 | self.formatter.writer.saved_clear() |
| 318 | |
| 319 | # Return all saved text as a string. |
| 320 | def saved_get(self): |
| 321 | return self.formatter.writer.saved_get() |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 322 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 323 | class IdxHlpHtmlParser(HelpHtmlParser): |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 324 | # nothing special here, seems enough with parent class |
| 325 | pass |
| 326 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 327 | class TocHlpHtmlParser(HelpHtmlParser): |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 328 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 329 | def start_dl(self, atr_val): |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 330 | self.begin_group() |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 331 | self.tab('<UL>\n') |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 332 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 333 | def end_dl(self): |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 334 | self.finish_group() |
| 335 | self.tab('</UL>\n') |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 336 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 337 | def start_ul(self, atr_val): |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 338 | self.begin_group() |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 339 | self.tab('<UL>\n') |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 340 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 341 | def end_ul(self): |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 342 | self.finish_group() |
| 343 | self.tab('</UL>\n') |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 344 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 345 | def do_li(self, atr_val): |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 346 | # no trailing newline on purpose! |
| 347 | self.tab("<LI>") |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 348 | |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 349 | def index(path, indexpage, output): |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 350 | parser = IdxHlpHtmlParser(AbstractFormatter(AlmostNullWriter()), |
| 351 | path, output) |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 352 | f = open(path + '/' + indexpage) |
| 353 | parser.feed(f.read()) |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 354 | parser.close() |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 355 | f.close() |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 356 | |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 357 | def content(path, contentpage, output): |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 358 | parser = TocHlpHtmlParser(AbstractFormatter(AlmostNullWriter()), |
| 359 | path, output) |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 360 | f = open(path + '/' + contentpage) |
| 361 | parser.feed(f.read()) |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 362 | parser.close() |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 363 | f.close() |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 364 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 365 | def do_index(library, output): |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 366 | output.write('<UL>\n') |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 367 | for book in library: |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 368 | print '\t', book.title, '-', book.indexpage |
| 369 | if book.indexpage: |
| 370 | index(book.directory, book.indexpage, output) |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 371 | output.write('</UL>\n') |
| 372 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 373 | def do_content(library, version, output): |
Tim Peters | c8490c7 | 2002-04-20 21:34:34 +0000 | [diff] [blame] | 374 | output.write(contents_header) |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 375 | for book in library: |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 376 | print '\t', book.title, '-', book.firstpage |
Tim Peters | 4545407 | 2002-04-20 20:26:26 +0000 | [diff] [blame] | 377 | path = book.directory + "/" + book.firstpage |
| 378 | output.write('<LI>') |
| 379 | output.write(object_sitemap % (book.title, path)) |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 380 | if book.contentpage: |
| 381 | content(book.directory, book.contentpage, output) |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 382 | output.write(contents_footer) |
| 383 | |
Tim Peters | 460643b | 2002-04-20 02:37:07 +0000 | [diff] [blame] | 384 | # Fill in the [FILES] section of the project (.hhp) file. |
| 385 | # 'library' is the list of directory description tuples from |
| 386 | # supported_libraries for the version of the docs getting generated. |
| 387 | def do_project(library, output, arch, version): |
Tim Peters | e6b63e6 | 2002-04-19 18:07:52 +0000 | [diff] [blame] | 388 | output.write(project_template % locals()) |
Tim Peters | c8490c7 | 2002-04-20 21:34:34 +0000 | [diff] [blame] | 389 | pathseen = {} |
Tim Peters | 460643b | 2002-04-20 02:37:07 +0000 | [diff] [blame] | 390 | for book in library: |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 391 | directory = book.directory |
Tim Peters | 460643b | 2002-04-20 02:37:07 +0000 | [diff] [blame] | 392 | path = directory + '\\%s\n' |
| 393 | for page in os.listdir(directory): |
| 394 | if page.endswith('.html') or page.endswith('.css'): |
Tim Peters | c8490c7 | 2002-04-20 21:34:34 +0000 | [diff] [blame] | 395 | fullpath = path % page |
| 396 | if fullpath not in pathseen: |
| 397 | output.write(fullpath) |
| 398 | pathseen[fullpath] = True |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 399 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 400 | def openfile(file): |
| 401 | try: |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 402 | p = open(file, "w") |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 403 | except IOError, msg: |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 404 | print file, ":", msg |
| 405 | sys.exit(1) |
| 406 | return p |
| 407 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 408 | def usage(): |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 409 | print usage_mode |
| 410 | sys.exit(0) |
| 411 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 412 | def do_it(args = None): |
| 413 | if not args: |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 414 | args = sys.argv[1:] |
| 415 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 416 | if not args: |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 417 | usage() |
| 418 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 419 | try: |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 420 | optlist, args = getopt.getopt(args, 'ckpv:') |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 421 | except getopt.error, msg: |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 422 | print msg |
| 423 | usage() |
| 424 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 425 | if not args or len(args) > 1: |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 426 | usage() |
| 427 | arch = args[0] |
| 428 | |
| 429 | version = None |
| 430 | for opt in optlist: |
| 431 | if opt[0] == '-v': |
| 432 | version = opt[1] |
| 433 | break |
| 434 | if not version: |
| 435 | usage() |
| 436 | |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 437 | library = supported_libraries[version] |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 438 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 439 | if not (('-p','') in optlist): |
Tim Peters | 4f109c1 | 2002-04-19 18:41:46 +0000 | [diff] [blame] | 440 | fname = arch + '.stp' |
| 441 | f = openfile(fname) |
| 442 | print "Building stoplist", fname, "..." |
| 443 | words = stop_list.split() |
| 444 | words.sort() |
| 445 | for word in words: |
| 446 | print >> f, word |
| 447 | f.close() |
| 448 | |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 449 | f = openfile(arch + '.hhp') |
| 450 | print "Building Project..." |
| 451 | do_project(library, f, arch, version) |
| 452 | if version == '2.0.0': |
| 453 | for image in os.listdir('icons'): |
| 454 | f.write('icons'+ '\\' + image + '\n') |
| 455 | |
| 456 | f.close() |
| 457 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 458 | if not (('-c','') in optlist): |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 459 | f = openfile(arch + '.hhc') |
| 460 | print "Building Table of Content..." |
| 461 | do_content(library, version, f) |
| 462 | f.close() |
| 463 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 464 | if not (('-k','') in optlist): |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 465 | f = openfile(arch + '.hhk') |
| 466 | print "Building Index..." |
| 467 | do_index(library, f) |
| 468 | f.close() |
| 469 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 470 | if __name__ == '__main__': |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 471 | do_it() |