2016-01-23 21:28:29 +01:00
|
|
|
#!/usr/bin/env python
|
2010-04-27 08:56:47 +02:00
|
|
|
#
|
2010-02-09 16:15:29 +01:00
|
|
|
# kconfig2wiki - Kconfig to MediaWiki converter for
|
2017-06-04 04:05:42 +02:00
|
|
|
# https://www.coreboot.org/coreboot_Options
|
2010-02-09 16:15:29 +01:00
|
|
|
# based on http://landley.net/kdocs/make/menuconfig2html.py
|
2010-04-27 08:56:47 +02:00
|
|
|
#
|
2010-02-09 16:15:29 +01:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; version 2 of the License
|
2010-04-27 08:56:47 +02:00
|
|
|
#
|
2010-02-09 16:15:29 +01:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2010-04-27 08:56:47 +02:00
|
|
|
#
|
2010-02-09 16:15:29 +01:00
|
|
|
|
2015-05-06 01:20:07 +02:00
|
|
|
import glob
|
|
|
|
|
2010-02-09 16:15:29 +01:00
|
|
|
helplen = 0
|
|
|
|
extra_chapters = 0
|
|
|
|
|
|
|
|
##
|
|
|
|
## Remove quotes from Kconfig string options
|
|
|
|
##
|
|
|
|
def zapquotes(str):
|
|
|
|
if str[0]=='"': str = str[1:str.rfind('"')]
|
|
|
|
return str
|
|
|
|
|
|
|
|
##
|
|
|
|
## Escape HTML special characters
|
|
|
|
##
|
|
|
|
def htmlescape(str):
|
|
|
|
return str.strip().replace("&","&").replace("<","<").replace(">",">")
|
|
|
|
|
|
|
|
##
|
|
|
|
## Process Kconfig file
|
|
|
|
##
|
|
|
|
def readfile(filename):
|
|
|
|
import sys
|
|
|
|
global helplen
|
|
|
|
|
|
|
|
source=filename.replace("src/","").replace("/Kconfig","").replace("Kconfig","toplevel")
|
|
|
|
|
|
|
|
try:
|
|
|
|
lines = open(filename).read().split("\n")
|
|
|
|
except IOError:
|
|
|
|
sys.stderr.write("File %s missing\n" % filename)
|
|
|
|
return
|
|
|
|
config = None
|
|
|
|
description = None
|
|
|
|
configtype = None
|
|
|
|
for i in lines:
|
|
|
|
if helplen:
|
|
|
|
i = i.expandtabs()
|
|
|
|
if not len(i) or i[:helplen].isspace():
|
2018-06-07 13:54:57 +02:00
|
|
|
sys.stdout.write("%s<br />\n" % htmlescape(i))
|
2010-02-09 16:15:29 +01:00
|
|
|
continue
|
|
|
|
else:
|
|
|
|
helplen = 0
|
2018-06-07 13:54:57 +02:00
|
|
|
sys.stdout.write("</td></tr>\n")
|
2010-02-09 16:15:29 +01:00
|
|
|
|
|
|
|
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"):
|
|
|
|
configtype = htmlescape(zapquotes(words[0]))
|
|
|
|
if len(words)>1: description = htmlescape(zapquotes(words[1]))
|
|
|
|
elif words[0]=="prompt":
|
|
|
|
description = htmlescape(zapquotes(words[1]))
|
|
|
|
elif words[0] in ("help", "---help---"):
|
2018-06-07 13:54:57 +02:00
|
|
|
sys.stdout.write("<tr bgcolor=\"#eeeeee\">\n")
|
|
|
|
sys.stdout.write("<td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>\n" % (config,source,configtype,description) )
|
2010-02-09 16:15:29 +01:00
|
|
|
helplen = len(i[:i.find(words[0])].expandtabs())
|
|
|
|
elif words[0] == "comment":
|
2018-06-07 13:54:57 +02:00
|
|
|
sys.stdout.write("<tr bgcolor=\"#eeeeee\">\n")
|
2018-06-07 13:59:14 +02:00
|
|
|
sys.stdout.write("<td></td><td>%s</td><td>(comment)</td><td></td><td>%s</td></tr>\n" % (source, htmlescape(zapquotes(words[1]))))
|
2010-02-09 16:15:29 +01:00
|
|
|
elif words[0]=="menu":
|
|
|
|
if len(words)>1:
|
|
|
|
temp = htmlescape(zapquotes(words[1]))
|
2018-06-07 13:54:57 +02:00
|
|
|
sys.stdout.write("<tr bgcolor=\"#6699dd\">\n")
|
|
|
|
sys.stdout.write("<td colspan=5>Menu: %s</td></tr>\n" % temp)
|
2010-02-09 16:15:29 +01:00
|
|
|
elif words[0] == "endmenu":
|
|
|
|
sys.stdout.write("\n")
|
|
|
|
elif words[0] == "source":
|
|
|
|
fn=zapquotes(words[1])
|
2015-05-06 01:20:07 +02:00
|
|
|
for name in glob.glob(fn):
|
|
|
|
readfile(name)
|
2010-02-09 16:15:29 +01:00
|
|
|
elif words[0] in ("default","depends", "select", "if", "endif", "#"): pass
|
|
|
|
#else: sys.stderr.write("unknown: %s\n" % i)
|
2018-06-07 13:54:57 +02:00
|
|
|
if helplen: sys.stdout.write("</td></tr>\n")
|
2010-02-09 16:15:29 +01:00
|
|
|
|
|
|
|
def main():
|
|
|
|
import sys, time
|
|
|
|
|
|
|
|
if len(sys.argv)!=3:
|
|
|
|
sys.stderr.write("Usage: kconfig2wiki kconfigfile version\n")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
sys.stdout.write("This is an automatically generated list of '''coreboot compile-time options'''.\n")
|
2016-02-19 11:58:16 +01:00
|
|
|
sys.stdout.write("\nLast update: %s\n" % sys.argv[2])
|
2018-06-07 13:54:57 +02:00
|
|
|
sys.stdout.write("<table border=\"0\" style=\"font-size: smaller\">\n");
|
|
|
|
sys.stdout.write("<tr bgcolor=\"#6699dd\">\n")
|
|
|
|
sys.stdout.write("<td align=\"left\">Option</td>\n")
|
|
|
|
sys.stdout.write("<td align=\"left\">Source</td>\n")
|
|
|
|
sys.stdout.write("<td align=\"left\">Format</td>\n")
|
|
|
|
sys.stdout.write("<td align=\"left\">Short Description</td>\n")
|
|
|
|
sys.stdout.write("<td align=\"left\">Description</td></tr>\n")
|
2010-02-09 16:15:29 +01:00
|
|
|
readfile(sys.argv[1])
|
2018-06-07 13:54:57 +02:00
|
|
|
sys.stdout.write("</table>\n")
|
2010-02-09 16:15:29 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|