diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2017-11-09 11:43:13 +0100 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2017-11-09 11:43:13 +0100 |
| commit | 395c2db0e9761def8eb992e3e8068ba2d3ab179c (patch) | |
| tree | 7b14ac791dbf9d4b9354f1c6149444e090068309 /examples/print_tree.py | |
| parent | 8c978ee0b9c0f7f8406f58d24478a73330512056 (diff) | |
| parent | 4bffd653148d6fa1c8e626872ae4f445e2b0a24c (diff) | |
Make Kconfiglib 2 official
Merge in the 'kconfiglib-2-backup' branch.
Diffstat (limited to 'examples/print_tree.py')
| -rw-r--r-- | examples/print_tree.py | 80 |
1 files changed, 62 insertions, 18 deletions
diff --git a/examples/print_tree.py b/examples/print_tree.py index 1405ed5..1a53a3a 100644 --- a/examples/print_tree.py +++ b/examples/print_tree.py @@ -1,23 +1,67 @@ -# Prints a tree of all items in the configuration +# Prints the menu tree of the configuration. Dependencies between symbols can +# sometimes implicitly alter the menu structure (see kconfig-language.txt), and +# that's implemented too. +# +# Usage: +# +# $ make [ARCH=<arch>] scriptconfig SCRIPT=Kconfiglib/examples/print_tree.py +# +# Example output: +# +# ... +# config HAVE_KERNEL_LZO +# config HAVE_KERNEL_LZ4 +# choice +# config KERNEL_GZIP +# config KERNEL_BZIP2 +# config KERNEL_LZMA +# config KERNEL_XZ +# config KERNEL_LZO +# config KERNEL_LZ4 +# config DEFAULT_HOSTNAME +# config SWAP +# config SYSVIPC +# config SYSVIPC_SYSCTL +# config POSIX_MQUEUE +# config POSIX_MQUEUE_SYSCTL +# config CROSS_MEMORY_ATTACH +# config FHANDLE +# config USELIB +# config AUDIT +# config HAVE_ARCH_AUDITSYSCALL +# config AUDITSYSCALL +# config AUDIT_WATCH +# config AUDIT_TREE +# menu "IRQ subsystem" +# config MAY_HAVE_SPARSE_IRQ +# config GENERIC_IRQ_LEGACY +# config GENERIC_IRQ_PROBE +# ... -import kconfiglib +from kconfiglib import Kconfig, Symbol, Choice, MENU, COMMENT import sys -def print_with_indent(s, indent): +def indent_print(s, indent): print((" " * indent) + s) -def print_items(items, indent): - for item in items: - if item.is_symbol(): - print_with_indent("config {0}".format(item.get_name()), indent) - elif item.is_menu(): - print_with_indent('menu "{0}"'.format(item.get_title()), indent) - print_items(item.get_items(), indent + 2) - elif item.is_choice(): - print_with_indent('choice', indent) - print_items(item.get_items(), indent + 2) - elif item.is_comment(): - print_with_indent('comment "{0}"'.format(item.get_text()), indent) - -conf = kconfiglib.Config(sys.argv[1]) -print_items(conf.get_top_level_items(), 0) +def print_items(node, indent): + while node: + if isinstance(node.item, Symbol): + indent_print("config " + node.item.name, indent) + + elif isinstance(node.item, Choice): + indent_print("choice", indent) + + elif node.item == MENU: + indent_print('menu "{0}"'.format(node.prompt[0]), indent) + + elif node.item == COMMENT: + indent_print('comment "{0}"'.format(node.prompt[0]), indent) + + if node.list: + print_items(node.list, indent + 2) + + node = node.next + +kconf = Kconfig(sys.argv[1]) +print_items(kconf.top_node, 0) |
