Replaced the fiddly 5-tuples with a new Book convenience class, allowing

to reference fields via names instead of meaningless little integers.
This turned up one case where the wrong little integer was being used,
in informative progress output.  Fixed that too.
This commit is contained in:
Tim Peters 2002-04-20 03:25:02 +00:00
parent 8d62ad7ffd
commit d9a10509ac

View file

@ -97,84 +97,102 @@ or
the the
''' '''
# Library Doc list of tuples: # 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:
# each 'book' : (Dir, Title, First page, Content page, Index page) # each 'book' : (Dir, Title, First page, Content page, Index page)
#
supported_libraries = { supported_libraries = {
'2.2': ### Beta!!! fix for actual release '2.2': ### Beta!!! fix for actual release
[ [
('.', 'Global Module Index', 'modindex.html', None, None), Book('.', 'Global Module Index', 'modindex'),
('whatsnew', "What's New", 'index.html', 'contents.html', None), Book('whatsnew', "What's New", 'index', 'contents'),
('tut','Tutorial','tut.html','node2.html',None), Book('tut','Tutorial','tut','node2'),
('lib','Library Reference','lib.html','contents.html','genindex.html'), Book('lib','Library Reference','lib','contents','genindex'),
('ref','Language Reference','ref.html','contents.html','genindex.html'), Book('ref','Language Reference','ref','contents','genindex'),
('mac','Macintosh Reference','mac.html','contents.html','genindex.html'), Book('mac','Macintosh Reference','mac','contents','genindex'),
('ext','Extending and Embedding','ext.html','contents.html',None), Book('ext','Extending and Embedding','ext','contents'),
('api','Python/C API','api.html','contents.html','genindex.html'), Book('api','Python/C API','api','contents','genindex'),
('doc','Documenting Python','doc.html','contents.html',None), Book('doc','Documenting Python','doc','contents'),
('inst','Installing Python Modules', 'inst.html', 'index.html', None), Book('inst','Installing Python Modules', 'inst', 'index'),
('dist','Distributing Python Modules', 'dist.html', 'index.html', None), Book('dist','Distributing Python Modules', 'dist', 'index'),
], ],
'2.1.1': '2.1.1':
[ [
('.', 'Global Module Index', 'modindex.html', None, None), Book('.', 'Global Module Index', 'modindex'),
('tut','Tutorial','tut.html','node2.html',None), Book('tut','Tutorial','tut','node2'),
('lib','Library Reference','lib.html','contents.html','genindex.html'), Book('lib','Library Reference','lib','contents','genindex'),
('ref','Language Reference','ref.html','contents.html','genindex.html'), Book('ref','Language Reference','ref','contents','genindex'),
('mac','Macintosh Reference','mac.html','contents.html','genindex.html'), Book('mac','Macintosh Reference','mac','contents','genindex'),
('ext','Extending and Embedding','ext.html','contents.html',None), Book('ext','Extending and Embedding','ext','contents'),
('api','Python/C API','api.html','contents.html','genindex.html'), Book('api','Python/C API','api','contents','genindex'),
('doc','Documenting Python','doc.html','contents.html',None), Book('doc','Documenting Python','doc','contents'),
('inst','Installing Python Modules', 'inst.html', 'index.html', None), Book('inst','Installing Python Modules', 'inst', 'index'),
('dist','Distributing Python Modules', 'dist.html', 'index.html', None), Book('dist','Distributing Python Modules', 'dist', 'index'),
], ],
'2.0.0': '2.0.0':
[ [
('.', 'Global Module Index', 'modindex.html', None, None), Book('.', 'Global Module Index', 'modindex'),
('tut','Tutorial','tut.html','node2.html',None), Book('tut','Tutorial','tut','node2'),
('lib','Library Reference','lib.html','contents.html','genindex.html'), Book('lib','Library Reference','lib','contents','genindex'),
('ref','Language Reference','ref.html','contents.html','genindex.html'), Book('ref','Language Reference','ref','contents','genindex'),
('mac','Macintosh Reference','mac.html','contents.html','genindex.html'), Book('mac','Macintosh Reference','mac','contents','genindex'),
('ext','Extending and Embedding','ext.html','contents.html',None), Book('ext','Extending and Embedding','ext','contents'),
('api','Python/C API','api.html','contents.html','genindex.html'), Book('api','Python/C API','api','contents','genindex'),
('doc','Documenting Python','doc.html','contents.html',None), Book('doc','Documenting Python','doc','contents'),
('inst','Installing Python Modules', 'inst.html', 'contents.html', None), Book('inst','Installing Python Modules', 'inst', 'contents'),
('dist','Distributing Python Modules', 'dist.html', 'contents.html', None), Book('dist','Distributing Python Modules', 'dist', 'contents'),
], ],
# <dnagata@creo.com> Apr 17/99: library for 1.5.2 version: # <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): # <hernan.foffani@iname.com> May 01/99: library for 1.5.2 (04/30/99):
'1.5.2': '1.5.2':
[ [
('tut','Tutorial','tut.html','node2.html',None), Book('tut','Tutorial','tut','node2'),
('lib','Library Reference','lib.html','contents.html','genindex.html'), Book('lib','Library Reference','lib','contents','genindex'),
('ref','Language Reference','ref.html','contents.html','genindex.html'), Book('ref','Language Reference','ref','contents','genindex'),
('mac','Macintosh Reference','mac.html','contents.html','genindex.html'), Book('mac','Macintosh Reference','mac','contents','genindex'),
('ext','Extending and Embedding','ext.html','contents.html',None), Book('ext','Extending and Embedding','ext','contents'),
('api','Python/C API','api.html','contents.html','genindex.html'), Book('api','Python/C API','api','contents','genindex'),
('doc','Documenting Python','doc.html','contents.html',None) Book('doc','Documenting Python','doc','contents')
], ],
# library for 1.5.1 version: # library for 1.5.1 version:
'1.5.1': '1.5.1':
[ [
('tut','Tutorial','tut.html','contents.html',None), Book('tut','Tutorial','tut','contents'),
('lib','Library Reference','lib.html','contents.html','genindex.html'), Book('lib','Library Reference','lib','contents','genindex'),
('ref','Language Reference','ref-1.html','ref-2.html','ref-11.html'), Book('ref','Language Reference','ref-1','ref-2','ref-11'),
('ext','Extending and Embedding','ext.html','contents.html',None), Book('ext','Extending and Embedding','ext','contents'),
('api','Python/C API','api.html','contents.html','genindex.html') Book('api','Python/C API','api','contents','genindex')
], ],
# library for 1.5 version: # library for 1.5 version:
'1.5': '1.5':
[ [
('tut','Tutorial','tut.html','node1.html',None), Book('tut','Tutorial','tut','node1'),
('lib','Library Reference','lib.html','node1.html','node268.html'), Book('lib','Library Reference','lib','node1','node268'),
('ref','Language Reference','ref-1.html','ref-2.html','ref-11.html'), Book('ref','Language Reference','ref-1','ref-2','ref-11'),
('ext','Extending and Embedding','ext.html','node1.html',None), Book('ext','Extending and Embedding','ext','node1'),
('api','Python/C API','api.html','node1.html','node48.html') Book('api','Python/C API','api','node1','node48')
] ]
} }
@ -263,42 +281,45 @@ class TocHlpHtmlParser(HelpHtmlParser):
self.ft.write("\t" * self.indent + "<LI>") self.ft.write("\t" * self.indent + "<LI>")
def index(path, archivo, output): def index(path, indexpage, output):
f = formatter.AbstractFormatter(AlmostNullWriter()) f = formatter.AbstractFormatter(AlmostNullWriter())
parser = IdxHlpHtmlParser(f) parser = IdxHlpHtmlParser(f)
parser.path = path parser.path = path
parser.ft = output parser.ft = output
fil = path + '/' + archivo f = open(path + '/' + indexpage)
parser.feed(open(fil).read()) parser.feed(f.read())
parser.close() parser.close()
f.close()
def content(path, archivo, output): def content(path, contentpage, output):
f = formatter.AbstractFormatter(AlmostNullWriter()) f = formatter.AbstractFormatter(AlmostNullWriter())
parser = TocHlpHtmlParser(f) parser = TocHlpHtmlParser(f)
parser.path = path parser.path = path
parser.ft = output parser.ft = output
fil = path + '/' + archivo f = open(path + '/' + contentpage)
parser.feed(open(fil).read()) parser.feed(f.read())
parser.close() parser.close()
f.close()
def do_index(library, output): def do_index(library, output):
output.write('<UL>\n') output.write('<UL>\n')
for book in library: for book in library:
print '\t', book[2] print '\t', book.title, '-', book.indexpage
if book[4]: if book.indexpage:
index(book[0], book[4], output) index(book.directory, book.indexpage, output)
output.write('</UL>\n') output.write('</UL>\n')
def do_content(library, version, output): def do_content(library, version, output):
output.write(contents_header % version) output.write(contents_header % version)
for book in library: for book in library:
print '\t', book[2] print '\t', book.title, '-', book.firstpage
output.write(object_sitemap % (book[0]+"/"+book[2], book[1])) output.write(object_sitemap % (book.directory + "/" + book.firstpage,
if book[3]: book.title))
content(book[0], book[3], output) if book.contentpage:
content(book.directory, book.contentpage, output)
output.write(contents_footer) output.write(contents_footer)
# Fill in the [FILES] section of the project (.hhp) file. # Fill in the [FILES] section of the project (.hhp) file.
@ -307,7 +328,7 @@ def do_content(library, version, output):
def do_project(library, output, arch, version): def do_project(library, output, arch, version):
output.write(project_template % locals()) output.write(project_template % locals())
for book in library: for book in library:
directory = book[0] directory = book.directory
path = directory + '\\%s\n' path = directory + '\\%s\n'
for page in os.listdir(directory): for page in os.listdir(directory):
if page.endswith('.html') or page.endswith('.css'): if page.endswith('.html') or page.endswith('.css'):