Stefan Reinauer | f64b42e | 2010-02-09 15:15:29 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 2 | # |
Stefan Reinauer | f64b42e | 2010-02-09 15:15:29 +0000 | [diff] [blame] | 3 | # kconfig2wiki - Kconfig to MediaWiki converter for |
| 4 | # http://www.coreboot.org/Coreboot_Options |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 5 | # |
Stefan Reinauer | f64b42e | 2010-02-09 15:15:29 +0000 | [diff] [blame] | 6 | # Copyright (C) 2010 coresystems GmbH |
| 7 | # based on http://landley.net/kdocs/make/menuconfig2html.py |
| 8 | # Copyright (C) by Rob Landley |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 9 | # |
Stefan Reinauer | f64b42e | 2010-02-09 15:15:29 +0000 | [diff] [blame] | 10 | # This program is free software; you can redistribute it and/or modify |
| 11 | # it under the terms of the GNU General Public License as published by |
| 12 | # the Free Software Foundation; version 2 of the License |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 13 | # |
Stefan Reinauer | f64b42e | 2010-02-09 15:15:29 +0000 | [diff] [blame] | 14 | # This program is distributed in the hope that it will be useful, |
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | # GNU General Public License for more details. |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 18 | # |
Stefan Reinauer | f64b42e | 2010-02-09 15:15:29 +0000 | [diff] [blame] | 19 | |
Stefan Reinauer | 0a52468 | 2015-05-05 16:20:07 -0700 | [diff] [blame] | 20 | import glob |
| 21 | |
Stefan Reinauer | f64b42e | 2010-02-09 15:15:29 +0000 | [diff] [blame] | 22 | helplen = 0 |
| 23 | extra_chapters = 0 |
| 24 | |
| 25 | ## |
| 26 | ## Remove quotes from Kconfig string options |
| 27 | ## |
| 28 | def zapquotes(str): |
| 29 | if str[0]=='"': str = str[1:str.rfind('"')] |
| 30 | return str |
| 31 | |
| 32 | ## |
| 33 | ## Escape HTML special characters |
| 34 | ## |
| 35 | def htmlescape(str): |
| 36 | return str.strip().replace("&","&").replace("<","<").replace(">",">") |
| 37 | |
| 38 | ## |
| 39 | ## Process Kconfig file |
| 40 | ## |
| 41 | def readfile(filename): |
| 42 | import sys |
| 43 | global helplen |
| 44 | |
| 45 | source=filename.replace("src/","").replace("/Kconfig","").replace("Kconfig","toplevel") |
| 46 | |
| 47 | try: |
| 48 | lines = open(filename).read().split("\n") |
| 49 | except IOError: |
| 50 | sys.stderr.write("File %s missing\n" % filename) |
| 51 | return |
| 52 | config = None |
| 53 | description = None |
| 54 | configtype = None |
| 55 | for i in lines: |
| 56 | if helplen: |
| 57 | i = i.expandtabs() |
| 58 | if not len(i) or i[:helplen].isspace(): |
| 59 | sys.stdout.write("%s\n" % htmlescape(i)) |
| 60 | continue |
| 61 | else: |
| 62 | helplen = 0 |
| 63 | sys.stdout.write("||\n") |
| 64 | |
| 65 | words = i.strip().split(None,1) |
| 66 | if not len(words): continue |
| 67 | |
| 68 | if words[0] in ("config", "menuconfig"): |
| 69 | config = words[1] |
| 70 | description = "" |
| 71 | elif words[0] in ("bool", "boolean", "tristate", "string", "hex", "int"): |
| 72 | configtype = htmlescape(zapquotes(words[0])) |
| 73 | if len(words)>1: description = htmlescape(zapquotes(words[1])) |
| 74 | elif words[0]=="prompt": |
| 75 | description = htmlescape(zapquotes(words[1])) |
| 76 | elif words[0] in ("help", "---help---"): |
| 77 | sys.stdout.write("|- bgcolor=\"#eeeeee\"\n") |
| 78 | sys.stdout.write("| %s || %s || %s || %s || \n" % (config,source,configtype,description) ) |
| 79 | helplen = len(i[:i.find(words[0])].expandtabs()) |
| 80 | elif words[0] == "comment": |
| 81 | sys.stdout.write("|- bgcolor=\"#eeeeee\"\n") |
| 82 | sys.stdout.write("| || || (comment) || || %s ||\n" % htmlescape(zapquotes(words[1]))) |
| 83 | elif words[0]=="menu": |
| 84 | if len(words)>1: |
| 85 | temp = htmlescape(zapquotes(words[1])) |
| 86 | if extra_chapters: |
| 87 | sys.stdout.write("== Menu: %s ==\n" % temp) |
| 88 | sys.stdout.write("{| border=\"0\" style=\"font-size: smaller\"\n"); |
| 89 | sys.stdout.write("|- bgcolor=\"#6699dd\"\n") |
| 90 | sys.stdout.write("! align=\"left\" | Option\n") |
| 91 | sys.stdout.write("! align=\"left\" | Source\n") |
| 92 | sys.stdout.write("! align=\"left\" | Format\n") |
| 93 | sys.stdout.write("! align=\"left\" | Short Description\n") |
| 94 | sys.stdout.write("! align=\"left\" | Description\n") |
| 95 | else: |
| 96 | # Don't start an extra chapter for a |
| 97 | # new menu |
| 98 | sys.stdout.write("|- bgcolor=\"#6699dd\"\n") |
| 99 | sys.stdout.write("! align=\"left\" | Menu: %s || || || ||\n" % temp) |
| 100 | elif words[0] == "endmenu": |
| 101 | if extra_chapters: |
| 102 | sys.stdout.write("|}\n") |
| 103 | sys.stdout.write("\n") |
| 104 | elif words[0] == "source": |
| 105 | fn=zapquotes(words[1]) |
Stefan Reinauer | 0a52468 | 2015-05-05 16:20:07 -0700 | [diff] [blame] | 106 | for name in glob.glob(fn): |
| 107 | readfile(name) |
Stefan Reinauer | f64b42e | 2010-02-09 15:15:29 +0000 | [diff] [blame] | 108 | elif words[0] in ("default","depends", "select", "if", "endif", "#"): pass |
| 109 | #else: sys.stderr.write("unknown: %s\n" % i) |
| 110 | if helplen: sys.stdout.write("||\n") |
| 111 | |
| 112 | def main(): |
| 113 | import sys, time |
| 114 | |
| 115 | if len(sys.argv)!=3: |
| 116 | sys.stderr.write("Usage: kconfig2wiki kconfigfile version\n") |
| 117 | sys.exit(1) |
| 118 | |
| 119 | sys.stdout.write("This is an automatically generated list of '''coreboot compile-time options'''.\n") |
| 120 | sys.stdout.write("\nLast update: %s. (r%s)\n" % (time.strftime('%Y/%m/%d %H:%M:%S'),sys.argv[2])) |
| 121 | sys.stdout.write("{| border=\"0\" style=\"font-size: smaller\"\n"); |
| 122 | sys.stdout.write("|- bgcolor=\"#6699dd\"\n") |
| 123 | sys.stdout.write("! align=\"left\" | Option\n") |
| 124 | sys.stdout.write("! align=\"left\" | Source\n") |
| 125 | sys.stdout.write("! align=\"left\" | Format\n") |
| 126 | sys.stdout.write("! align=\"left\" | Short Description\n") |
| 127 | sys.stdout.write("! align=\"left\" | Description\n") |
| 128 | readfile(sys.argv[1]) |
| 129 | sys.stdout.write("|}\n") |
| 130 | |
| 131 | if __name__ == "__main__": |
| 132 | main() |