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 string |
| 23 | import getopt |
| 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 | |
| 59 | contents_header = ''' |
| 60 | <OBJECT type="text/site properties"> |
| 61 | <param name="Window Styles" value="0x801227"> |
Tim Peters | a905363 | 2002-04-19 16:46:43 +0000 | [diff] [blame] | 62 | <param name="ImageType" value="Folder"> |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 63 | </OBJECT> |
| 64 | <UL> |
| 65 | <LI> <OBJECT type="text/sitemap"> |
| 66 | <param name="Name" value="Python %s Docs"> |
| 67 | <param name="Local" value="./index.html"> |
| 68 | </OBJECT> |
| 69 | <UL> |
| 70 | ''' |
| 71 | |
| 72 | contents_footer = ''' |
| 73 | </UL></UL> |
| 74 | ''' |
| 75 | |
| 76 | object_sitemap = ''' |
| 77 | <LI> <OBJECT type="text/sitemap"> |
| 78 | <param name="Local" value="%s"> |
| 79 | <param name="Name" value="%s"> |
| 80 | </OBJECT> |
| 81 | ''' |
| 82 | |
Tim Peters | 4f109c1 | 2002-04-19 18:41:46 +0000 | [diff] [blame] | 83 | |
| 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 = { |
| 122 | '2.2': ### Beta!!! fix for actual release |
| 123 | [ |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 124 | Book('.', 'Global Module Index', 'modindex'), |
| 125 | Book('whatsnew', "What's New", 'index', 'contents'), |
| 126 | Book('tut','Tutorial','tut','node2'), |
| 127 | Book('lib','Library Reference','lib','contents','genindex'), |
| 128 | Book('ref','Language Reference','ref','contents','genindex'), |
| 129 | Book('mac','Macintosh Reference','mac','contents','genindex'), |
| 130 | Book('ext','Extending and Embedding','ext','contents'), |
| 131 | Book('api','Python/C API','api','contents','genindex'), |
| 132 | Book('doc','Documenting Python','doc','contents'), |
| 133 | Book('inst','Installing Python Modules', 'inst', 'index'), |
| 134 | Book('dist','Distributing Python Modules', 'dist', 'index'), |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 135 | ], |
| 136 | |
| 137 | '2.1.1': |
| 138 | [ |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 139 | Book('.', 'Global Module Index', 'modindex'), |
| 140 | Book('tut','Tutorial','tut','node2'), |
| 141 | Book('lib','Library Reference','lib','contents','genindex'), |
| 142 | Book('ref','Language Reference','ref','contents','genindex'), |
| 143 | Book('mac','Macintosh Reference','mac','contents','genindex'), |
| 144 | Book('ext','Extending and Embedding','ext','contents'), |
| 145 | Book('api','Python/C API','api','contents','genindex'), |
| 146 | Book('doc','Documenting Python','doc','contents'), |
| 147 | Book('inst','Installing Python Modules', 'inst', 'index'), |
| 148 | Book('dist','Distributing Python Modules', 'dist', 'index'), |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 149 | ], |
| 150 | |
| 151 | '2.0.0': |
| 152 | [ |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 153 | Book('.', 'Global Module Index', 'modindex'), |
| 154 | Book('tut','Tutorial','tut','node2'), |
| 155 | Book('lib','Library Reference','lib','contents','genindex'), |
| 156 | Book('ref','Language Reference','ref','contents','genindex'), |
| 157 | Book('mac','Macintosh Reference','mac','contents','genindex'), |
| 158 | Book('ext','Extending and Embedding','ext','contents'), |
| 159 | Book('api','Python/C API','api','contents','genindex'), |
| 160 | Book('doc','Documenting Python','doc','contents'), |
| 161 | Book('inst','Installing Python Modules', 'inst', 'contents'), |
| 162 | Book('dist','Distributing Python Modules', 'dist', 'contents'), |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 163 | ], |
| 164 | |
| 165 | # <dnagata@creo.com> Apr 17/99: library for 1.5.2 version: |
| 166 | # <hernan.foffani@iname.com> May 01/99: library for 1.5.2 (04/30/99): |
| 167 | '1.5.2': |
| 168 | [ |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 169 | Book('tut','Tutorial','tut','node2'), |
| 170 | Book('lib','Library Reference','lib','contents','genindex'), |
| 171 | Book('ref','Language Reference','ref','contents','genindex'), |
| 172 | Book('mac','Macintosh Reference','mac','contents','genindex'), |
| 173 | Book('ext','Extending and Embedding','ext','contents'), |
| 174 | Book('api','Python/C API','api','contents','genindex'), |
| 175 | Book('doc','Documenting Python','doc','contents') |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 176 | ], |
| 177 | |
| 178 | # library for 1.5.1 version: |
| 179 | '1.5.1': |
| 180 | [ |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 181 | Book('tut','Tutorial','tut','contents'), |
| 182 | Book('lib','Library Reference','lib','contents','genindex'), |
| 183 | Book('ref','Language Reference','ref-1','ref-2','ref-11'), |
| 184 | Book('ext','Extending and Embedding','ext','contents'), |
| 185 | Book('api','Python/C API','api','contents','genindex') |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 186 | ], |
| 187 | |
| 188 | # library for 1.5 version: |
| 189 | '1.5': |
| 190 | [ |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 191 | Book('tut','Tutorial','tut','node1'), |
| 192 | Book('lib','Library Reference','lib','node1','node268'), |
| 193 | Book('ref','Language Reference','ref-1','ref-2','ref-11'), |
| 194 | Book('ext','Extending and Embedding','ext','node1'), |
| 195 | Book('api','Python/C API','api','node1','node48') |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 196 | ] |
| 197 | } |
| 198 | |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 199 | # AlmostNullWriter doesn't print anything; it just arranges to save the |
| 200 | # text sent to send_flowing_data(). This is used to capture the text |
| 201 | # between an anchor begin/end pair, e.g. for TOC entries. |
| 202 | |
| 203 | class AlmostNullWriter(NullWriter): |
| 204 | |
| 205 | def __init__(self): |
| 206 | NullWriter.__init__(self) |
| 207 | self.saved_clear() |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 208 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 209 | def send_flowing_data(self, data): |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 210 | stripped = data.strip() |
| 211 | if stripped: # don't bother to save runs of whitespace |
| 212 | self.saved.append(stripped) |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 213 | |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 214 | # Forget all saved text. |
| 215 | def saved_clear(self): |
| 216 | self.saved = [] |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 217 | |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 218 | # Return all saved text as a string. |
| 219 | def saved_get(self): |
| 220 | return ' '.join(self.saved) |
| 221 | |
| 222 | class HelpHtmlParser(HTMLParser): |
| 223 | |
| 224 | def __init__(self, formatter, path, output): |
| 225 | HTMLParser.__init__(self, formatter) |
| 226 | self.path = path # relative path |
| 227 | self.ft = output # output file |
| 228 | self.indent = 0 # number of tabs for pretty printing of files |
| 229 | self.proc = False # True when actively processing, else False |
| 230 | # (headers, footers, etc) |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 231 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 232 | def begin_group(self): |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 233 | self.indent += 1 |
| 234 | self.proc = True |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 235 | |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 236 | def finish_group(self): |
| 237 | self.indent -= 1 |
| 238 | # stop processing when back to top level |
| 239 | self.proc = self.indent > 0 |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 240 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 241 | def anchor_bgn(self, href, name, type): |
| 242 | if self.proc: |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 243 | self.saved_clear() |
| 244 | self.write('<OBJECT type="text/sitemap">\n') |
| 245 | self.tab('\t<param name="Local" value="%s/%s">\n' % |
| 246 | (self.path, href)) |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 247 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 248 | def anchor_end(self): |
| 249 | if self.proc: |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 250 | self.tab('\t<param name="Name" value="%s">\n' % self.saved_get()) |
| 251 | self.tab('\t</OBJECT>\n') |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 252 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 253 | def start_dl(self, atr_val): |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 254 | self.begin_group() |
| 255 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 256 | def end_dl(self): |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 257 | self.finish_group() |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 258 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 259 | def do_dt(self, atr_val): |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 260 | # no trailing newline on purpose! |
| 261 | self.tab("<LI>") |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 262 | |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 263 | # Write text to output file. |
| 264 | def write(self, text): |
| 265 | self.ft.write(text) |
| 266 | |
| 267 | # Write text to output file after indenting by self.indent tabs. |
| 268 | def tab(self, text=''): |
| 269 | self.write('\t' * self.indent) |
| 270 | if text: |
| 271 | self.write(text) |
| 272 | |
| 273 | # Forget all saved text. |
| 274 | def saved_clear(self): |
| 275 | self.formatter.writer.saved_clear() |
| 276 | |
| 277 | # Return all saved text as a string. |
| 278 | def saved_get(self): |
| 279 | return self.formatter.writer.saved_get() |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 280 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 281 | class IdxHlpHtmlParser(HelpHtmlParser): |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 282 | # nothing special here, seems enough with parent class |
| 283 | pass |
| 284 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 285 | class TocHlpHtmlParser(HelpHtmlParser): |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 286 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 287 | def start_dl(self, atr_val): |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 288 | self.begin_group() |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 289 | self.tab('<UL>\n') |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 290 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 291 | def end_dl(self): |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 292 | self.finish_group() |
| 293 | self.tab('</UL>\n') |
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_ul(self, atr_val): |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 296 | self.begin_group() |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 297 | self.tab('<UL>\n') |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 298 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 299 | def end_ul(self): |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 300 | self.finish_group() |
| 301 | self.tab('</UL>\n') |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 302 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 303 | def do_li(self, atr_val): |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 304 | # no trailing newline on purpose! |
| 305 | self.tab("<LI>") |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 306 | |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 307 | def index(path, indexpage, output): |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 308 | parser = IdxHlpHtmlParser(AbstractFormatter(AlmostNullWriter()), |
| 309 | path, output) |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 310 | f = open(path + '/' + indexpage) |
| 311 | parser.feed(f.read()) |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 312 | parser.close() |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 313 | f.close() |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 314 | |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 315 | def content(path, contentpage, output): |
Tim Peters | e21095e | 2002-04-20 08:36:42 +0000 | [diff] [blame] | 316 | parser = TocHlpHtmlParser(AbstractFormatter(AlmostNullWriter()), |
| 317 | path, output) |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 318 | f = open(path + '/' + contentpage) |
| 319 | parser.feed(f.read()) |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 320 | parser.close() |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 321 | f.close() |
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 | def do_index(library, output): |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 324 | output.write('<UL>\n') |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 325 | for book in library: |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 326 | print '\t', book.title, '-', book.indexpage |
| 327 | if book.indexpage: |
| 328 | index(book.directory, book.indexpage, output) |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 329 | output.write('</UL>\n') |
| 330 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 331 | def do_content(library, version, output): |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 332 | output.write(contents_header % version) |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 333 | for book in library: |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 334 | print '\t', book.title, '-', book.firstpage |
| 335 | output.write(object_sitemap % (book.directory + "/" + book.firstpage, |
| 336 | book.title)) |
| 337 | if book.contentpage: |
| 338 | content(book.directory, book.contentpage, output) |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 339 | output.write(contents_footer) |
| 340 | |
Tim Peters | 460643b | 2002-04-20 02:37:07 +0000 | [diff] [blame] | 341 | # Fill in the [FILES] section of the project (.hhp) file. |
| 342 | # 'library' is the list of directory description tuples from |
| 343 | # supported_libraries for the version of the docs getting generated. |
| 344 | def do_project(library, output, arch, version): |
Tim Peters | e6b63e6 | 2002-04-19 18:07:52 +0000 | [diff] [blame] | 345 | output.write(project_template % locals()) |
Tim Peters | 460643b | 2002-04-20 02:37:07 +0000 | [diff] [blame] | 346 | for book in library: |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 347 | directory = book.directory |
Tim Peters | 460643b | 2002-04-20 02:37:07 +0000 | [diff] [blame] | 348 | path = directory + '\\%s\n' |
| 349 | for page in os.listdir(directory): |
| 350 | if page.endswith('.html') or page.endswith('.css'): |
| 351 | output.write(path % page) |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 352 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 353 | def openfile(file): |
| 354 | try: |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 355 | p = open(file, "w") |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 356 | except IOError, msg: |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 357 | print file, ":", msg |
| 358 | sys.exit(1) |
| 359 | return p |
| 360 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 361 | def usage(): |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 362 | print usage_mode |
| 363 | sys.exit(0) |
| 364 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 365 | def do_it(args = None): |
| 366 | if not args: |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 367 | args = sys.argv[1:] |
| 368 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 369 | if not args: |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 370 | usage() |
| 371 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 372 | try: |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 373 | optlist, args = getopt.getopt(args, 'ckpv:') |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 374 | except getopt.error, msg: |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 375 | print msg |
| 376 | usage() |
| 377 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 378 | if not args or len(args) > 1: |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 379 | usage() |
| 380 | arch = args[0] |
| 381 | |
| 382 | version = None |
| 383 | for opt in optlist: |
| 384 | if opt[0] == '-v': |
| 385 | version = opt[1] |
| 386 | break |
| 387 | if not version: |
| 388 | usage() |
| 389 | |
Tim Peters | d9a1050 | 2002-04-20 03:25:02 +0000 | [diff] [blame] | 390 | library = supported_libraries[version] |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 391 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 392 | if not (('-p','') in optlist): |
Tim Peters | 4f109c1 | 2002-04-19 18:41:46 +0000 | [diff] [blame] | 393 | fname = arch + '.stp' |
| 394 | f = openfile(fname) |
| 395 | print "Building stoplist", fname, "..." |
| 396 | words = stop_list.split() |
| 397 | words.sort() |
| 398 | for word in words: |
| 399 | print >> f, word |
| 400 | f.close() |
| 401 | |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 402 | f = openfile(arch + '.hhp') |
| 403 | print "Building Project..." |
| 404 | do_project(library, f, arch, version) |
| 405 | if version == '2.0.0': |
| 406 | for image in os.listdir('icons'): |
| 407 | f.write('icons'+ '\\' + image + '\n') |
| 408 | |
| 409 | f.close() |
| 410 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 411 | if not (('-c','') in optlist): |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 412 | f = openfile(arch + '.hhc') |
| 413 | print "Building Table of Content..." |
| 414 | do_content(library, version, f) |
| 415 | f.close() |
| 416 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 417 | if not (('-k','') in optlist): |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 418 | f = openfile(arch + '.hhk') |
| 419 | print "Building Index..." |
| 420 | do_index(library, f) |
| 421 | f.close() |
| 422 | |
Tim Peters | 661e492 | 2002-04-20 02:39:44 +0000 | [diff] [blame] | 423 | if __name__ == '__main__': |
Tim Peters | 52cfa33 | 2002-04-19 16:09:26 +0000 | [diff] [blame] | 424 | do_it() |