From 2bfd1f2a8983b5e556f2e3d9e6b6c0604bc08308 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Mon, 30 Oct 2017 14:08:17 +0100 Subject: Have printing a menu node print the item Handy and intuitive. Avoids having to go to .item all the time when experimenting, and provides Kconfig output for menus and comments. >>> print c.top_node menu "Linux/$ARCH $KERNELVERSION Kernel Configuration" >>> print c.top_node.list config SRCARCH string option env="SRCARCH" default "x86" >>> print c.top_node.list.next config 64BIT bool prompt "64-bit kernel" if ARCH = "x86" default ARCH != "i386" help Say yes to build a 64-bit kernel - formerly known as x86_64 Say no to build a 32-bit kernel - formerly known as i386 Piggyback escaping when printing the prompt of symbols and choices. They can contain " and \ as well. --- kconfiglib.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/kconfiglib.py b/kconfiglib.py index 226ae9f..09d821f 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -3288,6 +3288,28 @@ class MenuNode(object): return "<{}>".format(", ".join(fields)) + def __str__(self): + """ + TODO + """ + if isinstance(self.item, (Symbol, Choice)): + return self.item.__str__() + + if self.item in (MENU, COMMENT): + s = ("menu" if self.item == MENU else "comment") + \ + ' "{}"\n'.format(escape(self.prompt[0])) + + if self.dep is not self.kconfig.y: + s += "\tdepends on {}\n".format(expr_str(self.dep)) + + if self.item == MENU and self.visibility is not self.kconfig.y: + s += "\tvisible if {}\n".format(expr_str(self.visibility)) + + return s + + # 'if' node. Should never appear in the final tree. + return "if " + expr_str(self.dep) + class KconfigSyntaxError(Exception): """ Exception raised for syntax errors. @@ -3560,7 +3582,7 @@ def _sym_choice_str(sc): indent_add(_TYPENAME[sc.orig_type]) if node.prompt is not None: - prompt_str = 'prompt "{}"'.format(node.prompt[0]) + prompt_str = 'prompt "{}"'.format(escape(node.prompt[0])) if node.prompt[1] is not sc.kconfig.y: prompt_str += " if " + expr_str(node.prompt[1]) indent_add(prompt_str) -- cgit v1.2.3