4 """usage: %(program)s [options] file...
9 -a addr Set the address text to include at the end of the generated
10 HTML; this should be used for contact information.
12 -c cols Set the number of columns each index section should be
13 displayed in. The default is 1.
15 -h Display this help message.
17 -l Split the output into sections by letter.
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
24 --uplink url Set the upward link URL. The default is './'.
25 --uptitle str Set the upward link title. The default is 'Python
32 from xml
.sax
.saxutils
import quoteattr
38 class IndexOptions(support
.Options
):
42 support
.Options
.__init
__(self
)
43 self
.add_args("l", ["letters"])
46 def handle_option(self
, opt
, val
):
47 if opt
in ("-l", "--letters"):
51 program
= os
.path
.basename(sys
.argv
[0])
52 print __doc__
% {"program": program
}
55 ('author', 'acks.html', 'Acknowledgements'),
56 ('help', 'about.html', 'About the Python Documentation'),
60 header
= support
.Options
.get_header(self
)
62 for rel
, href
, title
in self
.links
:
63 s
+= '<link rel="%s" href="%s"' % (rel
, href
)
65 s
+= ' title=' + quoteattr(title
)
67 return header
.replace("<link ", s
+ "<link ", 1)
70 class Node(buildindex
.Node
):
71 def __init__(self
, link
, str, seqno
, platinfo
):
72 self
.annotation
= platinfo
or None
73 if str[0][-5:] == "</tt>":
76 buildindex
.Node
.__init
__(self
, link
, self
.modname
, seqno
)
78 s
= '<tt class="module">%s</tt> %s' \
79 % (self
.modname
, self
.annotation
)
81 s
= '<tt class="module">%s</tt>' % str
86 return '<tt class="module">%s</tt> %s' \
87 % (self
.modname
, self
.annotation
)
89 return '<tt class="module">%s</tt>' % self
.modname
92 "<dt><a href=['\"](module-.*\.html)(?:#l2h-\d+)?['\"]>"
93 "<tt class=['\"]module['\"]>([a-zA-Z_][a-zA-Z0-9_.]*)</tt>\s*(<em>"
94 "\(<span class=['\"]platform['\"]>.*</span>\)</em>)?</a>")
97 options
= IndexOptions()
98 options
.variables
["title"] = "Global Module Index"
99 options
.parse(sys
.argv
[1:])
104 # Collect the input data:
114 dirname
= os
.path
.dirname(ifn
)
116 line
= ifp
.readline()
121 # This line specifies a module!
122 basename
, modname
, platinfo
= m
.group(1, 2, 3)
123 has_plat_flag
= has_plat_flag
or platinfo
124 linkfile
= os
.path
.join(dirname
, basename
)
125 nodes
.append(Node('<a href="%s">' % linkfile
, modname
,
126 len(nodes
), platinfo
))
129 # Generate all output:
131 num_nodes
= len(nodes
)
132 # Here's the HTML generation:
133 parts
= [options
.get_header(),
134 buildindex
.process_nodes(nodes
, options
.columns
, options
.letters
),
135 options
.get_footer(),
138 parts
.insert(1, PLAT_DISCUSS
)
139 html
= ''.join(parts
)
140 program
= os
.path
.basename(sys
.argv
[0])
141 fp
= options
.get_output_file()
142 fp
.write(html
.rstrip() + "\n")
143 if options
.outputfile
== "-":
144 sys
.stderr
.write("%s: %d index nodes\n" % (program
, num_nodes
))
147 print "%s: %d index nodes" % (program
, num_nodes
)
151 <p> Some module names are followed by an annotation indicating what
152 platform they are available on.</p>
157 if __name__
== "__main__":