blob: 257e30aa01858de67a82c33385e329e274748410 [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
Fred Drake2ef38a71999-02-24 17:33:07 +000029import os
30import re
31import string
Fred Drake01a110b2000-10-05 05:14:26 +000032import support
Fred Drake2ef38a71999-02-24 17:33:07 +000033import sys
34
35
Fred Drake01a110b2000-10-05 05:14:26 +000036class IndexOptions(support.Options):
37 def __init__(self):
38 support.Options.__init__(self)
39 self.add_args("l", ["letters"])
40 self.letters = 0
Fred Drake5f7832d1999-03-04 21:19:57 +000041
Fred Drake01a110b2000-10-05 05:14:26 +000042 def handle_option(self, opt, val):
43 if opt in ("-l", "--letters"):
44 self.letters = 1
Fred Drake5f7832d1999-03-04 21:19:57 +000045
Fred Drake01a110b2000-10-05 05:14:26 +000046 def usage(self):
47 program = os.path.basename(sys.argv[0])
48 print __doc__ % {"program": program}
Fred Drake5f7832d1999-03-04 21:19:57 +000049
50
Fred Drake2ef38a71999-02-24 17:33:07 +000051_rx = re.compile(
Fred Drakeba828782000-04-03 04:19:14 +000052 "<dt><a href='(module-.*\.html)#l2h-\d+'><tt class='module'>"
53 "([a-zA-Z_][a-zA-Z0-9_.]*</tt>(\s*<em>"
54 "\(<span class='platform'>.*</span>\)</em>)?)</a>")
Fred Drake2ef38a71999-02-24 17:33:07 +000055
56def main():
Fred Drake01a110b2000-10-05 05:14:26 +000057 options = IndexOptions()
58 options.variables["title"] = "Global Module Index"
59 options.parse(sys.argv[1:])
60 args = options.args
Fred Drake2ef38a71999-02-24 17:33:07 +000061 if not args:
62 args = ["-"]
63 #
64 # Collect the input data:
65 #
66 nodes = []
67 seqno = 0
Fred Drake7f492ad1999-03-02 16:22:56 +000068 has_plat_flag = 0
Fred Drake2ef38a71999-02-24 17:33:07 +000069 for ifn in args:
70 if ifn == "-":
71 ifp = sys.stdin
72 dirname = ''
73 else:
74 ifp = open(ifn)
75 dirname = os.path.dirname(ifn)
76 while 1:
77 line = ifp.readline()
78 if not line:
79 break
80 m = _rx.match(line)
81 if m:
82 # This line specifies a module!
83 basename, modname = m.group(1, 2)
Fred Drake7f492ad1999-03-02 16:22:56 +000084 has_plat_flag = has_plat_flag or m.group(3)
Fred Drake2ef38a71999-02-24 17:33:07 +000085 linkfile = os.path.join(dirname, basename)
Fred Drake7f492ad1999-03-02 16:22:56 +000086 nodes.append(buildindex.Node(
87 '<a href="%s">' % linkfile,
88 "<tt class=module>%s</tt>" % modname,
89 seqno))
Fred Drake2ef38a71999-02-24 17:33:07 +000090 seqno = seqno + 1
91 ifp.close()
Fred Drake7f492ad1999-03-02 16:22:56 +000092 #
93 # Generate all output:
94 #
Fred Drake2ef38a71999-02-24 17:33:07 +000095 num_nodes = len(nodes)
Fred Drake7f492ad1999-03-02 16:22:56 +000096 # Here's the HTML generation:
Fred Drake01a110b2000-10-05 05:14:26 +000097 parts = [options.get_header(),
98 buildindex.process_nodes(nodes, options.columns, options.letters),
99 options.get_footer(),
Fred Drake5f7832d1999-03-04 21:19:57 +0000100 ]
Fred Drake7f492ad1999-03-02 16:22:56 +0000101 if has_plat_flag:
102 parts.insert(1, PLAT_DISCUSS)
103 html = string.join(parts, '')
Fred Drake2ef38a71999-02-24 17:33:07 +0000104 program = os.path.basename(sys.argv[0])
Fred Drake01a110b2000-10-05 05:14:26 +0000105 fp = options.get_output_file()
106 print >>fp, html.rstrip()
107 if options.outputfile == "-":
108 print >>sys.stderr, "%s: %d index nodes" % (program, num_nodes)
Fred Drake2ef38a71999-02-24 17:33:07 +0000109 else:
Fred Drake2ef38a71999-02-24 17:33:07 +0000110 print
111 print "%s: %d index nodes" % (program, num_nodes)
112
113
Fred Drake7f492ad1999-03-02 16:22:56 +0000114PLAT_DISCUSS = """
115<p> Some module names are followed by an annotation indicating what
116platform they are available on.</p>
117
Fred Drake2ef38a71999-02-24 17:33:07 +0000118"""
119
Fred Drake2ef38a71999-02-24 17:33:07 +0000120
121if __name__ == "__main__":
122 main()