Fred Drake | 2ef38a7 | 1999-02-24 17:33:07 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | # -*- Python -*- |
| 3 | |
| 4 | import buildindex |
| 5 | import getopt |
| 6 | import os |
| 7 | import re |
| 8 | import string |
| 9 | import sys |
| 10 | |
| 11 | |
| 12 | _rx = re.compile( |
Fred Drake | 7f492ad | 1999-03-02 16:22:56 +0000 | [diff] [blame^] | 13 | '<dt><a href="(module-.*\.html)">' |
| 14 | '([a-zA-Z_][a-zA-Z0-9_.]*(\s*<em>\(.*\)</em>)?)</a>') |
Fred Drake | 2ef38a7 | 1999-02-24 17:33:07 +0000 | [diff] [blame] | 15 | |
| 16 | def 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 Drake | 7f492ad | 1999-03-02 16:22:56 +0000 | [diff] [blame^] | 36 | has_plat_flag = 0 |
Fred Drake | 2ef38a7 | 1999-02-24 17:33:07 +0000 | [diff] [blame] | 37 | 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 Drake | 7f492ad | 1999-03-02 16:22:56 +0000 | [diff] [blame^] | 52 | has_plat_flag = has_plat_flag or m.group(3) |
Fred Drake | 2ef38a7 | 1999-02-24 17:33:07 +0000 | [diff] [blame] | 53 | linkfile = os.path.join(dirname, basename) |
Fred Drake | 7f492ad | 1999-03-02 16:22:56 +0000 | [diff] [blame^] | 54 | nodes.append(buildindex.Node( |
| 55 | '<a href="%s">' % linkfile, |
| 56 | "<tt class=module>%s</tt>" % modname, |
| 57 | seqno)) |
Fred Drake | 2ef38a7 | 1999-02-24 17:33:07 +0000 | [diff] [blame] | 58 | seqno = seqno + 1 |
| 59 | ifp.close() |
Fred Drake | 7f492ad | 1999-03-02 16:22:56 +0000 | [diff] [blame^] | 60 | # |
| 61 | # Generate all output: |
| 62 | # |
Fred Drake | 2ef38a7 | 1999-02-24 17:33:07 +0000 | [diff] [blame] | 63 | num_nodes = len(nodes) |
Fred Drake | 7f492ad | 1999-03-02 16:22:56 +0000 | [diff] [blame^] | 64 | # 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 Drake | 2ef38a7 | 1999-02-24 17:33:07 +0000 | [diff] [blame] | 69 | 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 | |
| 79 | HEAD = """\ |
| 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 Drake | 7f492ad | 1999-03-02 16:22:56 +0000 | [diff] [blame^] | 111 | |
| 112 | <h2>Global Module Index</h2> |
| 113 | |
| 114 | """ |
| 115 | |
| 116 | PLAT_DISCUSS = """ |
| 117 | <p> Some module names are followed by an annotation indicating what |
| 118 | platform they are available on.</p> |
| 119 | |
Fred Drake | 2ef38a7 | 1999-02-24 17:33:07 +0000 | [diff] [blame] | 120 | """ |
| 121 | |
| 122 | TAIL = """ |
| 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 | |
| 155 | if __name__ == "__main__": |
| 156 | main() |