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