blob: 16aa109e656e669936ce1ed21d72b48a79625420 [file] [log] [blame]
Fred Drake2ef38a71999-02-24 17:33:07 +00001#! /usr/bin/env python
2# -*- Python -*-
3
4import buildindex
5import getopt
6import os
7import re
8import string
9import sys
10
11
12_rx = re.compile(
Fred Drake7f492ad1999-03-02 16:22:56 +000013 '<dt><a href="(module-.*\.html)">'
14 '([a-zA-Z_][a-zA-Z0-9_.]*(\s*<em>\(.*\)</em>)?)</a>')
Fred Drake2ef38a71999-02-24 17:33:07 +000015
16def main():
17 outputfile = "-"
18 columns = 1
19 letters = 0
20 opts, args = getopt.getopt(sys.argv[1:], "c:lo:",
21 ["columns=", "letters", "output="])
22 for opt, val in opts:
23 if opt in ("-o", "--output"):
24 outputfile = val
25 elif opt in ("-c", "--columns"):
26 columns = string.atoi(val)
27 elif opt in ("-l", "--letters"):
28 letters = 1
29 if not args:
30 args = ["-"]
31 #
32 # Collect the input data:
33 #
34 nodes = []
35 seqno = 0
Fred Drake7f492ad1999-03-02 16:22:56 +000036 has_plat_flag = 0
Fred Drake2ef38a71999-02-24 17:33:07 +000037 for ifn in args:
38 if ifn == "-":
39 ifp = sys.stdin
40 dirname = ''
41 else:
42 ifp = open(ifn)
43 dirname = os.path.dirname(ifn)
44 while 1:
45 line = ifp.readline()
46 if not line:
47 break
48 m = _rx.match(line)
49 if m:
50 # This line specifies a module!
51 basename, modname = m.group(1, 2)
Fred Drake7f492ad1999-03-02 16:22:56 +000052 has_plat_flag = has_plat_flag or m.group(3)
Fred Drake2ef38a71999-02-24 17:33:07 +000053 linkfile = os.path.join(dirname, basename)
Fred Drake7f492ad1999-03-02 16:22:56 +000054 nodes.append(buildindex.Node(
55 '<a href="%s">' % linkfile,
56 "<tt class=module>%s</tt>" % modname,
57 seqno))
Fred Drake2ef38a71999-02-24 17:33:07 +000058 seqno = seqno + 1
59 ifp.close()
Fred Drake7f492ad1999-03-02 16:22:56 +000060 #
61 # Generate all output:
62 #
Fred Drake2ef38a71999-02-24 17:33:07 +000063 num_nodes = len(nodes)
Fred Drake7f492ad1999-03-02 16:22:56 +000064 # Here's the HTML generation:
65 parts = [HEAD, buildindex.process_nodes(nodes, columns, letters), TAIL]
66 if has_plat_flag:
67 parts.insert(1, PLAT_DISCUSS)
68 html = string.join(parts, '')
Fred Drake2ef38a71999-02-24 17:33:07 +000069 program = os.path.basename(sys.argv[0])
70 if outputfile == "-":
71 sys.stdout.write(html)
72 sys.stderr.write("%s: %d index nodes\n" % (program, num_nodes))
73 else:
74 open(outputfile, "w").write(html)
75 print
76 print "%s: %d index nodes" % (program, num_nodes)
77
78
79HEAD = """\
80<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
81<html>
82<head>
83<title>Global Module Index</title>
84<META NAME="description" CONTENT="Global Module Index">
85<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
86<LINK REL="STYLESHEET" HREF="lib/lib.css">
87<LINK REL="up" HREF="./">
88</head>
89<body bgcolor="#ffffff">
90<div class=navigation>
91<table width="100%" cellpadding=0 cellspacing=2>
92<tr>
93<td><img width=32 height=32 align=bottom border=0 alt="blank"
94 src="icons/blank.gif"></td>
95<td><a href="./"><img width=32 height=32 align=bottom border=0 alt="up"
96 src="icons/up.gif"></A></td>
97<td><img width=32 height=32 align=bottom border=0 alt="blank"
98 src="icons/blank.gif"></td>
99<td align=center bgcolor="#99CCFF" width="100%">
100 <b class=title>Global Module Index</b></td>
101<td><img width=32 height=32 align=bottom border=0 alt="blank"
102 src="icons/blank.gif"></td>
103<td><img width=32 height=32 align=bottom border=0 alt="blank"
104 src="icons/blank.gif"></td>
105<td><img width=32 height=32 align=bottom border=0 alt="blank"
106 src="icons/blank.gif"></td>
107</tr></table>
108<b class=navlabel>Up:</b> <span class=sectref><A
109 HREF="./">Python Documentation Index</A></span>
110<br><hr></div>
Fred Drake7f492ad1999-03-02 16:22:56 +0000111
112<h2>Global Module Index</h2>
113
114"""
115
116PLAT_DISCUSS = """
117<p> Some module names are followed by an annotation indicating what
118platform they are available on.</p>
119
Fred Drake2ef38a71999-02-24 17:33:07 +0000120"""
121
122TAIL = """
123<div class=navigation>
124<hr>
125<table width="100%" cellpadding=0 cellspacing=2>
126<tr>
127<td><img width=32 height=32 align=bottom border=0 alt="blank"
128 src="icons/blank.gif"></td>
129<td><a href="./"><img width=32 height=32 align=bottom border=0 alt="up"
130 src="icons/up.gif"></A></td>
131<td><img width=32 height=32 align=bottom border=0 alt=""
132 src="icons/blank.gif"></A></td>
133<td align=center bgcolor="#99CCFF" width="100%">
134 <b class=title>Global Module Index</b></td>
135<td><img width=32 height=32 align=bottom border=0 alt=""
136 src="icons/blank.gif"></td>
137<td><img width=32 height=32 align=bottom border=0 alt=""
138 src="icons/blank.gif"></td>
139<td><img width=32 height=32 align=bottom border=0 alt=""
140 src="icons/blank.gif"></td>
141</tr></table>
142<b class=navlabel>Up:</b> <span class=sectref><A
143 HREF="./">Python Documentation Index</A></span>
144</div>
145<!--End of Navigation Panel-->
146<ADDRESS>
147<hr>Send comments to
148<a href="mailto:python-docs@python.org">python-docs@python.org</a>.
149</ADDRESS>
150</BODY>
151</HTML>
152"""
153
154
155if __name__ == "__main__":
156 main()