coreboot/util/optionlist/kconfig2wiki
<<
>>
Prefs
   1#!/usr/bin/python
   2#
   3# kconfig2wiki - Kconfig to MediaWiki converter for
   4# http://www.coreboot.org/Coreboot_Options
   5#
   6# Copyright (C) 2010 coresystems GmbH
   7# based on http://landley.net/kdocs/make/menuconfig2html.py
   8# Copyright (C) by Rob Landley
   9#
  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
  13#
  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.
  18#
  19# You should have received a copy of the GNU General Public License
  20# along with this program; if not, write to the Free Software
  21# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  22#
  23
  24helplen = 0
  25extra_chapters = 0
  26
  27##
  28## Remove quotes from Kconfig string options
  29##
  30def zapquotes(str):
  31        if str[0]=='"': str = str[1:str.rfind('"')]
  32        return str
  33
  34##
  35## Escape HTML special characters
  36##
  37def htmlescape(str):
  38        return str.strip().replace("&","&amp;").replace("<","&lt;").replace(">","&gt;")
  39
  40##
  41## Process Kconfig file
  42##
  43def readfile(filename):
  44        import sys
  45        global helplen
  46
  47        source=filename.replace("src/","").replace("/Kconfig","").replace("Kconfig","toplevel")
  48
  49        try:
  50                lines = open(filename).read().split("\n")
  51        except IOError:
  52                sys.stderr.write("File %s missing\n" % filename)
  53                return
  54        config = None
  55        description = None
  56        configtype = None
  57        for i in lines:
  58                if helplen:
  59                        i = i.expandtabs()
  60                        if not len(i) or i[:helplen].isspace():
  61                                sys.stdout.write("%s\n" % htmlescape(i))
  62                                continue
  63                        else:
  64                                helplen = 0
  65                                sys.stdout.write("||\n")
  66
  67                words = i.strip().split(None,1)
  68                if not len(words): continue
  69
  70                if words[0] in ("config", "menuconfig"):
  71                        config = words[1]
  72                        description = ""
  73                elif words[0] in ("bool", "boolean", "tristate", "string", "hex", "int"):
  74                         configtype = htmlescape(zapquotes(words[0]))
  75                         if len(words)>1: description = htmlescape(zapquotes(words[1]))
  76                elif words[0]=="prompt":
  77                        description = htmlescape(zapquotes(words[1]))
  78                elif words[0] in ("help", "---help---"):
  79                        sys.stdout.write("|- bgcolor=\"#eeeeee\"\n")
  80                        sys.stdout.write("| %s || %s || %s || %s || \n" % (config,source,configtype,description) )
  81                        helplen = len(i[:i.find(words[0])].expandtabs())
  82                elif words[0] == "comment":
  83                        sys.stdout.write("|- bgcolor=\"#eeeeee\"\n")
  84                        sys.stdout.write("| || || (comment) || || %s ||\n" % htmlescape(zapquotes(words[1])))
  85                elif words[0]=="menu":
  86                        if len(words)>1:
  87                                temp = htmlescape(zapquotes(words[1]))
  88                                if extra_chapters:
  89                                        sys.stdout.write("== Menu: %s ==\n" % temp)
  90                                        sys.stdout.write("{| border=\"0\" style=\"font-size: smaller\"\n");
  91                                        sys.stdout.write("|- bgcolor=\"#6699dd\"\n")
  92                                        sys.stdout.write("! align=\"left\" | Option\n")
  93                                        sys.stdout.write("! align=\"left\" | Source\n")
  94                                        sys.stdout.write("! align=\"left\" | Format\n")
  95                                        sys.stdout.write("! align=\"left\" | Short&nbsp;Description\n")
  96                                        sys.stdout.write("! align=\"left\" | Description\n")
  97                                else:
  98                                        # Don't start an extra chapter for a
  99                                        # new menu
 100                                        sys.stdout.write("|- bgcolor=\"#6699dd\"\n")
 101                                        sys.stdout.write("! align=\"left\" | Menu: %s || || || ||\n" % temp)
 102                elif words[0] == "endmenu":
 103                        if extra_chapters:
 104                                sys.stdout.write("|}\n")
 105                        sys.stdout.write("\n")
 106                elif words[0] == "source":
 107                        fn=zapquotes(words[1])
 108                        readfile(fn)
 109                elif words[0] in ("default","depends", "select", "if", "endif", "#"): pass
 110                #else: sys.stderr.write("unknown: %s\n" % i)
 111        if helplen: sys.stdout.write("||\n")
 112
 113def main():
 114        import sys, time
 115
 116        if len(sys.argv)!=3:
 117                sys.stderr.write("Usage: kconfig2wiki kconfigfile version\n")
 118                sys.exit(1)
 119
 120        sys.stdout.write("This is an automatically generated list of '''coreboot compile-time options'''.\n")
 121        sys.stdout.write("\nLast update: %s. (r%s)\n" % (time.strftime('%Y/%m/%d %H:%M:%S'),sys.argv[2]))
 122        sys.stdout.write("{| border=\"0\" style=\"font-size: smaller\"\n");
 123        sys.stdout.write("|- bgcolor=\"#6699dd\"\n")
 124        sys.stdout.write("! align=\"left\" | Option\n")
 125        sys.stdout.write("! align=\"left\" | Source\n")
 126        sys.stdout.write("! align=\"left\" | Format\n")
 127        sys.stdout.write("! align=\"left\" | Short&nbsp;Description\n")
 128        sys.stdout.write("! align=\"left\" | Description\n")
 129        readfile(sys.argv[1])
 130        sys.stdout.write("|}\n")
 131
 132if __name__ == "__main__":
 133        main()
 134
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.