summaryrefslogtreecommitdiff
path: root/examples/print_tree.py
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2012-12-06 17:01:09 +0100
committerUlf Magnusson <ulfalizer@gmail.com>2012-12-06 17:01:29 +0100
commitc805e3143bada2df897927996ae23a469cf83eb3 (patch)
tree38212ced8df505ee2814ac5b8d29460f0fa5e98b /examples/print_tree.py
parent94fb111d02b95413f7c36d923dabd4ec1ca1c90e (diff)
Move examples into separate directory.
Diffstat (limited to 'examples/print_tree.py')
-rw-r--r--examples/print_tree.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/examples/print_tree.py b/examples/print_tree.py
new file mode 100644
index 0000000..35ad23e
--- /dev/null
+++ b/examples/print_tree.py
@@ -0,0 +1,23 @@
+# Prints a tree of all items in the configuration
+
+import kconfiglib
+import sys
+
+def print_with_indent(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)