aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-10-20 15:14:24 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-10-20 15:14:24 +0200
commit88492823826b3720be4ba29d246848031418bfb5 (patch)
tree4f17cc7f4ef3f76f869a1d4fcb94722464aa9d0b /tools
parentHostlist test: test non-empty domain (diff)
downloadsmolbote-88492823826b3720be4ba29d246848031418bfb5.tar.xz
Add Kconfiglib to parse Kconfig/.config
Diffstat (limited to 'tools')
m---------tools/Kconfiglib0
-rwxr-xr-xtools/config.py64
2 files changed, 64 insertions, 0 deletions
diff --git a/tools/Kconfiglib b/tools/Kconfiglib
new file mode 160000
+Subproject 5d918357dd5734b900e1fdf074090ea662debd9
diff --git a/tools/config.py b/tools/config.py
new file mode 100755
index 0000000..22defdd
--- /dev/null
+++ b/tools/config.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python3
+
+import argparse
+from Kconfiglib import kconfiglib
+
+def search(node, term):
+ while node:
+ if isinstance(node.item, kconfiglib.Symbol):
+ if node.item.name == term:
+ return node.item.str_value
+
+ if node.list:
+ r = search(node.list, term)
+ if r is not None:
+ return r
+
+ node = node.next
+
+def searchBug(node, term):
+ bugs = ""
+
+ while node:
+ if isinstance(node.item, kconfiglib.Symbol):
+ if node.item.name.startswith(term):
+ if bugs is not "":
+ bugs += ";"
+ bugs += node.item.name
+
+ if node.list:
+ r = searchBug(node.list, term)
+ if r is not None and r is not "":
+ if bugs is not "":
+ bugs += ";"
+ bugs += r
+
+ node = node.next
+ return bugs
+
+def main(args):
+ kconf = kconfiglib.Kconfig(args.kconfig)
+ if args.dotconfig is not None:
+ kconf.load_config(args.dotconfig)
+
+ i = ""
+ if args.setting.endswith("BUG"):
+ i = searchBug(kconf.top_node, args.setting)
+ else:
+ i = search(kconf.top_node, args.setting)
+
+ if i is not None:
+ print(i)
+
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser()
+
+ parser.add_argument("--kconfig", metavar="Kconfig", nargs="?", default="Kconfig", help="Top-level Kconfig file (default: Kconfig)")
+
+ parser.add_argument("--dotconfig", metavar="dotconfig", nargs="?", help=".config")
+
+ parser.add_argument("setting", metavar="CONFIG_KEY", nargs="?", help="Top-level Kconfig file (default: Kconfig)")
+
+ args = parser.parse_args()
+ main(args)