diff options
author | Patrick Georgi <pgeorgi@chromium.org> | 2018-06-07 13:54:57 +0200 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2018-06-11 21:18:09 +0000 |
commit | 446f77daad4184c745575f57615960fd33641b40 (patch) | |
tree | 28f205432af4c8d2c9b88e8822cc8eb4cf42b88d /util/optionlist/kconfig2html | |
parent | d8214d7e0e3083de30f269d720ab816736ed79eb (diff) | |
download | coreboot-446f77daad4184c745575f57615960fd33641b40.tar.xz |
util/optionlist: move kconfig2wiki to kconfig2html and adapt to html
This also removes a "chapters mode" that we never used.
Change-Id: Ib301e2f4db0b9678081fa987a5dcc7108bb103a4
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-on: https://review.coreboot.org/26944
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Martin Roth <martinroth@google.com>
Diffstat (limited to 'util/optionlist/kconfig2html')
-rwxr-xr-x | util/optionlist/kconfig2html | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/util/optionlist/kconfig2html b/util/optionlist/kconfig2html new file mode 100755 index 0000000000..defd35df82 --- /dev/null +++ b/util/optionlist/kconfig2html @@ -0,0 +1,118 @@ +#!/usr/bin/env python +# +# kconfig2wiki - Kconfig to MediaWiki converter for +# https://www.coreboot.org/coreboot_Options +# +# Copyright (C) 2010 coresystems GmbH +# based on http://landley.net/kdocs/make/menuconfig2html.py +# Copyright (C) by Rob Landley +# +# 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 +# +# 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. +# + +import glob + +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(): + sys.stdout.write("%s<br />\n" % htmlescape(i)) + continue + else: + helplen = 0 + sys.stdout.write("</td></tr>\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"): + 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---"): + 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) ) + helplen = len(i[:i.find(words[0])].expandtabs()) + elif words[0] == "comment": + sys.stdout.write("<tr bgcolor=\"#eeeeee\">\n") + sys.stdout.write("<td></td><td></td><td>(comment)</td><td></td><td>%s</td></tr>\n" % htmlescape(zapquotes(words[1]))) + elif words[0]=="menu": + if len(words)>1: + temp = htmlescape(zapquotes(words[1])) + sys.stdout.write("<tr bgcolor=\"#6699dd\">\n") + sys.stdout.write("<td colspan=5>Menu: %s</td></tr>\n" % temp) + elif words[0] == "endmenu": + sys.stdout.write("\n") + elif words[0] == "source": + fn=zapquotes(words[1]) + for name in glob.glob(fn): + readfile(name) + elif words[0] in ("default","depends", "select", "if", "endif", "#"): pass + #else: sys.stderr.write("unknown: %s\n" % i) + if helplen: sys.stdout.write("</td></tr>\n") + +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") + sys.stdout.write("\nLast update: %s\n" % sys.argv[2]) + 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") + readfile(sys.argv[1]) + sys.stdout.write("</table>\n") + +if __name__ == "__main__": + main() |