blob: 7b2f3936cecf89c98a01157847e4dedbb1c99baf [file] [log] [blame]
Tim Peters4f109c12002-04-19 18:41:46 +00001"""
Tim Peters52cfa332002-04-19 16:09:26 +00002 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 Peters4f109c12002-04-19 18:41:46 +000016"""
Tim Peters52cfa332002-04-19 16:09:26 +000017
18import sys
19import os
Tim Peterse21095e2002-04-20 08:36:42 +000020from formatter import NullWriter, AbstractFormatter
21from htmllib import HTMLParser
Tim Peters52cfa332002-04-19 16:09:26 +000022import getopt
Tim Peters45454072002-04-20 20:26:26 +000023import cgi
Tim Peters52cfa332002-04-19 16:09:26 +000024
Tim Peters52cfa332002-04-19 16:09:26 +000025usage_mode = '''
Raymond Hettinger78205542004-02-08 20:05:40 +000026Usage: prechm.py [-c] [-k] [-p] [-v 1.5[.x]] filename
Tim Peters52cfa332002-04-19 16:09:26 +000027 -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 Peterse6b63e62002-04-19 18:07:52 +000034# 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 Petersdc374e02002-04-21 02:01:01 +000039# 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 Peters52cfa332002-04-19 16:09:26 +000068project_template = '''
69[OPTIONS]
Tim Peterse6b63e62002-04-19 18:07:52 +000070Compiled file=%(arch)s.chm
71Contents file=%(arch)s.hhc
72Default Window=%(arch)s
Tim Peters52cfa332002-04-19 16:09:26 +000073Default topic=index.html
74Display compile progress=No
Tim Peters4f109c12002-04-19 18:41:46 +000075Full text search stop list file=%(arch)s.stp
Tim Peters52cfa332002-04-19 16:09:26 +000076Full-text search=Yes
Tim Peterse6b63e62002-04-19 18:07:52 +000077Index file=%(arch)s.hhk
Tim Peters52cfa332002-04-19 16:09:26 +000078Language=0x409
Tim Peterse6b63e62002-04-19 18:07:52 +000079Title=Python %(version)s Documentation
Tim Peters52cfa332002-04-19 16:09:26 +000080
81[WINDOWS]
Tim Peterse6b63e62002-04-19 18:07:52 +000082%(arch)s="Python %(version)s Documentation","%(arch)s.hhc","%(arch)s.hhk",\
Thomas Hellerccfbfb92003-09-23 20:50:47 +000083"index.html","index.html",,,,,0x63520,220,0x10384e,[0,0,1024,768],,,,,,,0
Tim Peters52cfa332002-04-19 16:09:26 +000084
85[FILES]
86'''
87
Tim Peters45454072002-04-20 20:26:26 +000088contents_header = '''\
89<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
90<HTML>
91<HEAD>
92<meta name="GENERATOR" content="Microsoft&reg; HTML Help Workshop 4.1">
93<!-- Sitemap 1.0 -->
94</HEAD><BODY>
Tim Peters52cfa332002-04-19 16:09:26 +000095<OBJECT type="text/site properties">
Raymond Hettingerce9b4712004-02-08 19:24:18 +000096 <param name="Window Styles" value="0x801227">
97 <param name="ImageType" value="Folder">
Tim Peters52cfa332002-04-19 16:09:26 +000098</OBJECT>
99<UL>
Tim Peters52cfa332002-04-19 16:09:26 +0000100'''
101
Tim Peters45454072002-04-20 20:26:26 +0000102contents_footer = '''\
Tim Petersc8490c72002-04-20 21:34:34 +0000103</UL></BODY></HTML>
Tim Peters52cfa332002-04-19 16:09:26 +0000104'''
105
Tim Peters45454072002-04-20 20:26:26 +0000106object_sitemap = '''\
107<OBJECT type="text/sitemap">
108 <param name="Name" value="%s">
109 <param name="Local" value="%s">
110</OBJECT>
Tim Peters52cfa332002-04-19 16:09:26 +0000111'''
112
Tim Peters4f109c12002-04-19 18:41:46 +0000113# 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 Peters8d62ad72002-04-20 02:56:20 +0000118# language, so no point indexing them even if we wanted to.
Tim Peters4f109c12002-04-19 18:41:46 +0000119stop_list = '''
Tim Petersa3b0b292002-05-02 21:59:08 +0000120a and are as at
121be but by
122for
123if in into is it
124near no not
125of on or
126such
127that the their then there these they this to
128was will with
Tim Peters4f109c12002-04-19 18:41:46 +0000129'''
130
Tim Petersd9a10502002-04-20 03:25:02 +0000131# 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.
133def 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.
141class 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 Peters661e4922002-04-20 02:39:44 +0000151# each 'book' : (Dir, Title, First page, Content page, Index page)
Tim Peters52cfa332002-04-19 16:09:26 +0000152supported_libraries = {
Thomas Hellerccfbfb92003-09-23 20:50:47 +0000153 '2.4':
154 [
155 Book('.', 'Main page', 'index'),
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'),
Thomas Hellera42bc212004-06-18 08:27:36 +0000166 Book('dist','Distributing Python Modules', 'dist', 'index', 'genindex'),
Thomas Hellerccfbfb92003-09-23 20:50:47 +0000167 ],
168
169 '2.3':
170 [
171 Book('.', 'Main page', 'index'),
172 Book('.', 'Global Module Index', 'modindex'),
173 Book('whatsnew', "What's New", 'index', 'contents'),
174 Book('tut','Tutorial','tut','node2'),
175 Book('lib','Library Reference','lib','contents','genindex'),
176 Book('ref','Language Reference','ref','contents','genindex'),
177 Book('mac','Macintosh Reference','mac','contents','genindex'),
178 Book('ext','Extending and Embedding','ext','contents'),
179 Book('api','Python/C API','api','contents','genindex'),
180 Book('doc','Documenting Python','doc','contents'),
181 Book('inst','Installing Python Modules', 'inst', 'index'),
182 Book('dist','Distributing Python Modules', 'dist', 'index'),
183 ],
184
Tim Petersc8490c72002-04-20 21:34:34 +0000185 '2.2':
Tim Peters52cfa332002-04-19 16:09:26 +0000186 [
Tim Petersc8490c72002-04-20 21:34:34 +0000187 Book('.', 'Main page', 'index'),
Tim Petersd9a10502002-04-20 03:25:02 +0000188 Book('.', 'Global Module Index', 'modindex'),
189 Book('whatsnew', "What's New", 'index', 'contents'),
190 Book('tut','Tutorial','tut','node2'),
191 Book('lib','Library Reference','lib','contents','genindex'),
192 Book('ref','Language Reference','ref','contents','genindex'),
193 Book('mac','Macintosh Reference','mac','contents','genindex'),
194 Book('ext','Extending and Embedding','ext','contents'),
195 Book('api','Python/C API','api','contents','genindex'),
196 Book('doc','Documenting Python','doc','contents'),
197 Book('inst','Installing Python Modules', 'inst', 'index'),
198 Book('dist','Distributing Python Modules', 'dist', 'index'),
Tim Peters52cfa332002-04-19 16:09:26 +0000199 ],
200
201 '2.1.1':
202 [
Tim Petersc8490c72002-04-20 21:34:34 +0000203 Book('.', 'Main page', 'index'),
Tim Petersd9a10502002-04-20 03:25:02 +0000204 Book('.', 'Global Module Index', 'modindex'),
205 Book('tut','Tutorial','tut','node2'),
206 Book('lib','Library Reference','lib','contents','genindex'),
207 Book('ref','Language Reference','ref','contents','genindex'),
208 Book('mac','Macintosh Reference','mac','contents','genindex'),
209 Book('ext','Extending and Embedding','ext','contents'),
210 Book('api','Python/C API','api','contents','genindex'),
211 Book('doc','Documenting Python','doc','contents'),
212 Book('inst','Installing Python Modules', 'inst', 'index'),
213 Book('dist','Distributing Python Modules', 'dist', 'index'),
Tim Peters52cfa332002-04-19 16:09:26 +0000214 ],
215
216 '2.0.0':
217 [
Tim Petersd9a10502002-04-20 03:25:02 +0000218 Book('.', 'Global Module Index', 'modindex'),
219 Book('tut','Tutorial','tut','node2'),
220 Book('lib','Library Reference','lib','contents','genindex'),
221 Book('ref','Language Reference','ref','contents','genindex'),
222 Book('mac','Macintosh Reference','mac','contents','genindex'),
223 Book('ext','Extending and Embedding','ext','contents'),
224 Book('api','Python/C API','api','contents','genindex'),
225 Book('doc','Documenting Python','doc','contents'),
226 Book('inst','Installing Python Modules', 'inst', 'contents'),
227 Book('dist','Distributing Python Modules', 'dist', 'contents'),
Tim Peters52cfa332002-04-19 16:09:26 +0000228 ],
229
230 # <dnagata@creo.com> Apr 17/99: library for 1.5.2 version:
231 # <hernan.foffani@iname.com> May 01/99: library for 1.5.2 (04/30/99):
232 '1.5.2':
233 [
Tim Petersd9a10502002-04-20 03:25:02 +0000234 Book('tut','Tutorial','tut','node2'),
235 Book('lib','Library Reference','lib','contents','genindex'),
236 Book('ref','Language Reference','ref','contents','genindex'),
237 Book('mac','Macintosh Reference','mac','contents','genindex'),
238 Book('ext','Extending and Embedding','ext','contents'),
239 Book('api','Python/C API','api','contents','genindex'),
240 Book('doc','Documenting Python','doc','contents')
Tim Peters52cfa332002-04-19 16:09:26 +0000241 ],
242
243 # library for 1.5.1 version:
244 '1.5.1':
245 [
Tim Petersd9a10502002-04-20 03:25:02 +0000246 Book('tut','Tutorial','tut','contents'),
247 Book('lib','Library Reference','lib','contents','genindex'),
248 Book('ref','Language Reference','ref-1','ref-2','ref-11'),
249 Book('ext','Extending and Embedding','ext','contents'),
250 Book('api','Python/C API','api','contents','genindex')
Tim Peters52cfa332002-04-19 16:09:26 +0000251 ],
252
253 # library for 1.5 version:
254 '1.5':
255 [
Tim Petersd9a10502002-04-20 03:25:02 +0000256 Book('tut','Tutorial','tut','node1'),
257 Book('lib','Library Reference','lib','node1','node268'),
258 Book('ref','Language Reference','ref-1','ref-2','ref-11'),
259 Book('ext','Extending and Embedding','ext','node1'),
260 Book('api','Python/C API','api','node1','node48')
Tim Peters52cfa332002-04-19 16:09:26 +0000261 ]
262}
263
Tim Peterse21095e2002-04-20 08:36:42 +0000264# AlmostNullWriter doesn't print anything; it just arranges to save the
265# text sent to send_flowing_data(). This is used to capture the text
266# between an anchor begin/end pair, e.g. for TOC entries.
267
268class AlmostNullWriter(NullWriter):
269
270 def __init__(self):
271 NullWriter.__init__(self)
272 self.saved_clear()
Tim Peters52cfa332002-04-19 16:09:26 +0000273
Tim Peters661e4922002-04-20 02:39:44 +0000274 def send_flowing_data(self, data):
Tim Peterse21095e2002-04-20 08:36:42 +0000275 stripped = data.strip()
276 if stripped: # don't bother to save runs of whitespace
277 self.saved.append(stripped)
Tim Peters52cfa332002-04-19 16:09:26 +0000278
Tim Peterse21095e2002-04-20 08:36:42 +0000279 # Forget all saved text.
280 def saved_clear(self):
281 self.saved = []
Tim Peters52cfa332002-04-19 16:09:26 +0000282
Tim Peterse21095e2002-04-20 08:36:42 +0000283 # Return all saved text as a string.
284 def saved_get(self):
285 return ' '.join(self.saved)
286
287class HelpHtmlParser(HTMLParser):
288
289 def __init__(self, formatter, path, output):
290 HTMLParser.__init__(self, formatter)
291 self.path = path # relative path
292 self.ft = output # output file
293 self.indent = 0 # number of tabs for pretty printing of files
294 self.proc = False # True when actively processing, else False
295 # (headers, footers, etc)
Tim Peters45454072002-04-20 20:26:26 +0000296 # XXX This shouldn't need to be a stack -- anchors shouldn't nest.
297 # XXX See SF bug <http://www.python.org/sf/546579>.
298 self.hrefstack = [] # stack of hrefs from anchor begins
Tim Peters52cfa332002-04-19 16:09:26 +0000299
Tim Peters661e4922002-04-20 02:39:44 +0000300 def begin_group(self):
Tim Peterse21095e2002-04-20 08:36:42 +0000301 self.indent += 1
302 self.proc = True
Tim Peters52cfa332002-04-19 16:09:26 +0000303
Tim Peterse21095e2002-04-20 08:36:42 +0000304 def finish_group(self):
305 self.indent -= 1
306 # stop processing when back to top level
307 self.proc = self.indent > 0
Tim Peters52cfa332002-04-19 16:09:26 +0000308
Tim Peters661e4922002-04-20 02:39:44 +0000309 def anchor_bgn(self, href, name, type):
310 if self.proc:
Tim Peters45454072002-04-20 20:26:26 +0000311 # XXX See SF bug <http://www.python.org/sf/546579>.
Tim Peters4a0db062002-04-21 04:44:11 +0000312 # XXX index.html for the 2.2.1 language reference manual contains
Tim Peters45454072002-04-20 20:26:26 +0000313 # XXX nested <a></a> tags in the entry for the section on blank
314 # XXX lines. We want to ignore the nested part completely.
315 if len(self.hrefstack) == 0:
Tim Peters4a0db062002-04-21 04:44:11 +0000316 self.saved_clear()
317 self.hrefstack.append(href)
318
319 def anchor_end(self):
320 if self.proc:
321 # XXX See XXX above.
322 if self.hrefstack:
323 title = cgi.escape(self.saved_get(), True)
324 path = self.path + '/' + self.hrefstack.pop()
Tim Peters45454072002-04-20 20:26:26 +0000325 self.tab(object_sitemap % (title, path))
Tim Peters52cfa332002-04-19 16:09:26 +0000326
Tim Peters661e4922002-04-20 02:39:44 +0000327 def start_dl(self, atr_val):
Tim Peters52cfa332002-04-19 16:09:26 +0000328 self.begin_group()
329
Tim Peters661e4922002-04-20 02:39:44 +0000330 def end_dl(self):
Tim Peterse21095e2002-04-20 08:36:42 +0000331 self.finish_group()
Tim Peters52cfa332002-04-19 16:09:26 +0000332
Tim Peters661e4922002-04-20 02:39:44 +0000333 def do_dt(self, atr_val):
Tim Peterse21095e2002-04-20 08:36:42 +0000334 # no trailing newline on purpose!
335 self.tab("<LI>")
Tim Peters52cfa332002-04-19 16:09:26 +0000336
Tim Peterse21095e2002-04-20 08:36:42 +0000337 # Write text to output file.
338 def write(self, text):
339 self.ft.write(text)
340
341 # Write text to output file after indenting by self.indent tabs.
342 def tab(self, text=''):
343 self.write('\t' * self.indent)
344 if text:
345 self.write(text)
346
347 # Forget all saved text.
348 def saved_clear(self):
349 self.formatter.writer.saved_clear()
350
351 # Return all saved text as a string.
352 def saved_get(self):
353 return self.formatter.writer.saved_get()
Tim Peters52cfa332002-04-19 16:09:26 +0000354
Tim Peters661e4922002-04-20 02:39:44 +0000355class IdxHlpHtmlParser(HelpHtmlParser):
Tim Peters52cfa332002-04-19 16:09:26 +0000356 # nothing special here, seems enough with parent class
357 pass
358
Tim Peters661e4922002-04-20 02:39:44 +0000359class TocHlpHtmlParser(HelpHtmlParser):
Tim Peters52cfa332002-04-19 16:09:26 +0000360
Tim Peters661e4922002-04-20 02:39:44 +0000361 def start_dl(self, atr_val):
Tim Peters52cfa332002-04-19 16:09:26 +0000362 self.begin_group()
Tim Peterse21095e2002-04-20 08:36:42 +0000363 self.tab('<UL>\n')
Tim Peters52cfa332002-04-19 16:09:26 +0000364
Tim Peters661e4922002-04-20 02:39:44 +0000365 def end_dl(self):
Tim Peterse21095e2002-04-20 08:36:42 +0000366 self.finish_group()
367 self.tab('</UL>\n')
Tim Peters52cfa332002-04-19 16:09:26 +0000368
Tim Peters661e4922002-04-20 02:39:44 +0000369 def start_ul(self, atr_val):
Tim Peters52cfa332002-04-19 16:09:26 +0000370 self.begin_group()
Tim Peterse21095e2002-04-20 08:36:42 +0000371 self.tab('<UL>\n')
Tim Peters52cfa332002-04-19 16:09:26 +0000372
Tim Peters661e4922002-04-20 02:39:44 +0000373 def end_ul(self):
Tim Peterse21095e2002-04-20 08:36:42 +0000374 self.finish_group()
375 self.tab('</UL>\n')
Tim Peters52cfa332002-04-19 16:09:26 +0000376
Tim Peters661e4922002-04-20 02:39:44 +0000377 def do_li(self, atr_val):
Tim Peterse21095e2002-04-20 08:36:42 +0000378 # no trailing newline on purpose!
379 self.tab("<LI>")
Tim Peters52cfa332002-04-19 16:09:26 +0000380
Tim Petersd9a10502002-04-20 03:25:02 +0000381def index(path, indexpage, output):
Tim Peterse21095e2002-04-20 08:36:42 +0000382 parser = IdxHlpHtmlParser(AbstractFormatter(AlmostNullWriter()),
383 path, output)
Tim Petersd9a10502002-04-20 03:25:02 +0000384 f = open(path + '/' + indexpage)
385 parser.feed(f.read())
Tim Peters52cfa332002-04-19 16:09:26 +0000386 parser.close()
Tim Petersd9a10502002-04-20 03:25:02 +0000387 f.close()
Tim Peters52cfa332002-04-19 16:09:26 +0000388
Tim Petersd9a10502002-04-20 03:25:02 +0000389def content(path, contentpage, output):
Tim Peterse21095e2002-04-20 08:36:42 +0000390 parser = TocHlpHtmlParser(AbstractFormatter(AlmostNullWriter()),
391 path, output)
Tim Petersd9a10502002-04-20 03:25:02 +0000392 f = open(path + '/' + contentpage)
393 parser.feed(f.read())
Tim Peters52cfa332002-04-19 16:09:26 +0000394 parser.close()
Tim Petersd9a10502002-04-20 03:25:02 +0000395 f.close()
Tim Peters52cfa332002-04-19 16:09:26 +0000396
Tim Peters661e4922002-04-20 02:39:44 +0000397def do_index(library, output):
Tim Peters52cfa332002-04-19 16:09:26 +0000398 output.write('<UL>\n')
Tim Peters661e4922002-04-20 02:39:44 +0000399 for book in library:
Tim Petersd9a10502002-04-20 03:25:02 +0000400 print '\t', book.title, '-', book.indexpage
401 if book.indexpage:
402 index(book.directory, book.indexpage, output)
Tim Peters52cfa332002-04-19 16:09:26 +0000403 output.write('</UL>\n')
404
Tim Peters661e4922002-04-20 02:39:44 +0000405def do_content(library, version, output):
Tim Petersc8490c72002-04-20 21:34:34 +0000406 output.write(contents_header)
Tim Peters661e4922002-04-20 02:39:44 +0000407 for book in library:
Tim Petersd9a10502002-04-20 03:25:02 +0000408 print '\t', book.title, '-', book.firstpage
Tim Peters45454072002-04-20 20:26:26 +0000409 path = book.directory + "/" + book.firstpage
410 output.write('<LI>')
411 output.write(object_sitemap % (book.title, path))
Tim Petersd9a10502002-04-20 03:25:02 +0000412 if book.contentpage:
413 content(book.directory, book.contentpage, output)
Tim Peters52cfa332002-04-19 16:09:26 +0000414 output.write(contents_footer)
415
Tim Peters460643b2002-04-20 02:37:07 +0000416# Fill in the [FILES] section of the project (.hhp) file.
417# 'library' is the list of directory description tuples from
418# supported_libraries for the version of the docs getting generated.
419def do_project(library, output, arch, version):
Tim Peterse6b63e62002-04-19 18:07:52 +0000420 output.write(project_template % locals())
Tim Petersc8490c72002-04-20 21:34:34 +0000421 pathseen = {}
Tim Peters460643b2002-04-20 02:37:07 +0000422 for book in library:
Tim Petersd9a10502002-04-20 03:25:02 +0000423 directory = book.directory
Tim Peters460643b2002-04-20 02:37:07 +0000424 path = directory + '\\%s\n'
425 for page in os.listdir(directory):
426 if page.endswith('.html') or page.endswith('.css'):
Tim Petersc8490c72002-04-20 21:34:34 +0000427 fullpath = path % page
428 if fullpath not in pathseen:
429 output.write(fullpath)
430 pathseen[fullpath] = True
Tim Peters52cfa332002-04-19 16:09:26 +0000431
Tim Peters661e4922002-04-20 02:39:44 +0000432def openfile(file):
433 try:
Tim Peters52cfa332002-04-19 16:09:26 +0000434 p = open(file, "w")
Tim Peters661e4922002-04-20 02:39:44 +0000435 except IOError, msg:
Tim Peters52cfa332002-04-19 16:09:26 +0000436 print file, ":", msg
437 sys.exit(1)
438 return p
439
Tim Peters661e4922002-04-20 02:39:44 +0000440def usage():
Tim Peters3d7d3722004-07-18 06:25:50 +0000441 print usage_mode
442 sys.exit(0)
Tim Peters52cfa332002-04-19 16:09:26 +0000443
Tim Peters661e4922002-04-20 02:39:44 +0000444def do_it(args = None):
445 if not args:
Tim Peters52cfa332002-04-19 16:09:26 +0000446 args = sys.argv[1:]
447
Tim Peters661e4922002-04-20 02:39:44 +0000448 if not args:
Tim Peters52cfa332002-04-19 16:09:26 +0000449 usage()
450
Tim Peters661e4922002-04-20 02:39:44 +0000451 try:
Tim Peters52cfa332002-04-19 16:09:26 +0000452 optlist, args = getopt.getopt(args, 'ckpv:')
Tim Peters661e4922002-04-20 02:39:44 +0000453 except getopt.error, msg:
Tim Peters52cfa332002-04-19 16:09:26 +0000454 print msg
455 usage()
456
Tim Peters661e4922002-04-20 02:39:44 +0000457 if not args or len(args) > 1:
Tim Peters52cfa332002-04-19 16:09:26 +0000458 usage()
459 arch = args[0]
460
461 version = None
462 for opt in optlist:
463 if opt[0] == '-v':
464 version = opt[1]
465 break
466 if not version:
467 usage()
468
Tim Petersd9a10502002-04-20 03:25:02 +0000469 library = supported_libraries[version]
Tim Peters52cfa332002-04-19 16:09:26 +0000470
Tim Peters661e4922002-04-20 02:39:44 +0000471 if not (('-p','') in optlist):
Tim Peters4f109c12002-04-19 18:41:46 +0000472 fname = arch + '.stp'
473 f = openfile(fname)
474 print "Building stoplist", fname, "..."
475 words = stop_list.split()
476 words.sort()
477 for word in words:
478 print >> f, word
479 f.close()
480
Tim Peters52cfa332002-04-19 16:09:26 +0000481 f = openfile(arch + '.hhp')
482 print "Building Project..."
483 do_project(library, f, arch, version)
484 if version == '2.0.0':
485 for image in os.listdir('icons'):
486 f.write('icons'+ '\\' + image + '\n')
487
488 f.close()
489
Tim Peters661e4922002-04-20 02:39:44 +0000490 if not (('-c','') in optlist):
Tim Peters52cfa332002-04-19 16:09:26 +0000491 f = openfile(arch + '.hhc')
492 print "Building Table of Content..."
493 do_content(library, version, f)
494 f.close()
495
Tim Peters661e4922002-04-20 02:39:44 +0000496 if not (('-k','') in optlist):
Tim Peters52cfa332002-04-19 16:09:26 +0000497 f = openfile(arch + '.hhk')
498 print "Building Index..."
499 do_index(library, f)
500 f.close()
501
Tim Peters661e4922002-04-20 02:39:44 +0000502if __name__ == '__main__':
Tim Peters52cfa332002-04-19 16:09:26 +0000503 do_it()