#! /usr/bin/env python # -*- Python -*- import buildindex import getopt import os import re import string import sys _rx = re.compile( '
' '([a-zA-Z_][a-zA-Z0-9_.]*(\s*\(.*\))?)') def main(): outputfile = "-" columns = 1 letters = 0 opts, args = getopt.getopt(sys.argv[1:], "c:lo:", ["columns=", "letters", "output="]) for opt, val in opts: if opt in ("-o", "--output"): outputfile = val elif opt in ("-c", "--columns"): columns = string.atoi(val) elif opt in ("-l", "--letters"): letters = 1 if not args: args = ["-"] # # Collect the input data: # nodes = [] seqno = 0 has_plat_flag = 0 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) has_plat_flag = has_plat_flag or m.group(3) linkfile = os.path.join(dirname, basename) nodes.append(buildindex.Node( '' % linkfile, "%s" % modname, seqno)) seqno = seqno + 1 ifp.close() # # Generate all output: # num_nodes = len(nodes) # Here's the HTML generation: parts = [HEAD, buildindex.process_nodes(nodes, columns, letters), TAIL] if has_plat_flag: parts.insert(1, PLAT_DISCUSS) html = string.join(parts, '') 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) HEAD = """\ Global Module Index

Global Module Index

""" PLAT_DISCUSS = """

Some module names are followed by an annotation indicating what platform they are available on.

""" TAIL = """

Send comments to python-docs@python.org.
""" if __name__ == "__main__": main()