blob: 14568d129ea1b42417f0fc910103dfbce91ad5a0 [file] [log] [blame]
Fred Drake2ef38a71999-02-24 17:33:07 +00001#! /usr/bin/env python
2# -*- Python -*-
3
Fred Drake5f7832d1999-03-04 21:19:57 +00004"""usage: %(program)s [options] file...
5
6Supported options:
7
8 --address addr
9 -a addr Set the address text to include at the end of the generated
10 HTML; this should be used for contact information.
11 --columns cols
12 -c cols Set the number of columns each index section should be
13 displayed in. The default is 1.
14 --help
15 -h Display this help message.
16 --letters
17 -l Split the output into sections by letter.
18 --output file
19 -o file Write output to 'file' instead of standard out.
20 --iconserver is Use 'is' as the directory containing icons for the
21 navigation bar. The default is 'icons'.
22 --title str Set the page title to 'str'. The default is 'Global
23 Module Index'.
24 --uplink url Set the upward link URL. The default is './'.
25 --uptitle str Set the upward link title. The default is 'Python
26 Documentation Index'.
27"""
Fred Drake2ef38a71999-02-24 17:33:07 +000028import buildindex
29import getopt
30import os
31import re
32import string
33import sys
34
35
Fred Drake5f7832d1999-03-04 21:19:57 +000036def usage():
37 program = os.path.basename(sys.argv[0])
38 print __doc__ % {"program": program}
39
40
41def error(msg, rc=2):
42 sys.stdout = sys.stderr
43 print msg
44 print
45 usage()
46 sys.exit(rc)
47
48
Fred Drake2ef38a71999-02-24 17:33:07 +000049_rx = re.compile(
Fred Drakeba828782000-04-03 04:19:14 +000050 "<dt><a href='(module-.*\.html)#l2h-\d+'><tt class='module'>"
51 "([a-zA-Z_][a-zA-Z0-9_.]*</tt>(\s*<em>"
52 "\(<span class='platform'>.*</span>\)</em>)?)</a>")
Fred Drake2ef38a71999-02-24 17:33:07 +000053
54def main():
55 outputfile = "-"
56 columns = 1
57 letters = 0
Fred Drake5f7832d1999-03-04 21:19:57 +000058 uplink = "./"
59 uptitle = "Python Documentation Index"
60 variables = {"address": "",
61 "iconserver": "icons",
62 "imgtype": "gif",
63 "title": "Global Module Index",
64 "uplinkalt": "up",
65 "uplinkicon": "up",
66 }
67 try:
68 opts, args = getopt.getopt(sys.argv[1:], "a:c:hlo:",
69 [# script controls:
70 "columns=", "help", "letters", "output=",
71 # content components:
72 "address=", "iconserver=",
73 "title=", "uplink=", "uptitle="])
74 except getopt.error, msg:
75 error(msg)
Fred Drake2ef38a71999-02-24 17:33:07 +000076 for opt, val in opts:
Fred Drake5f7832d1999-03-04 21:19:57 +000077 if opt in ("-a", "--address"):
78 val = string.strip(val)
79 variables["address"] = val and "<address>\n%s\n</address>\n" % val
80 elif opt in ("-h", "--help"):
81 usage()
82 sys.exit()
83 elif opt in ("-o", "--output"):
Fred Drake2ef38a71999-02-24 17:33:07 +000084 outputfile = val
85 elif opt in ("-c", "--columns"):
86 columns = string.atoi(val)
87 elif opt in ("-l", "--letters"):
88 letters = 1
Fred Drake5f7832d1999-03-04 21:19:57 +000089 elif opt == "--title":
90 variables["title"] = string.strip(val)
91 elif opt == "--uplink":
92 uplink = string.strip(val)
93 elif opt == "--uptitle":
94 uptitle = string.strip(val)
95 elif opt == "--iconserver":
96 variables["iconserver"] = string.strip(val) or "."
97 if uplink and uptitle:
98 variables["uplinkalt"] = "up"
99 variables["uplinkicon"] = "up"
100 else:
101 variables["uplinkalt"] = ""
102 variables["uplinkicon"] = "blank"
103 variables["uplink"] = uplink
104 variables["uptitle"] = uptitle
Fred Drake2ef38a71999-02-24 17:33:07 +0000105 if not args:
106 args = ["-"]
107 #
108 # Collect the input data:
109 #
110 nodes = []
111 seqno = 0
Fred Drake7f492ad1999-03-02 16:22:56 +0000112 has_plat_flag = 0
Fred Drake2ef38a71999-02-24 17:33:07 +0000113 for ifn in args:
114 if ifn == "-":
115 ifp = sys.stdin
116 dirname = ''
117 else:
118 ifp = open(ifn)
119 dirname = os.path.dirname(ifn)
120 while 1:
121 line = ifp.readline()
122 if not line:
123 break
124 m = _rx.match(line)
125 if m:
126 # This line specifies a module!
127 basename, modname = m.group(1, 2)
Fred Drake7f492ad1999-03-02 16:22:56 +0000128 has_plat_flag = has_plat_flag or m.group(3)
Fred Drake2ef38a71999-02-24 17:33:07 +0000129 linkfile = os.path.join(dirname, basename)
Fred Drake7f492ad1999-03-02 16:22:56 +0000130 nodes.append(buildindex.Node(
131 '<a href="%s">' % linkfile,
132 "<tt class=module>%s</tt>" % modname,
133 seqno))
Fred Drake2ef38a71999-02-24 17:33:07 +0000134 seqno = seqno + 1
135 ifp.close()
Fred Drake7f492ad1999-03-02 16:22:56 +0000136 #
137 # Generate all output:
138 #
Fred Drake2ef38a71999-02-24 17:33:07 +0000139 num_nodes = len(nodes)
Fred Drake7f492ad1999-03-02 16:22:56 +0000140 # Here's the HTML generation:
Fred Drake5f7832d1999-03-04 21:19:57 +0000141 parts = [HEAD % variables,
142 buildindex.process_nodes(nodes, columns, letters),
143 TAIL % variables,
144 ]
Fred Drake7f492ad1999-03-02 16:22:56 +0000145 if has_plat_flag:
146 parts.insert(1, PLAT_DISCUSS)
147 html = string.join(parts, '')
Fred Drake2ef38a71999-02-24 17:33:07 +0000148 program = os.path.basename(sys.argv[0])
149 if outputfile == "-":
150 sys.stdout.write(html)
151 sys.stderr.write("%s: %d index nodes\n" % (program, num_nodes))
152 else:
153 open(outputfile, "w").write(html)
154 print
155 print "%s: %d index nodes" % (program, num_nodes)
156
157
Fred Drake7f492ad1999-03-02 16:22:56 +0000158PLAT_DISCUSS = """
159<p> Some module names are followed by an annotation indicating what
160platform they are available on.</p>
161
Fred Drake2ef38a71999-02-24 17:33:07 +0000162"""
163
Fred Drake5f7832d1999-03-04 21:19:57 +0000164NAVIGATION = """\
Fred Drake2ef38a71999-02-24 17:33:07 +0000165<div class=navigation>
Fred Drake5f7832d1999-03-04 21:19:57 +0000166<table width="100%%" cellpadding=0 cellspacing=2>
Fred Drake2ef38a71999-02-24 17:33:07 +0000167<tr>
Fred Drake2ef38a71999-02-24 17:33:07 +0000168<td><img width=32 height=32 align=bottom border=0 alt=""
Fred Drake5f7832d1999-03-04 21:19:57 +0000169 src="%(iconserver)s/blank.%(imgtype)s"></td>
Fred Drake1acb8741999-03-04 21:33:55 +0000170<td><a href="%(uplink)s"
171 title="%(uptitle)s"><img width=32 height=32 align=bottom border=0
172 alt="%(uplinkalt)s"
173 src="%(iconserver)s/%(uplinkicon)s.%(imgtype)s"></a></td>
Fred Drake2ef38a71999-02-24 17:33:07 +0000174<td><img width=32 height=32 align=bottom border=0 alt=""
Fred Drake5f7832d1999-03-04 21:19:57 +0000175 src="%(iconserver)s/blank.%(imgtype)s"></td>
176<td align=center bgcolor="#99CCFF" width="100%%">
177 <b class=title>%(title)s</b></td>
Fred Drake2ef38a71999-02-24 17:33:07 +0000178<td><img width=32 height=32 align=bottom border=0 alt=""
Fred Drake5f7832d1999-03-04 21:19:57 +0000179 src="%(iconserver)s/blank.%(imgtype)s"></td>
Fred Drake2ef38a71999-02-24 17:33:07 +0000180<td><img width=32 height=32 align=bottom border=0 alt=""
Fred Drake5f7832d1999-03-04 21:19:57 +0000181 src="%(iconserver)s/blank.%(imgtype)s"></td>
182<td><img width=32 height=32 align=bottom border=0 alt=""
183 src="%(iconserver)s/blank.%(imgtype)s"></td>
Fred Drake2ef38a71999-02-24 17:33:07 +0000184</tr></table>
Fred Drake1acb8741999-03-04 21:33:55 +0000185<b class=navlabel>Up:</b> <span class=sectref><a href="%(uplink)s"
186 title="%(uptitle)s">%(uptitle)s</A></span>
187<br></div>
Fred Drake2ef38a71999-02-24 17:33:07 +0000188"""
189
Fred Drake5f7832d1999-03-04 21:19:57 +0000190HEAD = """\
191<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
192<html>
193<head>
194<title>Global Module Index</title>
195<meta name="description" content="%(title)s">
196<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
197<link rel="STYLESHEET" href="lib/lib.css">
198</head>
199<body bgcolor=white>
200""" + NAVIGATION + """\
Fred Drake1acb8741999-03-04 21:33:55 +0000201<hr>
Fred Drake5f7832d1999-03-04 21:19:57 +0000202
203<h2>%(title)s</h2>
204
205"""
206
Fred Drake1acb8741999-03-04 21:33:55 +0000207TAIL = "<hr>\n" + NAVIGATION + """\
Fred Drake5f7832d1999-03-04 21:19:57 +0000208%(address)s</body>
209</html>
210"""
Fred Drake2ef38a71999-02-24 17:33:07 +0000211
212if __name__ == "__main__":
213 main()