|
| 1 | +#! /usr/bin/env python |
| 2 | +# -*- Python -*- |
| 3 | + |
| 4 | +import buildindex |
| 5 | +import getopt |
| 6 | +import os |
| 7 | +import re |
| 8 | +import string |
| 9 | +import sys |
| 10 | + |
| 11 | + |
| 12 | +_rx = re.compile( |
| 13 | + '<dt><a href="(module-.*\.html)">([a-zA-Z_][a-zA-Z0-9_.]*)</a>') |
| 14 | + |
| 15 | +def main(): |
| 16 | + outputfile = "-" |
| 17 | + columns = 1 |
| 18 | + letters = 0 |
| 19 | + opts, args = getopt.getopt(sys.argv[1:], "c:lo:", |
| 20 | + ["columns=", "letters", "output="]) |
| 21 | + for opt, val in opts: |
| 22 | + if opt in ("-o", "--output"): |
| 23 | + outputfile = val |
| 24 | + elif opt in ("-c", "--columns"): |
| 25 | + columns = string.atoi(val) |
| 26 | + elif opt in ("-l", "--letters"): |
| 27 | + letters = 1 |
| 28 | + if not args: |
| 29 | + args = ["-"] |
| 30 | + # |
| 31 | + # Collect the input data: |
| 32 | + # |
| 33 | + nodes = [] |
| 34 | + seqno = 0 |
| 35 | + for ifn in args: |
| 36 | + if ifn == "-": |
| 37 | + ifp = sys.stdin |
| 38 | + dirname = '' |
| 39 | + else: |
| 40 | + ifp = open(ifn) |
| 41 | + dirname = os.path.dirname(ifn) |
| 42 | + while 1: |
| 43 | + line = ifp.readline() |
| 44 | + if not line: |
| 45 | + break |
| 46 | + m = _rx.match(line) |
| 47 | + if m: |
| 48 | + # This line specifies a module! |
| 49 | + basename, modname = m.group(1, 2) |
| 50 | + linkfile = os.path.join(dirname, basename) |
| 51 | + nodes.append(buildindex.Node('<a href="%s">' % linkfile, |
| 52 | + "<tt>%s</tt>" % modname, |
| 53 | + seqno)) |
| 54 | + seqno = seqno + 1 |
| 55 | + ifp.close() |
| 56 | + num_nodes = len(nodes) |
| 57 | + html = HEAD + buildindex.process_nodes(nodes, columns, letters) + TAIL |
| 58 | + program = os.path.basename(sys.argv[0]) |
| 59 | + if outputfile == "-": |
| 60 | + sys.stdout.write(html) |
| 61 | + sys.stderr.write("%s: %d index nodes\n" % (program, num_nodes)) |
| 62 | + else: |
| 63 | + open(outputfile, "w").write(html) |
| 64 | + print |
| 65 | + print "%s: %d index nodes" % (program, num_nodes) |
| 66 | + |
| 67 | + |
| 68 | +HEAD = """\ |
| 69 | +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 70 | +<html> |
| 71 | +<head> |
| 72 | +<title>Global Module Index</title> |
| 73 | +<META NAME="description" CONTENT="Global Module Index"> |
| 74 | +<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> |
| 75 | +<LINK REL="STYLESHEET" HREF="lib/lib.css"> |
| 76 | +<LINK REL="up" HREF="./"> |
| 77 | +</head> |
| 78 | +<body bgcolor="#ffffff"> |
| 79 | +<div class=navigation> |
| 80 | +<table width="100%" cellpadding=0 cellspacing=2> |
| 81 | +<tr> |
| 82 | +<td><img width=32 height=32 align=bottom border=0 alt="blank" |
| 83 | + src="icons/blank.gif"></td> |
| 84 | +<td><a href="./"><img width=32 height=32 align=bottom border=0 alt="up" |
| 85 | + src="icons/up.gif"></A></td> |
| 86 | +<td><img width=32 height=32 align=bottom border=0 alt="blank" |
| 87 | + src="icons/blank.gif"></td> |
| 88 | +<td align=center bgcolor="#99CCFF" width="100%"> |
| 89 | + <b class=title>Global Module Index</b></td> |
| 90 | +<td><img width=32 height=32 align=bottom border=0 alt="blank" |
| 91 | + src="icons/blank.gif"></td> |
| 92 | +<td><img width=32 height=32 align=bottom border=0 alt="blank" |
| 93 | + src="icons/blank.gif"></td> |
| 94 | +<td><img width=32 height=32 align=bottom border=0 alt="blank" |
| 95 | + src="icons/blank.gif"></td> |
| 96 | +</tr></table> |
| 97 | +<b class=navlabel>Up:</b> <span class=sectref><A |
| 98 | + HREF="./">Python Documentation Index</A></span> |
| 99 | +<br><hr></div> |
| 100 | +""" |
| 101 | + |
| 102 | +TAIL = """ |
| 103 | +<div class=navigation> |
| 104 | +<hr> |
| 105 | +<table width="100%" cellpadding=0 cellspacing=2> |
| 106 | +<tr> |
| 107 | +<td><img width=32 height=32 align=bottom border=0 alt="blank" |
| 108 | + src="icons/blank.gif"></td> |
| 109 | +<td><a href="./"><img width=32 height=32 align=bottom border=0 alt="up" |
| 110 | + src="icons/up.gif"></A></td> |
| 111 | +<td><img width=32 height=32 align=bottom border=0 alt="" |
| 112 | + src="icons/blank.gif"></A></td> |
| 113 | +<td align=center bgcolor="#99CCFF" width="100%"> |
| 114 | + <b class=title>Global Module Index</b></td> |
| 115 | +<td><img width=32 height=32 align=bottom border=0 alt="" |
| 116 | + src="icons/blank.gif"></td> |
| 117 | +<td><img width=32 height=32 align=bottom border=0 alt="" |
| 118 | + src="icons/blank.gif"></td> |
| 119 | +<td><img width=32 height=32 align=bottom border=0 alt="" |
| 120 | + src="icons/blank.gif"></td> |
| 121 | +</tr></table> |
| 122 | +<b class=navlabel>Up:</b> <span class=sectref><A |
| 123 | + HREF="./">Python Documentation Index</A></span> |
| 124 | +</div> |
| 125 | +<!--End of Navigation Panel--> |
| 126 | +<ADDRESS> |
| 127 | +<hr>Send comments to |
| 128 | + |
| 129 | +</ADDRESS> |
| 130 | +</BODY> |
| 131 | +</HTML> |
| 132 | +""" |
| 133 | + |
| 134 | + |
| 135 | +if __name__ == "__main__": |
| 136 | + main() |
0 commit comments