Mercurial > hg > kdocs
view make/menuconfig2html.py @ 29:c91c3395876f
Produce better menuconfig output, now in multiple files and with concise
symbol indexes per architecture, with nested menus displayed as lists.
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 29 Aug 2007 22:42:39 -0500 |
parents | 3c78854053e3 |
children | fc688c499467 |
line wrap: on
line source
#!/usr/bin/python # "boolean" not documented type in kconfig-language.txt line 51 import os,sys if len(sys.argv)!=3: sys.stderr.write("Usage: menuconfig2html.py kconfigfile outdir\n") sys.exit(1) def zapquotes(str): if str[0]=='"': str = str[1:str.rfind('"')] return str def htmlescape(str): return str.strip().replace("&","&").replace("<","<").replace(">",">") helplen = 0 def readfile(filename): global helplen myfn="%s.html" % "-".join(filename.split("/")) out=open("%s/%s.html" % (sys.argv[2], myfn),"w") #sys.stderr.write("Reading %s\n" % filename) try: lines = open(filename).read().split("\n") except IOError: sys.stderr.write("File %s missing\n" % filename) return out.write("<html>\n") config = None description = None for i in lines: if helplen: i = i.expandtabs() if not len(i) or i[:helplen].isspace(): out.write("%s\n" % htmlescape(i)) continue else: helplen = 0 out.write("</pre></blockquote>\n") words = i.strip().split(None,1) if not len(words): continue if words[0] in ("config", "menuconfig"): config = words[1] description = "" elif words[0] in ("bool", "boolean", "tristate", "string", "hex", "int"): if len(words)>1: description = htmlescape(zapquotes(words[1])) elif words[0]=="prompt": description = htmlescape(zapquotes(words[1])) elif words[0] in ("help", "---help---"): out.write('<a name="%s"><h2>%s</h2>\n<h3>%s</h3>\n<blockquote><pre>' % (config,config,description)) sys.stdout.write('<li><a href="%s#%s">%s</a> %s</li>\n' % (myfn,config,config,description)) helplen = len(i[:i.find(words[0])].expandtabs()) elif words[0] == "comment": out.write("<h3>%s</h3>\n" % htmlescape(zapquotes(words[1]))) elif words[0]=="menu": out.write("<hr>\n") if len(words)>1: temp = htmlescape(zapquotes(words[1])) out.write("<h1>Menu: %s</h1>\n" % temp) sys.stdout.write("<h2>Menu [%s]</h2>\n" % temp) sys.stdout.write("<ul>\n") elif words[0] == "endmenu": out.write("<hr>\n") sys.stdout.write("</ul>\n") elif words[0] == "source": fn=zapquotes(words[1]) readfile(fn) out.write('<h2><a href="%(link)s">%(link)s</a></h2>\n' % {"link": "%s/%s.html" % (sys.argv[2], "-".join(fn.split("/")))}) elif words[0] in ("default","depends", "select", "if", "endif", "#"): pass #else: sys.stderr.write("unknown: %s\n" % i) if helplen: out.write("</pre></blockquote>\n") out.write("</html>\n") sys.stdout.write("<html>\n<ul>\n") readfile(sys.argv[1]) sys.stdout.write("</ul>\n</html>\n")