From 458120dd40db6b4df55a4e96b650e16798ef06a0 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Tue, 3 May 2011 11:25:13 +0000 Subject: add hg and python --- sys/src/cmd/python/Doc/tools/support.py | 202 ++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 sys/src/cmd/python/Doc/tools/support.py (limited to 'sys/src/cmd/python/Doc/tools/support.py') diff --git a/sys/src/cmd/python/Doc/tools/support.py b/sys/src/cmd/python/Doc/tools/support.py new file mode 100644 index 000000000..5b8471aac --- /dev/null +++ b/sys/src/cmd/python/Doc/tools/support.py @@ -0,0 +1,202 @@ +"""Miscellaneous support code shared by some of the tool scripts. + +This includes option parsing code, HTML formatting code, and a couple of +useful helpers. + +""" +__version__ = '$Revision: 37764 $' + + +import getopt +import os.path +import sys + + +class Options: + __short_args = "a:c:ho:" + __long_args = [ + # script controls + "columns=", "help", "output=", + + # content components + "address=", "iconserver=", "favicon=", + "title=", "uplink=", "uptitle=", + "image-type=", + ] + + outputfile = "-" + columns = 1 + letters = 0 + uplink = "index.html" + uptitle = "Python Documentation Index" + favicon = None + + # The "Aesop Meta Tag" is poorly described, and may only be used + # by the Aesop search engine (www.aesop.com), but doesn't hurt. + # + # There are a number of values this may take to roughly categorize + # a page. A page should be marked according to its primary + # category. Known values are: + # 'personal' -- personal-info + # 'information' -- information + # 'interactive' -- interactive media + # 'multimedia' -- multimedia presenetation (non-sales) + # 'sales' -- sales material + # 'links' -- links to other information pages + # + # Setting the aesop_type value to one of these strings will cause + # get_header() to add the appropriate tag to the . + # + aesop_type = None + + def __init__(self): + self.args = [] + self.variables = {"address": "", + "iconserver": "icons", + "imgtype": "png", + "title": "Global Module Index", + } + + def add_args(self, short=None, long=None): + if short: + self.__short_args = self.__short_args + short + if long: + self.__long_args = 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 = 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 "." + elif opt == "--favicon": + self.favicon = val.strip() + elif opt == "--image-type": + self.variables["imgtype"] = val.strip() + 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): + s = HEAD % self.variables + if self.uplink: + if self.uptitle: + link = ('\n ' + '' + % (self.uplink, self.uptitle, + self.uplink, self.uptitle)) + else: + link = ('\n ' + '' + % (self.uplink, self.uplink)) + repl = " %s\n" % link + s = s.replace("", repl, 1) + if self.aesop_type: + meta = '\n ' % self.aesop_type + # Insert this in the middle of the head that's been + # generated so far, keeping and elements in + # neat groups: + s = s.replace("\n ' + % (self.favicon, type)) + s = s.replace(" + + + + + + + + + +
%(uplinkalt)s%(title)s
+Up: %(uptitle)s +
+''' + +HEAD = '''\ + + + + %(title)s + + + + + +''' + NAVIGATION + '''\ +
+ +

%(title)s

+ +''' + +TAIL = "
\n" + NAVIGATION + '''\ +%(address)s + +''' -- cgit v1.2.3