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 os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
2002-10-30 17:32:40 -04:00
|
|
|
from xml.sax.saxutils import quoteattr
|
|
|
|
|
2002-10-16 12:29:07 -03:00
|
|
|
import buildindex
|
|
|
|
import support
|
|
|
|
|
1999-02-24 13:33:07 -04:00
|
|
|
|
2000-10-05 02:14:26 -03:00
|
|
|
class IndexOptions(support.Options):
|
2002-04-05 13:34:50 -04:00
|
|
|
aesop_type = "links"
|
|
|
|
|
2000-10-05 02:14:26 -03:00
|
|
|
def __init__(self):
|
|
|
|
support.Options.__init__(self)
|
|
|
|
self.add_args("l", ["letters"])
|
|
|
|
self.letters = 0
|
1999-03-04 17:19:57 -04:00
|
|
|
|
2000-10-05 02:14:26 -03:00
|
|
|
def handle_option(self, opt, val):
|
|
|
|
if opt in ("-l", "--letters"):
|
|
|
|
self.letters = 1
|
1999-03-04 17:19:57 -04:00
|
|
|
|
2000-10-05 02:14:26 -03:00
|
|
|
def usage(self):
|
|
|
|
program = os.path.basename(sys.argv[0])
|
|
|
|
print __doc__ % {"program": program}
|
1999-03-04 17:19:57 -04:00
|
|
|
|
2002-10-30 17:32:40 -04:00
|
|
|
links = [
|
|
|
|
('author', 'acks.html', 'Acknowledgements'),
|
|
|
|
('help', 'about.html', 'About the Python Documentation'),
|
|
|
|
]
|
|
|
|
|
|
|
|
def get_header(self):
|
|
|
|
header = support.Options.get_header(self)
|
|
|
|
s = ''
|
|
|
|
for rel, href, title in self.links:
|
|
|
|
s += '<link rel="%s" href="%s"' % (rel, href)
|
|
|
|
if title:
|
|
|
|
s += ' title=' + quoteattr(title)
|
|
|
|
s += '>\n '
|
|
|
|
return header.replace("<link ", s + "<link ", 1)
|
|
|
|
|
1999-03-04 17:19:57 -04:00
|
|
|
|
2000-11-28 12:20:50 -04:00
|
|
|
class Node(buildindex.Node):
|
2001-06-22 14:11:30 -03:00
|
|
|
def __init__(self, link, str, seqno, platinfo):
|
|
|
|
self.annotation = platinfo or None
|
|
|
|
if str[0][-5:] == "</tt>":
|
|
|
|
str = str[:-5]
|
|
|
|
self.modname = str
|
2000-11-28 12:20:50 -04:00
|
|
|
buildindex.Node.__init__(self, link, self.modname, seqno)
|
2001-06-22 14:11:30 -03:00
|
|
|
if platinfo:
|
|
|
|
s = '<tt class="module">%s</tt> %s' \
|
|
|
|
% (self.modname, self.annotation)
|
|
|
|
else:
|
|
|
|
s = '<tt class="module">%s</tt>' % str
|
|
|
|
self.text = [s]
|
2000-11-28 12:20:50 -04:00
|
|
|
|
|
|
|
def __str__(self):
|
2001-06-22 14:11:30 -03:00
|
|
|
if self.annotation:
|
|
|
|
return '<tt class="module">%s</tt> %s' \
|
|
|
|
% (self.modname, self.annotation)
|
|
|
|
else:
|
|
|
|
return '<tt class="module">%s</tt>' % self.modname
|
2000-11-28 12:20:50 -04:00
|
|
|
|
1999-02-24 13:33:07 -04:00
|
|
|
_rx = re.compile(
|
2001-06-22 14:11:30 -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():
|
2000-10-05 02:14:26 -03:00
|
|
|
options = IndexOptions()
|
|
|
|
options.variables["title"] = "Global Module Index"
|
|
|
|
options.parse(sys.argv[1:])
|
|
|
|
args = options.args
|
1999-02-24 13:33:07 -04:00
|
|
|
if not args:
|
|
|
|
args = ["-"]
|
|
|
|
#
|
|
|
|
# Collect the input data:
|
|
|
|
#
|
|
|
|
nodes = []
|
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!
|
2001-06-22 14:11:30 -03:00
|
|
|
basename, modname, platinfo = m.group(1, 2, 3)
|
|
|
|
has_plat_flag = has_plat_flag or platinfo
|
1999-02-24 13:33:07 -04:00
|
|
|
linkfile = os.path.join(dirname, basename)
|
2001-06-22 14:11:30 -03:00
|
|
|
nodes.append(Node('<a href="%s">' % linkfile, modname,
|
|
|
|
len(nodes), platinfo))
|
1999-02-24 13:33:07 -04:00
|
|
|
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:
|
2000-10-05 02:14:26 -03:00
|
|
|
parts = [options.get_header(),
|
|
|
|
buildindex.process_nodes(nodes, options.columns, options.letters),
|
|
|
|
options.get_footer(),
|
1999-03-04 17:19:57 -04:00
|
|
|
]
|
1999-03-02 12:22:56 -04:00
|
|
|
if has_plat_flag:
|
|
|
|
parts.insert(1, PLAT_DISCUSS)
|
2002-10-16 12:29:07 -03:00
|
|
|
html = ''.join(parts)
|
1999-02-24 13:33:07 -04:00
|
|
|
program = os.path.basename(sys.argv[0])
|
2000-10-05 02:14:26 -03:00
|
|
|
fp = options.get_output_file()
|
2002-10-16 12:29:07 -03:00
|
|
|
fp.write(html.rstrip() + "\n")
|
2000-10-05 02:14:26 -03:00
|
|
|
if options.outputfile == "-":
|
2001-02-12 11:30:22 -04:00
|
|
|
sys.stderr.write("%s: %d index nodes\n" % (program, num_nodes))
|
1999-02-24 13:33:07 -04:00
|
|
|
else:
|
|
|
|
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
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|