blob: 4400cea5719a426ec78143daf5f79d24e5482e07 [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 Drake7f492ad1999-03-02 16:22:56 +000050 '<dt><a href="(module-.*\.html)">'
51 '([a-zA-Z_][a-zA-Z0-9_.]*(\s*<em>\(.*\)</em>)?)</a>')
Fred Drake2ef38a71999-02-24 17:33:07 +000052
53def main():
54 outputfile = "-"
55 columns = 1
56 letters = 0
Fred Drake5f7832d1999-03-04 21:19:57 +000057 uplink = "./"
58 uptitle = "Python Documentation Index"
59 variables = {"address": "",
60 "iconserver": "icons",
61 "imgtype": "gif",
62 "title": "Global Module Index",
63 "uplinkalt": "up",
64 "uplinkicon": "up",
65 }
66 try:
67 opts, args = getopt.getopt(sys.argv[1:], "a:c:hlo:",
68 [# script controls:
69 "columns=", "help", "letters", "output=",
70 # content components:
71 "address=", "iconserver=",
72 "title=", "uplink=", "uptitle="])
73 except getopt.error, msg:
74 error(msg)
Fred Drake2ef38a71999-02-24 17:33:07 +000075 for opt, val in opts:
Fred Drake5f7832d1999-03-04 21:19:57 +000076 if opt in ("-a", "--address"):
77 val = string.strip(val)
78 variables["address"] = val and "<address>\n%s\n</address>\n" % val
79 elif opt in ("-h", "--help"):
80 usage()
81 sys.exit()
82 elif opt in ("-o", "--output"):
Fred Drake2ef38a71999-02-24 17:33:07 +000083 outputfile = val
84 elif opt in ("-c", "--columns"):
85 columns = string.atoi(val)
86 elif opt in ("-l", "--letters"):
87 letters = 1
Fred Drake5f7832d1999-03-04 21:19:57 +000088 elif opt == "--title":
89 variables["title"] = string.strip(val)
90 elif opt == "--uplink":
91 uplink = string.strip(val)
92 elif opt == "--uptitle":
93 uptitle = string.strip(val)
94 elif opt == "--iconserver":
95 variables["iconserver"] = string.strip(val) or "."
96 if uplink and uptitle:
97 variables["uplinkalt"] = "up"
98 variables["uplinkicon"] = "up"
99 else:
100 variables["uplinkalt"] = ""
101 variables["uplinkicon"] = "blank"
102 variables["uplink"] = uplink
103 variables["uptitle"] = uptitle
Fred Drake2ef38a71999-02-24 17:33:07 +0000104 if not args:
105 args = ["-"]
106 #
107 # Collect the input data:
108 #
109 nodes = []
110 seqno = 0
Fred Drake7f492ad1999-03-02 16:22:56 +0000111 has_plat_flag = 0
Fred Drake2ef38a71999-02-24 17:33:07 +0000112 for ifn in args:
113 if ifn == "-":
114 ifp = sys.stdin
115 dirname = ''
116 else:
117 ifp = open(ifn)
118 dirname = os.path.dirname(ifn)
119 while 1:
120 line = ifp.readline()
121 if not line:
122 break
123 m = _rx.match(line)
124 if m:
125 # This line specifies a module!
126 basename, modname = m.group(1, 2)
Fred Drake7f492ad1999-03-02 16:22:56 +0000127 has_plat_flag = has_plat_flag or m.group(3)
Fred Drake2ef38a71999-02-24 17:33:07 +0000128 linkfile = os.path.join(dirname, basename)
Fred Drake7f492ad1999-03-02 16:22:56 +0000129 nodes.append(buildindex.Node(
130 '<a href="%s">' % linkfile,
131 "<tt class=module>%s</tt>" % modname,
132 seqno))
Fred Drake2ef38a71999-02-24 17:33:07 +0000133 seqno = seqno + 1
134 ifp.close()
Fred Drake7f492ad1999-03-02 16:22:56 +0000135 #
136 # Generate all output:
137 #
Fred Drake2ef38a71999-02-24 17:33:07 +0000138 num_nodes = len(nodes)
Fred Drake7f492ad1999-03-02 16:22:56 +0000139 # Here's the HTML generation:
Fred Drake5f7832d1999-03-04 21:19:57 +0000140 parts = [HEAD % variables,
141 buildindex.process_nodes(nodes, columns, letters),
142 TAIL % variables,
143 ]
Fred Drake7f492ad1999-03-02 16:22:56 +0000144 if has_plat_flag:
145 parts.insert(1, PLAT_DISCUSS)
146 html = string.join(parts, '')
Fred Drake2ef38a71999-02-24 17:33:07 +0000147 program = os.path.basename(sys.argv[0])
148 if outputfile == "-":
149 sys.stdout.write(html)
150 sys.stderr.write("%s: %d index nodes\n" % (program, num_nodes))
151 else:
152 open(outputfile, "w").write(html)
153 print
154 print "%s: %d index nodes" % (program, num_nodes)
155
156
Fred Drake7f492ad1999-03-02 16:22:56 +0000157PLAT_DISCUSS = """
158<p> Some module names are followed by an annotation indicating what
159platform they are available on.</p>
160
Fred Drake2ef38a71999-02-24 17:33:07 +0000161"""
162
Fred Drake5f7832d1999-03-04 21:19:57 +0000163NAVIGATION = """\
Fred Drake2ef38a71999-02-24 17:33:07 +0000164<div class=navigation>
Fred Drake5f7832d1999-03-04 21:19:57 +0000165<table width="100%%" cellpadding=0 cellspacing=2>
Fred Drake2ef38a71999-02-24 17:33:07 +0000166<tr>
Fred Drake2ef38a71999-02-24 17:33:07 +0000167<td><img width=32 height=32 align=bottom border=0 alt=""
Fred Drake5f7832d1999-03-04 21:19:57 +0000168 src="%(iconserver)s/blank.%(imgtype)s"></td>
Fred Drake1acb8741999-03-04 21:33:55 +0000169<td><a href="%(uplink)s"
170 title="%(uptitle)s"><img width=32 height=32 align=bottom border=0
171 alt="%(uplinkalt)s"
172 src="%(iconserver)s/%(uplinkicon)s.%(imgtype)s"></a></td>
Fred Drake2ef38a71999-02-24 17:33:07 +0000173<td><img width=32 height=32 align=bottom border=0 alt=""
Fred Drake5f7832d1999-03-04 21:19:57 +0000174 src="%(iconserver)s/blank.%(imgtype)s"></td>
175<td align=center bgcolor="#99CCFF" width="100%%">
176 <b class=title>%(title)s</b></td>
Fred Drake2ef38a71999-02-24 17:33:07 +0000177<td><img width=32 height=32 align=bottom border=0 alt=""
Fred Drake5f7832d1999-03-04 21:19:57 +0000178 src="%(iconserver)s/blank.%(imgtype)s"></td>
Fred Drake2ef38a71999-02-24 17:33:07 +0000179<td><img width=32 height=32 align=bottom border=0 alt=""
Fred Drake5f7832d1999-03-04 21:19:57 +0000180 src="%(iconserver)s/blank.%(imgtype)s"></td>
181<td><img width=32 height=32 align=bottom border=0 alt=""
182 src="%(iconserver)s/blank.%(imgtype)s"></td>
Fred Drake2ef38a71999-02-24 17:33:07 +0000183</tr></table>
Fred Drake1acb8741999-03-04 21:33:55 +0000184<b class=navlabel>Up:</b> <span class=sectref><a href="%(uplink)s"
185 title="%(uptitle)s">%(uptitle)s</A></span>
186<br></div>
Fred Drake2ef38a71999-02-24 17:33:07 +0000187"""
188
Fred Drake5f7832d1999-03-04 21:19:57 +0000189HEAD = """\
190<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
191<html>
192<head>
193<title>Global Module Index</title>
194<meta name="description" content="%(title)s">
195<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
196<link rel="STYLESHEET" href="lib/lib.css">
197</head>
198<body bgcolor=white>
199""" + NAVIGATION + """\
Fred Drake1acb8741999-03-04 21:33:55 +0000200<hr>
Fred Drake5f7832d1999-03-04 21:19:57 +0000201
202<h2>%(title)s</h2>
203
204"""
205
Fred Drake1acb8741999-03-04 21:33:55 +0000206TAIL = "<hr>\n" + NAVIGATION + """\
Fred Drake5f7832d1999-03-04 21:19:57 +0000207%(address)s</body>
208</html>
209"""
Fred Drake2ef38a71999-02-24 17:33:07 +0000210
211if __name__ == "__main__":
212 main()