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=",
23 "title=", "uplink=", "uptitle="]
29 uptitle
= "Python Documentation Index"
31 # The "Aesop Meta Tag" is poorly described, and may only be used
32 # by the Aesop search engine (www.aesop.com), but doesn't hurt.
34 # There are a number of values this may take to roughly categorize
35 # a page. A page should be marked according to its primary
36 # category. Known values are:
37 # 'personal' -- personal-info
38 # 'information' -- information
39 # 'interactive' -- interactive media
40 # 'multimedia' -- multimedia presenetation (non-sales)
41 # 'sales' -- sales material
42 # 'links' -- links to other information pages
44 # Setting the aesop_type value to one of these strings will cause
45 # get_header() to add the appropriate <meta> tag to the <head>.
51 self
.variables
= {"address": "",
52 "iconserver": "icons",
54 "title": "Global Module Index",
57 def add_args(self
, short
=None, long=None):
59 self
.__short
_args
= self
.__short
_args
+ short
61 self
.__long
_args
= self
.__long
_args
+ long
63 def parse(self
, args
):
65 opts
, args
= getopt
.getopt(args
, self
.__short
_args
,
68 sys
.stdout
= sys
.stderr
71 self
.args
= self
.args
+ args
73 if opt
in ("-a", "--address"):
74 val
= string
.strip(val
)
76 val
= "<address>\n%s\n</address>\n" % val
77 self
.variables
["address"] = val
78 elif opt
in ("-h", "--help"):
81 elif opt
in ("-o", "--output"):
83 elif opt
in ("-c", "--columns"):
84 self
.columns
= int(val
)
85 elif opt
== "--title":
86 self
.variables
["title"] = val
.strip()
87 elif opt
== "--uplink":
88 self
.uplink
= val
.strip()
89 elif opt
== "--uptitle":
90 self
.uptitle
= val
.strip()
91 elif opt
== "--iconserver":
92 self
.variables
["iconserver"] = val
.strip() or "."
94 self
.handle_option(opt
, val
)
95 if self
.uplink
and self
.uptitle
:
96 self
.variables
["uplinkalt"] = "up"
97 self
.variables
["uplinkicon"] = "up"
99 self
.variables
["uplinkalt"] = ""
100 self
.variables
["uplinkicon"] = "blank"
101 self
.variables
["uplink"] = self
.uplink
102 self
.variables
["uptitle"] = self
.uptitle
104 def handle_option(self
, opt
, val
):
105 raise getopt
.error("option %s not recognized" % opt
)
107 def get_header(self
):
108 s
= HEAD
% self
.variables
111 link
= ('<link rel="up" href="%s" title="%s">'
112 % (self
.uplink
, self
.uptitle
))
114 link
= '<link rel="up" href="%s">' % self
.uplink
115 repl
= " %s\n</head>" % link
116 s
= s
.replace("</head>", repl
, 1)
118 meta
= '\n <meta name="aesop" content="%s">'
119 # Insert this in the middle of the head that's been
120 # generated so far, keeping <meta> and <link> elements in
122 s
= s
.replace("<link ", meta
+ "<link ", 1)
125 def get_footer(self
):
126 return TAIL
% self
.variables
128 def get_output_file(self
, filename
=None):
130 filename
= self
.outputfile
134 return open(filename
, "w")
138 <div class="navigation">
139 <table width="100%%" cellpadding="0" cellspacing="2">
141 <td><img width="32" height="32" align="bottom" border="0" alt=""
142 src="%(iconserver)s/blank.%(imgtype)s"></td>
143 <td><a href="%(uplink)s"
144 title="%(uptitle)s"><img width="32" height="32" align="bottom" border="0"
146 src="%(iconserver)s/%(uplinkicon)s.%(imgtype)s"></a></td>
147 <td><img width="32" height="32" align="bottom" border="0" alt=""
148 src="%(iconserver)s/blank.%(imgtype)s"></td>
149 <td align="center" width="100%%">%(title)s</td>
150 <td><img width="32" height="32" align="bottom" border="0" alt=""
151 src="%(iconserver)s/blank.%(imgtype)s"></td>
152 <td><img width="32" height="32" align="bottom" border="0" alt=""
153 src="%(iconserver)s/blank.%(imgtype)s"></td>
154 <td><img width="32" height="32" align="bottom" border="0" alt=""
155 src="%(iconserver)s/blank.%(imgtype)s"></td>
157 <b class="navlabel">Up:</b> <span class="sectref"><a href="%(uplink)s"
158 title="%(uptitle)s">%(uptitle)s</A></span>
163 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
166 <title>%(title)s</title>
167 <meta name="description" content="%(title)s">
168 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
169 <link rel="STYLESHEET" href="lib/lib.css">
172 ''' + NAVIGATION
+ '''\
179 TAIL
= "<hr>\n" + NAVIGATION
+ '''\