| 
									
										
										
										
											2002-04-19 18:41:46 +00:00
										 |  |  | """
 | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |     Makes the necesary files to convert from plain html of | 
					
						
							|  |  |  |     Python 1.5 and 1.5.x Documentation to | 
					
						
							|  |  |  |     Microsoft HTML Help format version 1.1 | 
					
						
							|  |  |  |     Doesn't change the html's docs. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     by hernan.foffani@iname.com | 
					
						
							|  |  |  |     no copyright and no responsabilities. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     modified by Dale Nagata for Python 1.5.2 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Renamed from make_chm.py to prechm.py, and checked into the Python | 
					
						
							|  |  |  |     project, 19-Apr-2002 by Tim Peters.  Assorted modifications by Tim | 
					
						
							|  |  |  |     and Fred Drake.  Obtained from Robin Dunn's .chm packaging of the | 
					
						
							|  |  |  |     Python 2.2 docs, at <http://alldunn.com/python/>. | 
					
						
							| 
									
										
										
										
											2002-04-19 18:41:46 +00:00
										 |  |  | """
 | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | import os | 
					
						
							| 
									
										
										
										
											2002-04-20 08:36:42 +00:00
										 |  |  | from formatter import NullWriter, AbstractFormatter | 
					
						
							|  |  |  | from htmllib import HTMLParser | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | import getopt | 
					
						
							| 
									
										
										
										
											2002-04-20 20:26:26 +00:00
										 |  |  | import cgi | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | usage_mode = '''
 | 
					
						
							| 
									
										
										
										
											2004-02-08 20:05:40 +00:00
										 |  |  | Usage: prechm.py [-c] [-k] [-p] [-v 1.5[.x]] filename | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |     -c: does not build filename.hhc (Table of Contents) | 
					
						
							|  |  |  |     -k: does not build filename.hhk (Index) | 
					
						
							|  |  |  |     -p: does not build filename.hhp (Project File) | 
					
						
							|  |  |  |     -v 1.5[.x]: makes help for the python 1.5[.x] docs | 
					
						
							|  |  |  |         (default is python 1.5.2 docs) | 
					
						
							|  |  |  | '''
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-19 18:07:52 +00:00
										 |  |  | # Project file (*.hhp) template.  'arch' is the file basename (like | 
					
						
							|  |  |  | # the pythlp in pythlp.hhp); 'version' is the doc version number (like | 
					
						
							|  |  |  | # the 2.2 in Python 2.2). | 
					
						
							|  |  |  | # The magical numbers in the long line under [WINDOWS] set most of the | 
					
						
							|  |  |  | # user-visible features (visible buttons, tabs, etc). | 
					
						
							| 
									
										
										
										
											2002-04-21 02:01:01 +00:00
										 |  |  | # About 0x10384e:  This defines the buttons in the help viewer.  The | 
					
						
							|  |  |  | # following defns are taken from htmlhelp.h.  Not all possibilities | 
					
						
							|  |  |  | # actually work, and not all those that work are available from the Help | 
					
						
							|  |  |  | # Workshop GUI.  In particular, the Zoom/Font button works and is not | 
					
						
							|  |  |  | # available from the GUI.  The ones we're using are marked with 'x': | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #    0x000002   Hide/Show   x | 
					
						
							|  |  |  | #    0x000004   Back        x | 
					
						
							|  |  |  | #    0x000008   Forward     x | 
					
						
							|  |  |  | #    0x000010   Stop | 
					
						
							|  |  |  | #    0x000020   Refresh | 
					
						
							|  |  |  | #    0x000040   Home        x | 
					
						
							|  |  |  | #    0x000080   Forward | 
					
						
							|  |  |  | #    0x000100   Back | 
					
						
							|  |  |  | #    0x000200   Notes | 
					
						
							|  |  |  | #    0x000400   Contents | 
					
						
							|  |  |  | #    0x000800   Locate      x | 
					
						
							|  |  |  | #    0x001000   Options     x | 
					
						
							|  |  |  | #    0x002000   Print       x | 
					
						
							|  |  |  | #    0x004000   Index | 
					
						
							|  |  |  | #    0x008000   Search | 
					
						
							|  |  |  | #    0x010000   History | 
					
						
							|  |  |  | #    0x020000   Favorites | 
					
						
							|  |  |  | #    0x040000   Jump 1 | 
					
						
							|  |  |  | #    0x080000   Jump 2 | 
					
						
							|  |  |  | #    0x100000   Zoom/Font   x | 
					
						
							|  |  |  | #    0x200000   TOC Next | 
					
						
							|  |  |  | #    0x400000   TOC Prev | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | project_template = '''
 | 
					
						
							|  |  |  | [OPTIONS] | 
					
						
							| 
									
										
										
										
											2002-04-19 18:07:52 +00:00
										 |  |  | Compiled file=%(arch)s.chm | 
					
						
							|  |  |  | Contents file=%(arch)s.hhc | 
					
						
							|  |  |  | Default Window=%(arch)s | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | Default topic=index.html | 
					
						
							|  |  |  | Display compile progress=No | 
					
						
							| 
									
										
										
										
											2002-04-19 18:41:46 +00:00
										 |  |  | Full text search stop list file=%(arch)s.stp | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | Full-text search=Yes | 
					
						
							| 
									
										
										
										
											2002-04-19 18:07:52 +00:00
										 |  |  | Index file=%(arch)s.hhk | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | Language=0x409 | 
					
						
							| 
									
										
										
										
											2002-04-19 18:07:52 +00:00
										 |  |  | Title=Python %(version)s Documentation | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | [WINDOWS] | 
					
						
							| 
									
										
										
										
											2002-04-19 18:07:52 +00:00
										 |  |  | %(arch)s="Python %(version)s Documentation","%(arch)s.hhc","%(arch)s.hhk",\ | 
					
						
							| 
									
										
										
										
											2003-09-23 20:50:47 +00:00
										 |  |  | "index.html","index.html",,,,,0x63520,220,0x10384e,[0,0,1024,768],,,,,,,0 | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | [FILES] | 
					
						
							|  |  |  | '''
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 20:26:26 +00:00
										 |  |  | contents_header = '''\
 | 
					
						
							|  |  |  | <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 
					
						
							|  |  |  | <HTML> | 
					
						
							|  |  |  | <HEAD> | 
					
						
							|  |  |  | <meta name="GENERATOR" content="Microsoft® HTML Help Workshop 4.1"> | 
					
						
							|  |  |  | <!-- Sitemap 1.0 --> | 
					
						
							|  |  |  | </HEAD><BODY> | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | <OBJECT type="text/site properties"> | 
					
						
							| 
									
										
										
										
											2004-02-08 19:24:18 +00:00
										 |  |  |         <param name="Window Styles" value="0x801227"> | 
					
						
							|  |  |  |         <param name="ImageType" value="Folder"> | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | </OBJECT> | 
					
						
							|  |  |  | <UL> | 
					
						
							|  |  |  | '''
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 20:26:26 +00:00
										 |  |  | contents_footer = '''\
 | 
					
						
							| 
									
										
										
										
											2002-04-20 21:34:34 +00:00
										 |  |  | </UL></BODY></HTML> | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | '''
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 20:26:26 +00:00
										 |  |  | object_sitemap = '''\
 | 
					
						
							|  |  |  | <OBJECT type="text/sitemap"> | 
					
						
							|  |  |  |     <param name="Name" value="%s"> | 
					
						
							|  |  |  |     <param name="Local" value="%s"> | 
					
						
							|  |  |  | </OBJECT> | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | '''
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-19 18:41:46 +00:00
										 |  |  | # List of words the full text search facility shouldn't index.  This | 
					
						
							|  |  |  | # becomes file ARCH.stp.  Note that this list must be pretty small! | 
					
						
							|  |  |  | # Different versions of the MS docs claim the file has a maximum size of | 
					
						
							|  |  |  | # 256 or 512 bytes (including \r\n at the end of each line). | 
					
						
							|  |  |  | # Note that "and", "or", "not" and "near" are operators in the search | 
					
						
							| 
									
										
										
										
											2002-04-20 02:56:20 +00:00
										 |  |  | # language, so no point indexing them even if we wanted to. | 
					
						
							| 
									
										
										
										
											2002-04-19 18:41:46 +00:00
										 |  |  | stop_list = '''
 | 
					
						
							| 
									
										
										
										
											2002-05-02 21:59:08 +00:00
										 |  |  | a  and  are  as  at | 
					
						
							|  |  |  | be  but  by | 
					
						
							|  |  |  | for | 
					
						
							|  |  |  | if  in  into  is  it | 
					
						
							|  |  |  | near  no  not | 
					
						
							|  |  |  | of  on  or | 
					
						
							|  |  |  | such | 
					
						
							|  |  |  | that  the  their  then  there  these  they  this  to | 
					
						
							|  |  |  | was  will  with | 
					
						
							| 
									
										
										
										
											2002-04-19 18:41:46 +00:00
										 |  |  | '''
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 03:25:02 +00:00
										 |  |  | # s is a string or None.  If None or empty, return None.  Else tack '.html' | 
					
						
							|  |  |  | # on to the end, unless it's already there. | 
					
						
							|  |  |  | def addhtml(s): | 
					
						
							|  |  |  |     if s: | 
					
						
							|  |  |  |         if not s.endswith('.html'): | 
					
						
							|  |  |  |             s += '.html' | 
					
						
							|  |  |  |     return s | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Convenience class to hold info about "a book" in HTMLHelp terms == a doc | 
					
						
							|  |  |  | # directory in Python terms. | 
					
						
							|  |  |  | class Book: | 
					
						
							|  |  |  |     def __init__(self, directory, title, firstpage, | 
					
						
							|  |  |  |                  contentpage=None, indexpage=None): | 
					
						
							|  |  |  |         self.directory   = directory | 
					
						
							|  |  |  |         self.title       = title | 
					
						
							|  |  |  |         self.firstpage   = addhtml(firstpage) | 
					
						
							|  |  |  |         self.contentpage = addhtml(contentpage) | 
					
						
							|  |  |  |         self.indexpage   = addhtml(indexpage) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Library Doc list of books: | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  | # each 'book' : (Dir, Title, First page, Content page, Index page) | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | supported_libraries = { | 
					
						
							| 
									
										
										
										
											2003-09-23 20:50:47 +00:00
										 |  |  |     '2.4': | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         Book('.', 'Main page', 'index'), | 
					
						
							|  |  |  |         Book('.', 'Global Module Index', 'modindex'), | 
					
						
							|  |  |  |         Book('whatsnew', "What's New", 'index', 'contents'), | 
					
						
							|  |  |  |         Book('tut','Tutorial','tut','node2'), | 
					
						
							|  |  |  |         Book('lib','Library Reference','lib','contents','genindex'), | 
					
						
							|  |  |  |         Book('ref','Language Reference','ref','contents','genindex'), | 
					
						
							|  |  |  |         Book('mac','Macintosh Reference','mac','contents','genindex'), | 
					
						
							|  |  |  |         Book('ext','Extending and Embedding','ext','contents'), | 
					
						
							|  |  |  |         Book('api','Python/C API','api','contents','genindex'), | 
					
						
							|  |  |  |         Book('doc','Documenting Python','doc','contents'), | 
					
						
							|  |  |  |         Book('inst','Installing Python Modules', 'inst', 'index'), | 
					
						
							|  |  |  |         Book('dist','Distributing Python Modules', 'dist', 'index'), | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     '2.3': | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         Book('.', 'Main page', 'index'), | 
					
						
							|  |  |  |         Book('.', 'Global Module Index', 'modindex'), | 
					
						
							|  |  |  |         Book('whatsnew', "What's New", 'index', 'contents'), | 
					
						
							|  |  |  |         Book('tut','Tutorial','tut','node2'), | 
					
						
							|  |  |  |         Book('lib','Library Reference','lib','contents','genindex'), | 
					
						
							|  |  |  |         Book('ref','Language Reference','ref','contents','genindex'), | 
					
						
							|  |  |  |         Book('mac','Macintosh Reference','mac','contents','genindex'), | 
					
						
							|  |  |  |         Book('ext','Extending and Embedding','ext','contents'), | 
					
						
							|  |  |  |         Book('api','Python/C API','api','contents','genindex'), | 
					
						
							|  |  |  |         Book('doc','Documenting Python','doc','contents'), | 
					
						
							|  |  |  |         Book('inst','Installing Python Modules', 'inst', 'index'), | 
					
						
							|  |  |  |         Book('dist','Distributing Python Modules', 'dist', 'index'), | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 21:34:34 +00:00
										 |  |  |     '2.2': | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |     [ | 
					
						
							| 
									
										
										
										
											2002-04-20 21:34:34 +00:00
										 |  |  |         Book('.', 'Main page', 'index'), | 
					
						
							| 
									
										
										
										
											2002-04-20 03:25:02 +00:00
										 |  |  |         Book('.', 'Global Module Index', 'modindex'), | 
					
						
							|  |  |  |         Book('whatsnew', "What's New", 'index', 'contents'), | 
					
						
							|  |  |  |         Book('tut','Tutorial','tut','node2'), | 
					
						
							|  |  |  |         Book('lib','Library Reference','lib','contents','genindex'), | 
					
						
							|  |  |  |         Book('ref','Language Reference','ref','contents','genindex'), | 
					
						
							|  |  |  |         Book('mac','Macintosh Reference','mac','contents','genindex'), | 
					
						
							|  |  |  |         Book('ext','Extending and Embedding','ext','contents'), | 
					
						
							|  |  |  |         Book('api','Python/C API','api','contents','genindex'), | 
					
						
							|  |  |  |         Book('doc','Documenting Python','doc','contents'), | 
					
						
							|  |  |  |         Book('inst','Installing Python Modules', 'inst', 'index'), | 
					
						
							|  |  |  |         Book('dist','Distributing Python Modules', 'dist', 'index'), | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |     ], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     '2.1.1': | 
					
						
							|  |  |  |     [ | 
					
						
							| 
									
										
										
										
											2002-04-20 21:34:34 +00:00
										 |  |  |         Book('.', 'Main page', 'index'), | 
					
						
							| 
									
										
										
										
											2002-04-20 03:25:02 +00:00
										 |  |  |         Book('.', 'Global Module Index', 'modindex'), | 
					
						
							|  |  |  |         Book('tut','Tutorial','tut','node2'), | 
					
						
							|  |  |  |         Book('lib','Library Reference','lib','contents','genindex'), | 
					
						
							|  |  |  |         Book('ref','Language Reference','ref','contents','genindex'), | 
					
						
							|  |  |  |         Book('mac','Macintosh Reference','mac','contents','genindex'), | 
					
						
							|  |  |  |         Book('ext','Extending and Embedding','ext','contents'), | 
					
						
							|  |  |  |         Book('api','Python/C API','api','contents','genindex'), | 
					
						
							|  |  |  |         Book('doc','Documenting Python','doc','contents'), | 
					
						
							|  |  |  |         Book('inst','Installing Python Modules', 'inst', 'index'), | 
					
						
							|  |  |  |         Book('dist','Distributing Python Modules', 'dist', 'index'), | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |     ], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     '2.0.0': | 
					
						
							|  |  |  |     [ | 
					
						
							| 
									
										
										
										
											2002-04-20 03:25:02 +00:00
										 |  |  |         Book('.', 'Global Module Index', 'modindex'), | 
					
						
							|  |  |  |         Book('tut','Tutorial','tut','node2'), | 
					
						
							|  |  |  |         Book('lib','Library Reference','lib','contents','genindex'), | 
					
						
							|  |  |  |         Book('ref','Language Reference','ref','contents','genindex'), | 
					
						
							|  |  |  |         Book('mac','Macintosh Reference','mac','contents','genindex'), | 
					
						
							|  |  |  |         Book('ext','Extending and Embedding','ext','contents'), | 
					
						
							|  |  |  |         Book('api','Python/C API','api','contents','genindex'), | 
					
						
							|  |  |  |         Book('doc','Documenting Python','doc','contents'), | 
					
						
							|  |  |  |         Book('inst','Installing Python Modules', 'inst', 'contents'), | 
					
						
							|  |  |  |         Book('dist','Distributing Python Modules', 'dist', 'contents'), | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |     ], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # <dnagata@creo.com> Apr 17/99: library for 1.5.2 version: | 
					
						
							|  |  |  |     # <hernan.foffani@iname.com> May 01/99: library for 1.5.2 (04/30/99): | 
					
						
							|  |  |  |     '1.5.2': | 
					
						
							|  |  |  |     [ | 
					
						
							| 
									
										
										
										
											2002-04-20 03:25:02 +00:00
										 |  |  |         Book('tut','Tutorial','tut','node2'), | 
					
						
							|  |  |  |         Book('lib','Library Reference','lib','contents','genindex'), | 
					
						
							|  |  |  |         Book('ref','Language Reference','ref','contents','genindex'), | 
					
						
							|  |  |  |         Book('mac','Macintosh Reference','mac','contents','genindex'), | 
					
						
							|  |  |  |         Book('ext','Extending and Embedding','ext','contents'), | 
					
						
							|  |  |  |         Book('api','Python/C API','api','contents','genindex'), | 
					
						
							|  |  |  |         Book('doc','Documenting Python','doc','contents') | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |     ], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # library for 1.5.1 version: | 
					
						
							|  |  |  |     '1.5.1': | 
					
						
							|  |  |  |     [ | 
					
						
							| 
									
										
										
										
											2002-04-20 03:25:02 +00:00
										 |  |  |         Book('tut','Tutorial','tut','contents'), | 
					
						
							|  |  |  |         Book('lib','Library Reference','lib','contents','genindex'), | 
					
						
							|  |  |  |         Book('ref','Language Reference','ref-1','ref-2','ref-11'), | 
					
						
							|  |  |  |         Book('ext','Extending and Embedding','ext','contents'), | 
					
						
							|  |  |  |         Book('api','Python/C API','api','contents','genindex') | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |     ], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # library for 1.5 version: | 
					
						
							|  |  |  |     '1.5': | 
					
						
							|  |  |  |     [ | 
					
						
							| 
									
										
										
										
											2002-04-20 03:25:02 +00:00
										 |  |  |         Book('tut','Tutorial','tut','node1'), | 
					
						
							|  |  |  |         Book('lib','Library Reference','lib','node1','node268'), | 
					
						
							|  |  |  |         Book('ref','Language Reference','ref-1','ref-2','ref-11'), | 
					
						
							|  |  |  |         Book('ext','Extending and Embedding','ext','node1'), | 
					
						
							|  |  |  |         Book('api','Python/C API','api','node1','node48') | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |     ] | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 08:36:42 +00:00
										 |  |  | # AlmostNullWriter doesn't print anything; it just arranges to save the | 
					
						
							|  |  |  | # text sent to send_flowing_data().  This is used to capture the text | 
					
						
							|  |  |  | # between an anchor begin/end pair, e.g. for TOC entries. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class AlmostNullWriter(NullWriter): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __init__(self): | 
					
						
							|  |  |  |         NullWriter.__init__(self) | 
					
						
							|  |  |  |         self.saved_clear() | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     def send_flowing_data(self, data): | 
					
						
							| 
									
										
										
										
											2002-04-20 08:36:42 +00:00
										 |  |  |         stripped = data.strip() | 
					
						
							|  |  |  |         if stripped:    # don't bother to save runs of whitespace | 
					
						
							|  |  |  |             self.saved.append(stripped) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Forget all saved text. | 
					
						
							|  |  |  |     def saved_clear(self): | 
					
						
							|  |  |  |         self.saved = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Return all saved text as a string. | 
					
						
							|  |  |  |     def saved_get(self): | 
					
						
							|  |  |  |         return ' '.join(self.saved) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class HelpHtmlParser(HTMLParser): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __init__(self, formatter, path, output): | 
					
						
							|  |  |  |         HTMLParser.__init__(self, formatter) | 
					
						
							|  |  |  |         self.path = path    # relative path | 
					
						
							|  |  |  |         self.ft = output    # output file | 
					
						
							|  |  |  |         self.indent = 0     # number of tabs for pretty printing of files | 
					
						
							|  |  |  |         self.proc = False   # True when actively processing, else False | 
					
						
							|  |  |  |                             # (headers, footers, etc) | 
					
						
							| 
									
										
										
										
											2002-04-20 20:26:26 +00:00
										 |  |  |         # XXX This shouldn't need to be a stack -- anchors shouldn't nest. | 
					
						
							|  |  |  |         # XXX See SF bug <http://www.python.org/sf/546579>. | 
					
						
							|  |  |  |         self.hrefstack = [] # stack of hrefs from anchor begins | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     def begin_group(self): | 
					
						
							| 
									
										
										
										
											2002-04-20 08:36:42 +00:00
										 |  |  |         self.indent += 1 | 
					
						
							|  |  |  |         self.proc = True | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 08:36:42 +00:00
										 |  |  |     def finish_group(self): | 
					
						
							|  |  |  |         self.indent -= 1 | 
					
						
							|  |  |  |         # stop processing when back to top level | 
					
						
							|  |  |  |         self.proc = self.indent > 0 | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     def anchor_bgn(self, href, name, type): | 
					
						
							|  |  |  |         if self.proc: | 
					
						
							| 
									
										
										
										
											2002-04-20 20:26:26 +00:00
										 |  |  |             # XXX See SF bug <http://www.python.org/sf/546579>. | 
					
						
							| 
									
										
										
										
											2002-04-21 04:44:11 +00:00
										 |  |  |             # XXX index.html for the 2.2.1 language reference manual contains | 
					
						
							| 
									
										
										
										
											2002-04-20 20:26:26 +00:00
										 |  |  |             # XXX nested <a></a> tags in the entry for the section on blank | 
					
						
							|  |  |  |             # XXX lines.  We want to ignore the nested part completely. | 
					
						
							|  |  |  |             if len(self.hrefstack) == 0: | 
					
						
							| 
									
										
										
										
											2002-04-21 04:44:11 +00:00
										 |  |  |                 self.saved_clear() | 
					
						
							|  |  |  |                 self.hrefstack.append(href) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def anchor_end(self): | 
					
						
							|  |  |  |         if self.proc: | 
					
						
							|  |  |  |             # XXX See XXX above. | 
					
						
							|  |  |  |             if self.hrefstack: | 
					
						
							|  |  |  |                 title = cgi.escape(self.saved_get(), True) | 
					
						
							|  |  |  |                 path = self.path + '/' + self.hrefstack.pop() | 
					
						
							| 
									
										
										
										
											2002-04-20 20:26:26 +00:00
										 |  |  |                 self.tab(object_sitemap % (title, path)) | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     def start_dl(self, atr_val): | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |         self.begin_group() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     def end_dl(self): | 
					
						
							| 
									
										
										
										
											2002-04-20 08:36:42 +00:00
										 |  |  |         self.finish_group() | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     def do_dt(self, atr_val): | 
					
						
							| 
									
										
										
										
											2002-04-20 08:36:42 +00:00
										 |  |  |         # no trailing newline on purpose! | 
					
						
							|  |  |  |         self.tab("<LI>") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Write text to output file. | 
					
						
							|  |  |  |     def write(self, text): | 
					
						
							|  |  |  |         self.ft.write(text) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Write text to output file after indenting by self.indent tabs. | 
					
						
							|  |  |  |     def tab(self, text=''): | 
					
						
							|  |  |  |         self.write('\t' * self.indent) | 
					
						
							|  |  |  |         if text: | 
					
						
							|  |  |  |             self.write(text) | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 08:36:42 +00:00
										 |  |  |     # Forget all saved text. | 
					
						
							|  |  |  |     def saved_clear(self): | 
					
						
							|  |  |  |         self.formatter.writer.saved_clear() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Return all saved text as a string. | 
					
						
							|  |  |  |     def saved_get(self): | 
					
						
							|  |  |  |         return self.formatter.writer.saved_get() | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  | class IdxHlpHtmlParser(HelpHtmlParser): | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |     # nothing special here, seems enough with parent class | 
					
						
							|  |  |  |     pass | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  | class TocHlpHtmlParser(HelpHtmlParser): | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     def start_dl(self, atr_val): | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |         self.begin_group() | 
					
						
							| 
									
										
										
										
											2002-04-20 08:36:42 +00:00
										 |  |  |         self.tab('<UL>\n') | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     def end_dl(self): | 
					
						
							| 
									
										
										
										
											2002-04-20 08:36:42 +00:00
										 |  |  |         self.finish_group() | 
					
						
							|  |  |  |         self.tab('</UL>\n') | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     def start_ul(self, atr_val): | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |         self.begin_group() | 
					
						
							| 
									
										
										
										
											2002-04-20 08:36:42 +00:00
										 |  |  |         self.tab('<UL>\n') | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     def end_ul(self): | 
					
						
							| 
									
										
										
										
											2002-04-20 08:36:42 +00:00
										 |  |  |         self.finish_group() | 
					
						
							|  |  |  |         self.tab('</UL>\n') | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     def do_li(self, atr_val): | 
					
						
							| 
									
										
										
										
											2002-04-20 08:36:42 +00:00
										 |  |  |         # no trailing newline on purpose! | 
					
						
							|  |  |  |         self.tab("<LI>") | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 03:25:02 +00:00
										 |  |  | def index(path, indexpage, output): | 
					
						
							| 
									
										
										
										
											2002-04-20 08:36:42 +00:00
										 |  |  |     parser = IdxHlpHtmlParser(AbstractFormatter(AlmostNullWriter()), | 
					
						
							|  |  |  |                               path, output) | 
					
						
							| 
									
										
										
										
											2002-04-20 03:25:02 +00:00
										 |  |  |     f = open(path + '/' + indexpage) | 
					
						
							|  |  |  |     parser.feed(f.read()) | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |     parser.close() | 
					
						
							| 
									
										
										
										
											2002-04-20 03:25:02 +00:00
										 |  |  |     f.close() | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 03:25:02 +00:00
										 |  |  | def content(path, contentpage, output): | 
					
						
							| 
									
										
										
										
											2002-04-20 08:36:42 +00:00
										 |  |  |     parser = TocHlpHtmlParser(AbstractFormatter(AlmostNullWriter()), | 
					
						
							|  |  |  |                               path, output) | 
					
						
							| 
									
										
										
										
											2002-04-20 03:25:02 +00:00
										 |  |  |     f = open(path + '/' + contentpage) | 
					
						
							|  |  |  |     parser.feed(f.read()) | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |     parser.close() | 
					
						
							| 
									
										
										
										
											2002-04-20 03:25:02 +00:00
										 |  |  |     f.close() | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  | def do_index(library, output): | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |     output.write('<UL>\n') | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     for book in library: | 
					
						
							| 
									
										
										
										
											2002-04-20 03:25:02 +00:00
										 |  |  |         print '\t', book.title, '-', book.indexpage | 
					
						
							|  |  |  |         if book.indexpage: | 
					
						
							|  |  |  |             index(book.directory, book.indexpage, output) | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |     output.write('</UL>\n') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  | def do_content(library, version, output): | 
					
						
							| 
									
										
										
										
											2002-04-20 21:34:34 +00:00
										 |  |  |     output.write(contents_header) | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     for book in library: | 
					
						
							| 
									
										
										
										
											2002-04-20 03:25:02 +00:00
										 |  |  |         print '\t', book.title, '-', book.firstpage | 
					
						
							| 
									
										
										
										
											2002-04-20 20:26:26 +00:00
										 |  |  |         path = book.directory + "/" + book.firstpage | 
					
						
							|  |  |  |         output.write('<LI>') | 
					
						
							|  |  |  |         output.write(object_sitemap % (book.title, path)) | 
					
						
							| 
									
										
										
										
											2002-04-20 03:25:02 +00:00
										 |  |  |         if book.contentpage: | 
					
						
							|  |  |  |             content(book.directory, book.contentpage, output) | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |     output.write(contents_footer) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:37:07 +00:00
										 |  |  | # Fill in the [FILES] section of the project (.hhp) file. | 
					
						
							|  |  |  | # 'library' is the list of directory description tuples from | 
					
						
							|  |  |  | # supported_libraries for the version of the docs getting generated. | 
					
						
							|  |  |  | def do_project(library, output, arch, version): | 
					
						
							| 
									
										
										
										
											2002-04-19 18:07:52 +00:00
										 |  |  |     output.write(project_template % locals()) | 
					
						
							| 
									
										
										
										
											2002-04-20 21:34:34 +00:00
										 |  |  |     pathseen = {} | 
					
						
							| 
									
										
										
										
											2002-04-20 02:37:07 +00:00
										 |  |  |     for book in library: | 
					
						
							| 
									
										
										
										
											2002-04-20 03:25:02 +00:00
										 |  |  |         directory = book.directory | 
					
						
							| 
									
										
										
										
											2002-04-20 02:37:07 +00:00
										 |  |  |         path = directory + '\\%s\n' | 
					
						
							|  |  |  |         for page in os.listdir(directory): | 
					
						
							|  |  |  |             if page.endswith('.html') or page.endswith('.css'): | 
					
						
							| 
									
										
										
										
											2002-04-20 21:34:34 +00:00
										 |  |  |                 fullpath = path % page | 
					
						
							|  |  |  |                 if fullpath not in pathseen: | 
					
						
							|  |  |  |                     output.write(fullpath) | 
					
						
							|  |  |  |                     pathseen[fullpath] = True | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  | def openfile(file): | 
					
						
							|  |  |  |     try: | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |         p = open(file, "w") | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     except IOError, msg: | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |         print file, ":", msg | 
					
						
							|  |  |  |         sys.exit(1) | 
					
						
							|  |  |  |     return p | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  | def usage(): | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |         print usage_mode | 
					
						
							|  |  |  |         sys.exit(0) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  | def do_it(args = None): | 
					
						
							|  |  |  |     if not args: | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |         args = sys.argv[1:] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     if not args: | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |         usage() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     try: | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |         optlist, args = getopt.getopt(args, 'ckpv:') | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     except getopt.error, msg: | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |         print msg | 
					
						
							|  |  |  |         usage() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     if not args or len(args) > 1: | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |         usage() | 
					
						
							|  |  |  |     arch = args[0] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     version = None | 
					
						
							|  |  |  |     for opt in optlist: | 
					
						
							|  |  |  |         if opt[0] == '-v': | 
					
						
							|  |  |  |             version = opt[1] | 
					
						
							|  |  |  |             break | 
					
						
							|  |  |  |     if not version: | 
					
						
							|  |  |  |         usage() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 03:25:02 +00:00
										 |  |  |     library = supported_libraries[version] | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     if not (('-p','') in optlist): | 
					
						
							| 
									
										
										
										
											2002-04-19 18:41:46 +00:00
										 |  |  |         fname = arch + '.stp' | 
					
						
							|  |  |  |         f = openfile(fname) | 
					
						
							|  |  |  |         print "Building stoplist", fname, "..." | 
					
						
							|  |  |  |         words = stop_list.split() | 
					
						
							|  |  |  |         words.sort() | 
					
						
							|  |  |  |         for word in words: | 
					
						
							|  |  |  |             print >> f, word | 
					
						
							|  |  |  |         f.close() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |         f = openfile(arch + '.hhp') | 
					
						
							|  |  |  |         print "Building Project..." | 
					
						
							|  |  |  |         do_project(library, f, arch, version) | 
					
						
							|  |  |  |         if version == '2.0.0': | 
					
						
							|  |  |  |             for image in os.listdir('icons'): | 
					
						
							|  |  |  |                 f.write('icons'+ '\\' + image + '\n') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         f.close() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     if not (('-c','') in optlist): | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |         f = openfile(arch + '.hhc') | 
					
						
							|  |  |  |         print "Building Table of Content..." | 
					
						
							|  |  |  |         do_content(library, version, f) | 
					
						
							|  |  |  |         f.close() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  |     if not (('-k','') in optlist): | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |         f = openfile(arch + '.hhk') | 
					
						
							|  |  |  |         print "Building Index..." | 
					
						
							|  |  |  |         do_index(library, f) | 
					
						
							|  |  |  |         f.close() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-20 02:39:44 +00:00
										 |  |  | if __name__ == '__main__': | 
					
						
							| 
									
										
										
										
											2002-04-19 16:09:26 +00:00
										 |  |  |     do_it() |