1 """Miscellaneous support code shared by some of the tool scripts.
3 This includes option parsing code, HTML formatting code, and a couple of
7 __version__
= '$Revision$'
16 __short_args
= "a:c:ho:"
19 "columns=", "help", "output=",
22 "address=", "iconserver=", "favicon=",
23 "title=", "uplink=", "uptitle="]
29 uptitle
= "Python Documentation Index"
32 # The "Aesop Meta Tag" is poorly described, and may only be used
33 # by the Aesop search engine (www.aesop.com), but doesn't hurt.
35 # There are a number of values this may take to roughly categorize
36 # a page. A page should be marked according to its primary
37 # category. Known values are:
38 # 'personal' -- personal-info
39 # 'information' -- information
40 # 'interactive' -- interactive media
41 # 'multimedia' -- multimedia presenetation (non-sales)
42 # 'sales' -- sales material
43 # 'links' -- links to other information pages
45 # Setting the aesop_type value to one of these strings will cause
46 # get_header() to add the appropriate <meta> tag to the <head>.
52 self
.variables
= {"address": "",
53 "iconserver": "icons",
55 "title": "Global Module Index",
58 def add_args(self
, short
=None, long=None):
60 self
.__short
_args
= self
.__short
_args
+ short
62 self
.__long
_args
= self
.__long
_args
+ long
64 def parse(self
, args
):
66 opts
, args
= getopt
.getopt(args
, self
.__short
_args
,
69 sys
.stdout
= sys
.stderr
72 self
.args
= self
.args
+ args
74 if opt
in ("-a", "--address"):
77 val
= "<address>\n%s\n</address>\n" % val
78 self
.variables
["address"] = val
79 elif opt
in ("-h", "--help"):
82 elif opt
in ("-o", "--output"):
84 elif opt
in ("-c", "--columns"):
85 self
.columns
= int(val
)
86 elif opt
== "--title":
87 self
.variables
["title"] = val
.strip()
88 elif opt
== "--uplink":
89 self
.uplink
= val
.strip()
90 elif opt
== "--uptitle":
91 self
.uptitle
= val
.strip()
92 elif opt
== "--iconserver":
93 self
.variables
["iconserver"] = val
.strip() or "."
94 elif opt
== "--favicon":
95 self
.favicon
= val
.strip()
97 self
.handle_option(opt
, val
)
98 if self
.uplink
and self
.uptitle
:
99 self
.variables
["uplinkalt"] = "up"
100 self
.variables
["uplinkicon"] = "up"
102 self
.variables
["uplinkalt"] = ""
103 self
.variables
["uplinkicon"] = "blank"
104 self
.variables
["uplink"] = self
.uplink
105 self
.variables
["uptitle"] = self
.uptitle
107 def handle_option(self
, opt
, val
):
108 raise getopt
.error("option %s not recognized" % opt
)
110 def get_header(self
):
111 s
= HEAD
% self
.variables
114 link
= ('<link rel="up" href="%s" title="%s">\n '
115 '<link rel="start" href="%s" title="%s">'
116 % (self
.uplink
, self
.uptitle
,
117 self
.uplink
, self
.uptitle
))
119 link
= ('<link rel="up" href="%s">\n '
120 '<link rel="start" href="%s">'
121 % (self
.uplink
, self
.uplink
))
122 repl
= " %s\n</head>" % link
123 s
= s
.replace("</head>", repl
, 1)
125 meta
= '<meta name="aesop" content="%s">\n ' % self
.aesop_type
126 # Insert this in the middle of the head that's been
127 # generated so far, keeping <meta> and <link> elements in
129 s
= s
.replace("<link ", meta
+ "<link ", 1)
131 ext
= os
.path
.splitext(self
.favicon
)[1]
132 if ext
in (".gif", ".png"):
133 type = ' type="image/%s"' % ext
[1:]
136 link
= ('<link rel="SHORTCUT ICON" href="%s"%s>\n '
137 % (self
.favicon
, type))
138 s
= s
.replace("<link ", link
+ "<link ", 1)
141 def get_footer(self
):
142 return TAIL
% self
.variables
144 def get_output_file(self
, filename
=None):
146 filename
= self
.outputfile
150 return open(filename
, "w")
154 <div class="navigation">
155 <table width="100%%" cellpadding="0" cellspacing="2">
157 <td><img width="32" height="32" align="bottom" border="0" alt=""
158 src="%(iconserver)s/blank.%(imgtype)s"></td>
159 <td><a href="%(uplink)s"
160 title="%(uptitle)s"><img width="32" height="32" align="bottom" border="0"
162 src="%(iconserver)s/%(uplinkicon)s.%(imgtype)s"></a></td>
163 <td><img width="32" height="32" align="bottom" border="0" alt=""
164 src="%(iconserver)s/blank.%(imgtype)s"></td>
165 <td align="center" width="100%%">%(title)s</td>
166 <td><img width="32" height="32" align="bottom" border="0" alt=""
167 src="%(iconserver)s/blank.%(imgtype)s"></td>
168 <td><img width="32" height="32" align="bottom" border="0" alt=""
169 src="%(iconserver)s/blank.%(imgtype)s"></td>
170 <td><img width="32" height="32" align="bottom" border="0" alt=""
171 src="%(iconserver)s/blank.%(imgtype)s"></td>
173 <b class="navlabel">Up:</b> <span class="sectref"><a href="%(uplink)s"
174 title="%(uptitle)s">%(uptitle)s</A></span>
179 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
182 <title>%(title)s</title>
183 <meta name="description" content="%(title)s">
184 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
185 <link rel="STYLESHEET" href="lib/lib.css">
188 ''' + NAVIGATION
+ '''\
195 TAIL
= "<hr>\n" + NAVIGATION
+ '''\