diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-10-20 15:14:24 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-10-20 15:14:24 +0200 |
commit | 88492823826b3720be4ba29d246848031418bfb5 (patch) | |
tree | 4f17cc7f4ef3f76f869a1d4fcb94722464aa9d0b /tools | |
parent | Hostlist test: test non-empty domain (diff) | |
download | smolbote-88492823826b3720be4ba29d246848031418bfb5.tar.xz |
Add Kconfiglib to parse Kconfig/.config
Diffstat (limited to 'tools')
m--------- | tools/Kconfiglib | 0 | ||||
-rwxr-xr-x | tools/config.py | 64 |
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) |