blob: 448abee3952ba7299c12da3b3eabf214f4ea7ada [file] [log] [blame]
Fred Drakeca2b2e02000-10-05 05:11:57 +00001"""
2"""
3__version__ = '$Revision$'
4
5
6import getopt
7import sys
8
9
10class Options:
11 __short_args = "a:c:ho:"
12 __long_args = [
13 # script controls
14 "columns=", "help", "output=",
15
16 # content components
17 "address=", "iconserver=",
18 "title=", "uplink=", "uptitle="]
19
20 outputfile = "-"
21 columns = 1
22 letters = 0
23 uplink = "./"
24 uptitle = "Python Documentation Index"
25
26 def __init__(self):
27 self.args = []
28 self.variables = {"address": "",
29 "iconserver": "icons",
30 "imgtype": "gif",
31 "title": "Global Module Index",
32 }
33
34 def add_args(self, short=None, long=None):
35 if short:
36 self.__short_args += short
37 if long:
38 self.__long_args += long
39
40 def parse(self, args):
41 try:
42 opts, args = getopt.getopt(args, self.__short_args,
43 self.__long_args)
44 except getopt.error:
45 sys.stdout = sys.stderr
46 self.usage()
47 sys.exit(2)
48 self.args += args
49 for opt, val in opts:
50 if opt in ("-a", "--address"):
51 val = val.strip()
52 if val:
53 val = "<address>\n%s\n</address>\n" % val
54 self.variables["address"] = val
55 elif opt in ("-h", "--help"):
56 self.usage()
57 sys.exit()
58 elif opt in ("-o", "--output"):
59 self.outputfile = val
60 elif opt in ("-c", "--columns"):
61 self.columns = int(val)
62 elif opt == "--title":
63 self.variables["title"] = val.strip()
64 elif opt == "--uplink":
65 self.uplink = val.strip()
66 elif opt == "--uptitle":
67 self.uptitle = val.strip()
68 elif opt == "--iconserver":
69 self.variables["iconserver"] = val.strip() or "."
70 else:
71 self.handle_option(opt, val)
72 if self.uplink and self.uptitle:
73 self.variables["uplinkalt"] = "up"
74 self.variables["uplinkicon"] = "up"
75 else:
76 self.variables["uplinkalt"] = ""
77 self.variables["uplinkicon"] = "blank"
78 self.variables["uplink"] = self.uplink
79 self.variables["uptitle"] = self.uptitle
80
81 def handle_option(self, opt, val):
82 raise getopt.error("option %s not recognized" % opt)
83
84 def get_header(self):
85 return HEAD % self.variables
86
87 def get_footer(self):
88 return TAIL % self.variables
89
90 def get_output_file(self, filename=None):
91 if filename is None:
92 filename = self.outputfile
93 if filename == "-":
94 return sys.stdout
95 else:
96 return open(filename, "w")
97
98
99NAVIGATION = '''\
100<div class="navigation">
101<table width="100%%" cellpadding="0" cellspacing="2">
102<tr>
103<td><img width="32" height="32" align="bottom" border="0" alt=""
104 src="%(iconserver)s/blank.%(imgtype)s"></td>
105<td><a href="%(uplink)s"
106 title="%(uptitle)s"><img width="32" height="32" align="bottom" border="0"
107 alt="%(uplinkalt)s"
108 src="%(iconserver)s/%(uplinkicon)s.%(imgtype)s"></a></td>
109<td><img width="32" height="32" align="bottom" border="0" alt=""
110 src="%(iconserver)s/blank.%(imgtype)s"></td>
111<td align="center" width="100%%">%(title)s</td>
112<td><img width="32" height="32" align="bottom" border="0" alt=""
113 src="%(iconserver)s/blank.%(imgtype)s"></td>
114<td><img width="32" height="32" align="bottom" border="0" alt=""
115 src="%(iconserver)s/blank.%(imgtype)s"></td>
116<td><img width="32" height="32" align="bottom" border="0" alt=""
117 src="%(iconserver)s/blank.%(imgtype)s"></td>
118</tr></table>
119<b class="navlabel">Up:</b> <span class="sectref"><a href="%(uplink)s"
120 title="%(uptitle)s">%(uptitle)s</A></span>
121<br></div>
122'''
123
124HEAD = '''\
125<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
126<html>
127<head>
128 <title>%(title)s</title>
129 <meta name="description" content="%(title)s">
130 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
131 <link rel="STYLESHEET" href="lib/lib.css">
132</head>
133<body>
134''' + NAVIGATION + '''\
135<hr>
136
137<h2>%(title)s</h2>
138
139'''
140
141TAIL = "<hr>\n" + NAVIGATION + '''\
142%(address)s</body>
143</html>
144'''