diff options
Diffstat (limited to 'kconfiglib.py')
| -rw-r--r-- | kconfiglib.py | 108 |
1 files changed, 56 insertions, 52 deletions
diff --git a/kconfiglib.py b/kconfiglib.py index 98c39b9..3bdcb45 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -1389,73 +1389,77 @@ class Kconfig(object): if save_old: _save_old(filename) + with self._open(filename, "w") as f: + f.write(header) + self._write_config_syms(f) + + if verbose: + print("Configuration written to '{}'".format(filename)) + + def _write_config_syms(self, f): + # write_config() helper. Writes the actual configuration output to 'f'. + # node_iter() was used here before commit 3aea9f7 ("Add '# end of # <menu>' after menus in .config"). Those comments get tricky to # implement with it. - with self._open(filename, "w") as f: - f.write(header) - - for sym in self.unique_defined_syms: - sym._visited = False + for sym in self.unique_defined_syms: + sym._visited = False - # Did we just print an '# end of ...' comment? - after_end_comment = False + # Did we just print an '# end of ...' comment? + after_end_comment = False - node = self.top_node - while 1: - # Jump to the next node with an iterative tree walk - if node.list: - node = node.list - elif node.next: - node = node.next - else: - while node.parent: - node = node.parent - - # Print a comment when leaving visible menus - if node.item is MENU and expr_value(node.dep) and \ - expr_value(node.visibility) and \ - node is not self.top_node: - f.write("# end of {}\n".format(node.prompt[0])) - after_end_comment = True - - if node.next: - node = node.next - break - else: - # No more nodes - return + node = self.top_node + while 1: + # Jump to the next node with an iterative tree walk + if node.list: + node = node.list + elif node.next: + node = node.next + else: + while node.parent: + node = node.parent - # Generate configuration output for the node + # Print a comment when leaving visible menus + if node.item is MENU and expr_value(node.dep) and \ + expr_value(node.visibility) and \ + node is not self.top_node: + f.write("# end of {}\n".format(node.prompt[0])) + after_end_comment = True - item = node.item + if node.next: + node = node.next + break + else: + # No more nodes + return - if item.__class__ is Symbol: - if item._visited: - continue - item._visited = True + # Generate configuration output for the node - conf_string = item.config_string - if not conf_string: - continue + item = node.item - if after_end_comment: - # Add a blank line before the first symbol printed - # after an '# end of ...' comment - after_end_comment = False - f.write("\n") - f.write(conf_string) + if item.__class__ is Symbol: + if item._visited: + continue + item._visited = True - elif expr_value(node.dep) and \ - ((item is MENU and expr_value(node.visibility)) or - item is COMMENT): + conf_string = item.config_string + if not conf_string: + continue - f.write("\n#\n# {}\n#\n".format(node.prompt[0])) + if after_end_comment: + # Add a blank line before the first symbol printed after an + # '# end of ...' comment after_end_comment = False + f.write("\n") + f.write(conf_string) - if verbose: - print("Configuration written to '{}'".format(filename)) + elif expr_value(node.dep) and \ + ((item is MENU and expr_value(node.visibility)) or + item is COMMENT): + + f.write("\n#\n# {}\n#\n".format(node.prompt[0])) + after_end_comment = False def write_min_config(self, filename, header="# Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib)\n"): |
