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
|
|
|
|
import formatter
|
|
|
|
import htmllib
|
|
|
|
import string
|
|
|
|
import getopt
|
|
|
|
|
|
|
|
usage_mode = '''
|
|
|
|
Usage: make_chm.py [-c] [-k] [-p] [-v 1.5[.x]] filename
|
|
|
|
-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-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",\
|
|
|
|
"index.html","index.html",,,,,0x63520,220,0x384e,[271,372,740,718],,,,,,,0
|
2002-04-19 16:09:26 +00:00
|
|
|
|
|
|
|
[FILES]
|
|
|
|
'''
|
|
|
|
|
|
|
|
contents_header = '''
|
|
|
|
<OBJECT type="text/site properties">
|
|
|
|
<param name="Window Styles" value="0x801227">
|
2002-04-19 16:46:43 +00:00
|
|
|
<param name="ImageType" value="Folder">
|
2002-04-19 16:09:26 +00:00
|
|
|
</OBJECT>
|
|
|
|
<UL>
|
|
|
|
<LI> <OBJECT type="text/sitemap">
|
|
|
|
<param name="Name" value="Python %s Docs">
|
|
|
|
<param name="Local" value="./index.html">
|
|
|
|
</OBJECT>
|
|
|
|
<UL>
|
|
|
|
'''
|
|
|
|
|
|
|
|
contents_footer = '''
|
|
|
|
</UL></UL>
|
|
|
|
'''
|
|
|
|
|
|
|
|
object_sitemap = '''
|
|
|
|
<LI> <OBJECT type="text/sitemap">
|
|
|
|
<param name="Local" value="%s">
|
|
|
|
<param name="Name" value="%s">
|
|
|
|
</OBJECT>
|
|
|
|
'''
|
|
|
|
|
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
|
|
|
|
# language, so not point indexing them even if wanted to.
|
|
|
|
stop_list = '''
|
|
|
|
a an and
|
|
|
|
is
|
|
|
|
near
|
|
|
|
not
|
|
|
|
of
|
|
|
|
or
|
|
|
|
the
|
|
|
|
'''
|
|
|
|
|
2002-04-19 16:09:26 +00:00
|
|
|
# Library Doc list of tuples:
|
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 = {
|
|
|
|
'2.2': ### Beta!!! fix for actual release
|
|
|
|
[
|
|
|
|
('.', 'Global Module Index', 'modindex.html', None, None),
|
2002-04-20 02:07:58 +00:00
|
|
|
('whatsnew', "What's New", 'index.html', 'contents.html', None),
|
2002-04-19 16:09:26 +00:00
|
|
|
('tut','Tutorial','tut.html','node2.html',None),
|
|
|
|
('lib','Library Reference','lib.html','contents.html','genindex.html'),
|
|
|
|
('ref','Language Reference','ref.html','contents.html','genindex.html'),
|
|
|
|
('mac','Macintosh Reference','mac.html','contents.html','genindex.html'),
|
|
|
|
('ext','Extending and Embedding','ext.html','contents.html',None),
|
|
|
|
('api','Python/C API','api.html','contents.html','genindex.html'),
|
|
|
|
('doc','Documenting Python','doc.html','contents.html',None),
|
|
|
|
('inst','Installing Python Modules', 'inst.html', 'index.html', None),
|
|
|
|
('dist','Distributing Python Modules', 'dist.html', 'index.html', None),
|
|
|
|
],
|
|
|
|
|
|
|
|
'2.1.1':
|
|
|
|
[
|
|
|
|
('.', 'Global Module Index', 'modindex.html', None, None),
|
|
|
|
('tut','Tutorial','tut.html','node2.html',None),
|
|
|
|
('lib','Library Reference','lib.html','contents.html','genindex.html'),
|
|
|
|
('ref','Language Reference','ref.html','contents.html','genindex.html'),
|
|
|
|
('mac','Macintosh Reference','mac.html','contents.html','genindex.html'),
|
|
|
|
('ext','Extending and Embedding','ext.html','contents.html',None),
|
|
|
|
('api','Python/C API','api.html','contents.html','genindex.html'),
|
|
|
|
('doc','Documenting Python','doc.html','contents.html',None),
|
|
|
|
('inst','Installing Python Modules', 'inst.html', 'index.html', None),
|
|
|
|
('dist','Distributing Python Modules', 'dist.html', 'index.html', None),
|
|
|
|
],
|
|
|
|
|
|
|
|
'2.0.0':
|
|
|
|
[
|
|
|
|
('.', 'Global Module Index', 'modindex.html', None, None),
|
|
|
|
('tut','Tutorial','tut.html','node2.html',None),
|
|
|
|
('lib','Library Reference','lib.html','contents.html','genindex.html'),
|
|
|
|
('ref','Language Reference','ref.html','contents.html','genindex.html'),
|
|
|
|
('mac','Macintosh Reference','mac.html','contents.html','genindex.html'),
|
|
|
|
('ext','Extending and Embedding','ext.html','contents.html',None),
|
|
|
|
('api','Python/C API','api.html','contents.html','genindex.html'),
|
|
|
|
('doc','Documenting Python','doc.html','contents.html',None),
|
|
|
|
('inst','Installing Python Modules', 'inst.html', 'contents.html', None),
|
|
|
|
('dist','Distributing Python Modules', 'dist.html', 'contents.html', None),
|
|
|
|
],
|
|
|
|
|
|
|
|
# <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':
|
|
|
|
[
|
|
|
|
('tut','Tutorial','tut.html','node2.html',None),
|
|
|
|
('lib','Library Reference','lib.html','contents.html','genindex.html'),
|
|
|
|
('ref','Language Reference','ref.html','contents.html','genindex.html'),
|
|
|
|
('mac','Macintosh Reference','mac.html','contents.html','genindex.html'),
|
|
|
|
('ext','Extending and Embedding','ext.html','contents.html',None),
|
|
|
|
('api','Python/C API','api.html','contents.html','genindex.html'),
|
|
|
|
('doc','Documenting Python','doc.html','contents.html',None)
|
|
|
|
],
|
|
|
|
|
|
|
|
# library for 1.5.1 version:
|
|
|
|
'1.5.1':
|
|
|
|
[
|
|
|
|
('tut','Tutorial','tut.html','contents.html',None),
|
|
|
|
('lib','Library Reference','lib.html','contents.html','genindex.html'),
|
|
|
|
('ref','Language Reference','ref-1.html','ref-2.html','ref-11.html'),
|
|
|
|
('ext','Extending and Embedding','ext.html','contents.html',None),
|
|
|
|
('api','Python/C API','api.html','contents.html','genindex.html')
|
|
|
|
],
|
|
|
|
|
|
|
|
# library for 1.5 version:
|
|
|
|
'1.5':
|
|
|
|
[
|
|
|
|
('tut','Tutorial','tut.html','node1.html',None),
|
|
|
|
('lib','Library Reference','lib.html','node1.html','node268.html'),
|
|
|
|
('ref','Language Reference','ref-1.html','ref-2.html','ref-11.html'),
|
|
|
|
('ext','Extending and Embedding','ext.html','node1.html',None),
|
|
|
|
('api','Python/C API','api.html','node1.html','node48.html')
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2002-04-20 02:39:44 +00:00
|
|
|
class AlmostNullWriter(formatter.NullWriter):
|
2002-04-19 16:09:26 +00:00
|
|
|
savedliteral = ''
|
|
|
|
|
2002-04-20 02:39:44 +00:00
|
|
|
def send_flowing_data(self, data):
|
2002-04-19 16:09:26 +00:00
|
|
|
# need the text tag for later
|
|
|
|
datastriped = string.strip(data)
|
|
|
|
if self.savedliteral == '':
|
|
|
|
self.savedliteral = datastriped
|
|
|
|
else:
|
|
|
|
self.savedliteral = string.strip(self.savedliteral +
|
|
|
|
' ' + datastriped)
|
|
|
|
|
|
|
|
|
2002-04-20 02:39:44 +00:00
|
|
|
class HelpHtmlParser(htmllib.HTMLParser):
|
2002-04-19 16:09:26 +00:00
|
|
|
indent = 0 # number of tabs for pritty printing of files
|
|
|
|
ft = None # output file
|
|
|
|
path = None # relative path
|
|
|
|
proc = 0 # if true I process, if false I skip
|
|
|
|
# (some headers, footers, etc.)
|
|
|
|
|
2002-04-20 02:39:44 +00:00
|
|
|
def begin_group(self):
|
|
|
|
if not self.proc:
|
2002-04-19 16:09:26 +00:00
|
|
|
# first level, start processing
|
|
|
|
self.proc = 1
|
|
|
|
self.indent = self.indent + 1
|
|
|
|
|
2002-04-20 02:39:44 +00:00
|
|
|
def finnish_group(self):
|
2002-04-19 16:09:26 +00:00
|
|
|
self.indent = self.indent - 1
|
2002-04-20 02:39:44 +00:00
|
|
|
if self.proc and self.indent == 0:
|
2002-04-19 16:09:26 +00:00
|
|
|
# if processing and back to root, then stop
|
|
|
|
self.proc = 0
|
|
|
|
|
2002-04-20 02:39:44 +00:00
|
|
|
def anchor_bgn(self, href, name, type):
|
|
|
|
if self.proc:
|
2002-04-19 16:09:26 +00:00
|
|
|
self.formatter.writer.savedliteral = ''
|
|
|
|
self.ft.write('<OBJECT type="text/sitemap">\n')
|
|
|
|
self.ft.write('\t' * self.indent + \
|
|
|
|
'\t<param name="Local" value="' + self.path + \
|
|
|
|
'/' + href + '">\n')
|
|
|
|
|
2002-04-20 02:39:44 +00:00
|
|
|
def anchor_end(self):
|
|
|
|
if self.proc:
|
2002-04-19 16:09:26 +00:00
|
|
|
self.ft.write('\t' * self.indent + \
|
|
|
|
'\t<param name="Name" value="' + \
|
|
|
|
self.formatter.writer.savedliteral + '">\n')
|
2002-04-20 02:39:44 +00:00
|
|
|
self.ft.write('\t' * self.indent + '\t</OBJECT>\n')
|
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-19 16:09:26 +00:00
|
|
|
self.finnish_group()
|
|
|
|
|
2002-04-20 02:39:44 +00:00
|
|
|
def do_dt(self, atr_val):
|
2002-04-19 16:09:26 +00:00
|
|
|
# no trailing newline on pourpose!
|
|
|
|
self.ft.write("\t" * self.indent + "<LI>")
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
self.ft.write('\t' * self.indent + '<UL>\n')
|
|
|
|
|
2002-04-20 02:39:44 +00:00
|
|
|
def end_dl(self):
|
2002-04-19 16:09:26 +00:00
|
|
|
self.finnish_group()
|
|
|
|
self.ft.write('</UL>\n')
|
|
|
|
|
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()
|
|
|
|
self.ft.write('\t' * self.indent + '<UL>\n')
|
|
|
|
|
2002-04-20 02:39:44 +00:00
|
|
|
def end_ul(self):
|
2002-04-19 16:09:26 +00:00
|
|
|
self.finnish_group()
|
|
|
|
self.ft.write('</UL>\n')
|
|
|
|
|
2002-04-20 02:39:44 +00:00
|
|
|
def do_li(self, atr_val):
|
2002-04-19 16:09:26 +00:00
|
|
|
# no trailing newline on pourpose!
|
|
|
|
self.ft.write("\t" * self.indent + "<LI>")
|
|
|
|
|
|
|
|
|
2002-04-20 02:39:44 +00:00
|
|
|
def index(path, archivo, output):
|
2002-04-19 16:09:26 +00:00
|
|
|
f = formatter.AbstractFormatter(AlmostNullWriter())
|
|
|
|
parser = IdxHlpHtmlParser(f)
|
|
|
|
parser.path = path
|
|
|
|
parser.ft = output
|
|
|
|
fil = path + '/' + archivo
|
|
|
|
parser.feed(open(fil).read())
|
|
|
|
parser.close()
|
|
|
|
|
|
|
|
|
2002-04-20 02:39:44 +00:00
|
|
|
def content(path, archivo, output):
|
2002-04-19 16:09:26 +00:00
|
|
|
f = formatter.AbstractFormatter(AlmostNullWriter())
|
|
|
|
parser = TocHlpHtmlParser(f)
|
|
|
|
parser.path = path
|
|
|
|
parser.ft = output
|
|
|
|
fil = path + '/' + archivo
|
|
|
|
parser.feed(open(fil).read())
|
|
|
|
parser.close()
|
|
|
|
|
|
|
|
|
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-19 16:09:26 +00:00
|
|
|
print '\t', book[2]
|
2002-04-20 02:39:44 +00:00
|
|
|
if book[4]:
|
2002-04-19 16:09:26 +00:00
|
|
|
index(book[0], book[4], output)
|
|
|
|
output.write('</UL>\n')
|
|
|
|
|
|
|
|
|
2002-04-20 02:39:44 +00:00
|
|
|
def do_content(library, version, output):
|
2002-04-19 16:09:26 +00:00
|
|
|
output.write(contents_header % version)
|
2002-04-20 02:39:44 +00:00
|
|
|
for book in library:
|
2002-04-19 16:09:26 +00:00
|
|
|
print '\t', book[2]
|
|
|
|
output.write(object_sitemap % (book[0]+"/"+book[2], book[1]))
|
2002-04-20 02:39:44 +00:00
|
|
|
if book[3]:
|
2002-04-19 16:09:26 +00:00
|
|
|
content(book[0], book[3], output)
|
|
|
|
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 02:37:07 +00:00
|
|
|
for book in library:
|
|
|
|
directory = book[0]
|
|
|
|
path = directory + '\\%s\n'
|
|
|
|
for page in os.listdir(directory):
|
|
|
|
if page.endswith('.html') or page.endswith('.css'):
|
|
|
|
output.write(path % page)
|
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()
|
|
|
|
|
|
|
|
library = supported_libraries[ version ]
|
|
|
|
|
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()
|