1999-02-24 13:33:07 -04:00
|
|
|
#! /usr/bin/env python
|
|
|
|
# -*- Python -*-
|
|
|
|
|
1999-03-04 17:19:57 -04:00
|
|
|
"""usage: %(program)s [options] file...
|
|
|
|
|
|
|
|
Supported options:
|
|
|
|
|
|
|
|
--address addr
|
|
|
|
-a addr Set the address text to include at the end of the generated
|
|
|
|
HTML; this should be used for contact information.
|
|
|
|
--columns cols
|
|
|
|
-c cols Set the number of columns each index section should be
|
|
|
|
displayed in. The default is 1.
|
|
|
|
--help
|
|
|
|
-h Display this help message.
|
|
|
|
--letters
|
|
|
|
-l Split the output into sections by letter.
|
|
|
|
--output file
|
|
|
|
-o file Write output to 'file' instead of standard out.
|
|
|
|
--iconserver is Use 'is' as the directory containing icons for the
|
|
|
|
navigation bar. The default is 'icons'.
|
|
|
|
--title str Set the page title to 'str'. The default is 'Global
|
|
|
|
Module Index'.
|
|
|
|
--uplink url Set the upward link URL. The default is './'.
|
|
|
|
--uptitle str Set the upward link title. The default is 'Python
|
|
|
|
Documentation Index'.
|
|
|
|
"""
|
1999-02-24 13:33:07 -04:00
|
|
|
import buildindex
|
|
|
|
import getopt
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import string
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
1999-03-04 17:19:57 -04:00
|
|
|
def usage():
|
|
|
|
program = os.path.basename(sys.argv[0])
|
|
|
|
print __doc__ % {"program": program}
|
|
|
|
|
|
|
|
|
|
|
|
def error(msg, rc=2):
|
|
|
|
sys.stdout = sys.stderr
|
|
|
|
print msg
|
|
|
|
print
|
|
|
|
usage()
|
|
|
|
sys.exit(rc)
|
|
|
|
|
|
|
|
|
1999-02-24 13:33:07 -04:00
|
|
|
_rx = re.compile(
|
2000-04-03 01:19:14 -03:00
|
|
|
"<dt><a href='(module-.*\.html)#l2h-\d+'><tt class='module'>"
|
|
|
|
"([a-zA-Z_][a-zA-Z0-9_.]*</tt>(\s*<em>"
|
|
|
|
"\(<span class='platform'>.*</span>\)</em>)?)</a>")
|
1999-02-24 13:33:07 -04:00
|
|
|
|
|
|
|
def main():
|
|
|
|
outputfile = "-"
|
|
|
|
columns = 1
|
|
|
|
letters = 0
|
1999-03-04 17:19:57 -04:00
|
|
|
uplink = "./"
|
|
|
|
uptitle = "Python Documentation Index"
|
|
|
|
variables = {"address": "",
|
|
|
|
"iconserver": "icons",
|
|
|
|
"imgtype": "gif",
|
|
|
|
"title": "Global Module Index",
|
|
|
|
"uplinkalt": "up",
|
|
|
|
"uplinkicon": "up",
|
|
|
|
}
|
|
|
|
try:
|
|
|
|
opts, args = getopt.getopt(sys.argv[1:], "a:c:hlo:",
|
|
|
|
[# script controls:
|
|
|
|
"columns=", "help", "letters", "output=",
|
|
|
|
# content components:
|
|
|
|
"address=", "iconserver=",
|
|
|
|
"title=", "uplink=", "uptitle="])
|
|
|
|
except getopt.error, msg:
|
|
|
|
error(msg)
|
1999-02-24 13:33:07 -04:00
|
|
|
for opt, val in opts:
|
1999-03-04 17:19:57 -04:00
|
|
|
if opt in ("-a", "--address"):
|
|
|
|
val = string.strip(val)
|
|
|
|
variables["address"] = val and "<address>\n%s\n</address>\n" % val
|
|
|
|
elif opt in ("-h", "--help"):
|
|
|
|
usage()
|
|
|
|
sys.exit()
|
|
|
|
elif opt in ("-o", "--output"):
|
1999-02-24 13:33:07 -04:00
|
|
|
outputfile = val
|
|
|
|
elif opt in ("-c", "--columns"):
|
|
|
|
columns = string.atoi(val)
|
|
|
|
elif opt in ("-l", "--letters"):
|
|
|
|
letters = 1
|
1999-03-04 17:19:57 -04:00
|
|
|
elif opt == "--title":
|
|
|
|
variables["title"] = string.strip(val)
|
|
|
|
elif opt == "--uplink":
|
|
|
|
uplink = string.strip(val)
|
|
|
|
elif opt == "--uptitle":
|
|
|
|
uptitle = string.strip(val)
|
|
|
|
elif opt == "--iconserver":
|
|
|
|
variables["iconserver"] = string.strip(val) or "."
|
|
|
|
if uplink and uptitle:
|
|
|
|
variables["uplinkalt"] = "up"
|
|
|
|
variables["uplinkicon"] = "up"
|
|
|
|
else:
|
|
|
|
variables["uplinkalt"] = ""
|
|
|
|
variables["uplinkicon"] = "blank"
|
|
|
|
variables["uplink"] = uplink
|
|
|
|
variables["uptitle"] = uptitle
|
1999-02-24 13:33:07 -04:00
|
|
|
if not args:
|
|
|
|
args = ["-"]
|
|
|
|
#
|
|
|
|
# Collect the input data:
|
|
|
|
#
|
|
|
|
nodes = []
|
|
|
|
seqno = 0
|
1999-03-02 12:22:56 -04:00
|
|
|
has_plat_flag = 0
|
1999-02-24 13:33:07 -04:00
|
|
|
for ifn in args:
|
|
|
|
if ifn == "-":
|
|
|
|
ifp = sys.stdin
|
|
|
|
dirname = ''
|
|
|
|
else:
|
|
|
|
ifp = open(ifn)
|
|
|
|
dirname = os.path.dirname(ifn)
|
|
|
|
while 1:
|
|
|
|
line = ifp.readline()
|
|
|
|
if not line:
|
|
|
|
break
|
|
|
|
m = _rx.match(line)
|
|
|
|
if m:
|
|
|
|
# This line specifies a module!
|
|
|
|
basename, modname = m.group(1, 2)
|
1999-03-02 12:22:56 -04:00
|
|
|
has_plat_flag = has_plat_flag or m.group(3)
|
1999-02-24 13:33:07 -04:00
|
|
|
linkfile = os.path.join(dirname, basename)
|
1999-03-02 12:22:56 -04:00
|
|
|
nodes.append(buildindex.Node(
|
|
|
|
'<a href="%s">' % linkfile,
|
|
|
|
"<tt class=module>%s</tt>" % modname,
|
|
|
|
seqno))
|
1999-02-24 13:33:07 -04:00
|
|
|
seqno = seqno + 1
|
|
|
|
ifp.close()
|
1999-03-02 12:22:56 -04:00
|
|
|
#
|
|
|
|
# Generate all output:
|
|
|
|
#
|
1999-02-24 13:33:07 -04:00
|
|
|
num_nodes = len(nodes)
|
1999-03-02 12:22:56 -04:00
|
|
|
# Here's the HTML generation:
|
1999-03-04 17:19:57 -04:00
|
|
|
parts = [HEAD % variables,
|
|
|
|
buildindex.process_nodes(nodes, columns, letters),
|
|
|
|
TAIL % variables,
|
|
|
|
]
|
1999-03-02 12:22:56 -04:00
|
|
|
if has_plat_flag:
|
|
|
|
parts.insert(1, PLAT_DISCUSS)
|
|
|
|
html = string.join(parts, '')
|
1999-02-24 13:33:07 -04:00
|
|
|
program = os.path.basename(sys.argv[0])
|
|
|
|
if outputfile == "-":
|
|
|
|
sys.stdout.write(html)
|
|
|
|
sys.stderr.write("%s: %d index nodes\n" % (program, num_nodes))
|
|
|
|
else:
|
|
|
|
open(outputfile, "w").write(html)
|
|
|
|
print
|
|
|
|
print "%s: %d index nodes" % (program, num_nodes)
|
|
|
|
|
|
|
|
|
1999-03-02 12:22:56 -04:00
|
|
|
PLAT_DISCUSS = """
|
|
|
|
<p> Some module names are followed by an annotation indicating what
|
|
|
|
platform they are available on.</p>
|
|
|
|
|
1999-02-24 13:33:07 -04:00
|
|
|
"""
|
|
|
|
|
1999-03-04 17:19:57 -04:00
|
|
|
NAVIGATION = """\
|
1999-02-24 13:33:07 -04:00
|
|
|
<div class=navigation>
|
1999-03-04 17:19:57 -04:00
|
|
|
<table width="100%%" cellpadding=0 cellspacing=2>
|
1999-02-24 13:33:07 -04:00
|
|
|
<tr>
|
|
|
|
<td><img width=32 height=32 align=bottom border=0 alt=""
|
1999-03-04 17:19:57 -04:00
|
|
|
src="%(iconserver)s/blank.%(imgtype)s"></td>
|
1999-03-04 17:33:55 -04:00
|
|
|
<td><a href="%(uplink)s"
|
|
|
|
title="%(uptitle)s"><img width=32 height=32 align=bottom border=0
|
|
|
|
alt="%(uplinkalt)s"
|
|
|
|
src="%(iconserver)s/%(uplinkicon)s.%(imgtype)s"></a></td>
|
1999-02-24 13:33:07 -04:00
|
|
|
<td><img width=32 height=32 align=bottom border=0 alt=""
|
1999-03-04 17:19:57 -04:00
|
|
|
src="%(iconserver)s/blank.%(imgtype)s"></td>
|
|
|
|
<td align=center bgcolor="#99CCFF" width="100%%">
|
|
|
|
<b class=title>%(title)s</b></td>
|
1999-02-24 13:33:07 -04:00
|
|
|
<td><img width=32 height=32 align=bottom border=0 alt=""
|
1999-03-04 17:19:57 -04:00
|
|
|
src="%(iconserver)s/blank.%(imgtype)s"></td>
|
1999-02-24 13:33:07 -04:00
|
|
|
<td><img width=32 height=32 align=bottom border=0 alt=""
|
1999-03-04 17:19:57 -04:00
|
|
|
src="%(iconserver)s/blank.%(imgtype)s"></td>
|
|
|
|
<td><img width=32 height=32 align=bottom border=0 alt=""
|
|
|
|
src="%(iconserver)s/blank.%(imgtype)s"></td>
|
1999-02-24 13:33:07 -04:00
|
|
|
</tr></table>
|
1999-03-04 17:33:55 -04:00
|
|
|
<b class=navlabel>Up:</b> <span class=sectref><a href="%(uplink)s"
|
|
|
|
title="%(uptitle)s">%(uptitle)s</A></span>
|
|
|
|
<br></div>
|
1999-03-04 17:19:57 -04:00
|
|
|
"""
|
|
|
|
|
|
|
|
HEAD = """\
|
|
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Global Module Index</title>
|
|
|
|
<meta name="description" content="%(title)s">
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
|
|
<link rel="STYLESHEET" href="lib/lib.css">
|
|
|
|
</head>
|
|
|
|
<body bgcolor=white>
|
|
|
|
""" + NAVIGATION + """\
|
1999-03-04 17:33:55 -04:00
|
|
|
<hr>
|
1999-03-04 17:19:57 -04:00
|
|
|
|
|
|
|
<h2>%(title)s</h2>
|
|
|
|
|
1999-02-24 13:33:07 -04:00
|
|
|
"""
|
|
|
|
|
1999-03-04 17:33:55 -04:00
|
|
|
TAIL = "<hr>\n" + NAVIGATION + """\
|
1999-03-04 17:19:57 -04:00
|
|
|
%(address)s</body>
|
|
|
|
</html>
|
|
|
|
"""
|
1999-02-24 13:33:07 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|