annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
1 #!/usr/bin/python
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
2
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 # "boolean" not documented type in kconfig-language.txt line 51
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
4
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
5 import os,sys
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
6
29
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
7 if len(sys.argv)!=3:
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
8 sys.stderr.write("Usage: menuconfig2html.py kconfigfile outdir\n")
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
9 sys.exit(1)
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
10
26
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
11 def zapquotes(str):
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
12 if str[0]=='"': str = str[1:str.rfind('"')]
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
13 return str
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
14
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
15 def htmlescape(str):
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
16 return str.strip().replace("&","&amp;").replace("<","&lt;").replace(">","&gt;")
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
17
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
18 helplen = 0
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
19
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 def readfile(filename):
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
21 global helplen
29
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
22
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
23 myfn="%s.html" % "-".join(filename.split("/"))
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
24
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
25 out=open("%s/%s.html" % (sys.argv[2], myfn),"w")
26
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
26 #sys.stderr.write("Reading %s\n" % filename)
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
27 try:
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
28 lines = open(filename).read().split("\n")
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
29 except IOError:
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
30 sys.stderr.write("File %s missing\n" % filename)
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
31 return
29
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
32 out.write("<html>\n")
26
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
33 config = None
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
34 description = None
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
35 for i in lines:
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
36 if helplen:
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
37 i = i.expandtabs()
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
38 if not len(i) or i[:helplen].isspace():
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
39 out.write("%s\n" % htmlescape(i))
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
40 continue
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
41 else:
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
42 helplen = 0
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
43 out.write("</pre></blockquote>\n")
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
44
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
45 words = i.strip().split(None,1)
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
46 if not len(words): continue
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
47
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
48 if words[0] in ("config", "menuconfig"):
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
49 config = words[1]
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
50 description = ""
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
51 elif words[0] in ("bool", "boolean", "tristate", "string", "hex", "int"):
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
52 if len(words)>1: description = htmlescape(zapquotes(words[1]))
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
53 elif words[0]=="prompt":
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
54 description = htmlescape(zapquotes(words[1]))
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
55 elif words[0] in ("help", "---help---"):
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
56 out.write('<a name="%s"><h2>%s</h2>\n<h3>%s</h3>\n<blockquote><pre>' % (config,config,description))
29
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
57 sys.stdout.write('<li><a href="%s#%s">%s</a> %s</li>\n' % (myfn,config,config,description))
26
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
58 helplen = len(i[:i.find(words[0])].expandtabs())
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
59 elif words[0] == "comment":
29
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
60 out.write("<h3>%s</h3>\n" % htmlescape(zapquotes(words[1])))
26
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
61 elif words[0]=="menu":
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
62 out.write("<hr>\n")
29
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
63 if len(words)>1:
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
64 temp = htmlescape(zapquotes(words[1]))
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
65 out.write("<h1>Menu: %s</h1>\n" % temp)
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
66 sys.stdout.write("<h2>Menu [%s]</h2>\n" % temp)
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
67 sys.stdout.write("<ul>\n")
26
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
68 elif words[0] == "endmenu":
29
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
69 out.write("<hr>\n")
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
70 sys.stdout.write("</ul>\n")
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
71 elif words[0] == "source":
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
72 fn=zapquotes(words[1])
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
73 readfile(fn)
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
74 out.write('<h2><a href="%(link)s">%(link)s</a></h2>\n' % {"link": "%s/%s.html" % (sys.argv[2], "-".join(fn.split("/")))})
26
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
75 elif words[0] in ("default","depends", "select", "if", "endif", "#"): pass
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
76 #else: sys.stderr.write("unknown: %s\n" % i)
29
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
77 if helplen: out.write("</pre></blockquote>\n")
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
78 out.write("</html>\n")
26
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
79
29
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
80 sys.stdout.write("<html>\n<ul>\n")
26
3c78854053e3 A script to convert menuconfig to html. Have make.sh call it for all $ARCH.
Rob Landley <rob@landley.net>
parents:
diff changeset
81 readfile(sys.argv[1])
29
c91c3395876f Produce better menuconfig output, now in multiple files and with concise
Rob Landley <rob@landley.net>
parents: 26
diff changeset
82 sys.stdout.write("</ul>\n</html>\n")