From ca2b2e04e12714ede1127071e08686479f875db7 Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Thu, 5 Oct 2000 05:11:57 +0000 Subject: [PATCH] Factor out some of the presentation and shared code from mkmodindex and a mkackshtml (not yet checked in). --- Doc/tools/support.py | 144 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 Doc/tools/support.py diff --git a/Doc/tools/support.py b/Doc/tools/support.py new file mode 100644 index 00000000000..448abee3952 --- /dev/null +++ b/Doc/tools/support.py @@ -0,0 +1,144 @@ +""" +""" +__version__ = '$Revision$' + + +import getopt +import sys + + +class Options: + __short_args = "a:c:ho:" + __long_args = [ + # script controls + "columns=", "help", "output=", + + # content components + "address=", "iconserver=", + "title=", "uplink=", "uptitle="] + + outputfile = "-" + columns = 1 + letters = 0 + uplink = "./" + uptitle = "Python Documentation Index" + + def __init__(self): + self.args = [] + self.variables = {"address": "", + "iconserver": "icons", + "imgtype": "gif", + "title": "Global Module Index", + } + + def add_args(self, short=None, long=None): + if short: + self.__short_args += short + if long: + self.__long_args += long + + def parse(self, args): + try: + opts, args = getopt.getopt(args, self.__short_args, + self.__long_args) + except getopt.error: + sys.stdout = sys.stderr + self.usage() + sys.exit(2) + self.args += args + for opt, val in opts: + if opt in ("-a", "--address"): + val = val.strip() + if val: + val = "
\n%s\n
\n" % val + self.variables["address"] = val + elif opt in ("-h", "--help"): + self.usage() + sys.exit() + elif opt in ("-o", "--output"): + self.outputfile = val + elif opt in ("-c", "--columns"): + self.columns = int(val) + elif opt == "--title": + self.variables["title"] = val.strip() + elif opt == "--uplink": + self.uplink = val.strip() + elif opt == "--uptitle": + self.uptitle = val.strip() + elif opt == "--iconserver": + self.variables["iconserver"] = val.strip() or "." + else: + self.handle_option(opt, val) + if self.uplink and self.uptitle: + self.variables["uplinkalt"] = "up" + self.variables["uplinkicon"] = "up" + else: + self.variables["uplinkalt"] = "" + self.variables["uplinkicon"] = "blank" + self.variables["uplink"] = self.uplink + self.variables["uptitle"] = self.uptitle + + def handle_option(self, opt, val): + raise getopt.error("option %s not recognized" % opt) + + def get_header(self): + return HEAD % self.variables + + def get_footer(self): + return TAIL % self.variables + + def get_output_file(self, filename=None): + if filename is None: + filename = self.outputfile + if filename == "-": + return sys.stdout + else: + return open(filename, "w") + + +NAVIGATION = '''\ + +''' + +HEAD = '''\ + + + + %(title)s + + + + + +''' + NAVIGATION + '''\ +
+ +

%(title)s

+ +''' + +TAIL = "
\n" + NAVIGATION + '''\ +%(address)s + +'''