summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2019-06-02 18:15:59 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2019-06-03 06:50:06 +0200
commit55bc8c380869ea663092212e8fe388ad7abae596 (patch)
tree200d557c614845bd017de4e411c66c5c0b19fae5
parent455e3661c6f50b088b35a3b2662052e7e2a24769 (diff)
Have load_config() and write_(min_)config() return messages
Hardcoding load_config() and write_(min_)config() to write any message to stdout is awkward, because it means that the message can't be easily reused when stdout is the wrong place to write it to (e.g. in menuconfig/guiconfig). This gets extra bad now that there's also the "No change to ..." message. Modify load_config() and write_(min_)config() to return the message as a string instead, and have them always return a message, instead of just when 'filename' is None and verbose=True. This makes things flexible and straightforward. Use the new behavior in menuconfig.py and guiconfig.py. They now show "No change to ..." when saving a file doesn't modify it. Tools that want to write messages to stdout should now do print(kconf.load_config()) / print(kconf.write_config()). There's no clean way to preserve perfect backwards compatibility here, but keep accepting the 'verbose' argument and print a deprecation warning if a value is ever passed for it. That way, scripts will keep running, though possibly with less output on stdout. This changes the meaning of the load_config() return value as well, though I suspect it was only ever used by the menuconfig/guiconfig interfaces. The new behavior applies for kconfiglib.VERSION >= (12, 0, 0).
-rwxr-xr-xalldefconfig.py2
-rwxr-xr-xallmodconfig.py2
-rwxr-xr-xallnoconfig.py2
-rwxr-xr-xallyesconfig.py2
-rwxr-xr-xdefconfig.py4
-rw-r--r--examples/allnoconfig_walk.py2
-rw-r--r--examples/defconfig_oldconfig.py2
-rwxr-xr-x[-rw-r--r--]examples/menuconfig_example.py24
-rwxr-xr-x[-rw-r--r--]examples/merge_config.py28
-rwxr-xr-xgenconfig.py2
-rwxr-xr-xguiconfig.py26
-rw-r--r--kconfiglib.py244
-rwxr-xr-xlistnewconfig.py4
-rwxr-xr-xmenuconfig.py32
-rwxr-xr-xoldconfig.py4
-rwxr-xr-xolddefconfig.py4
-rwxr-xr-xsavedefconfig.py4
-rwxr-xr-xsetconfig.py4
18 files changed, 226 insertions, 166 deletions
diff --git a/alldefconfig.py b/alldefconfig.py
index a24f07a..5082fcb 100755
--- a/alldefconfig.py
+++ b/alldefconfig.py
@@ -20,7 +20,7 @@ import kconfiglib
def main():
kconf = kconfiglib.standard_kconfig()
kconfiglib.load_allconfig(kconf, "alldef.config")
- kconf.write_config()
+ print(kconf.write_config())
if __name__ == "__main__":
diff --git a/allmodconfig.py b/allmodconfig.py
index 990cddf..add16a8 100755
--- a/allmodconfig.py
+++ b/allmodconfig.py
@@ -39,7 +39,7 @@ def main():
kconfiglib.load_allconfig(kconf, "allmod.config")
- kconf.write_config()
+ print(kconf.write_config())
if __name__ == "__main__":
diff --git a/allnoconfig.py b/allnoconfig.py
index 7d81906..a0afd78 100755
--- a/allnoconfig.py
+++ b/allnoconfig.py
@@ -38,7 +38,7 @@ def main():
kconfiglib.load_allconfig(kconf, "allno.config")
- kconf.write_config()
+ print(kconf.write_config())
if __name__ == "__main__":
diff --git a/allyesconfig.py b/allyesconfig.py
index 3f576fa..45231bc 100755
--- a/allyesconfig.py
+++ b/allyesconfig.py
@@ -49,7 +49,7 @@ def main():
kconfiglib.load_allconfig(kconf, "allyes.config")
- kconf.write_config()
+ print(kconf.write_config())
if __name__ == "__main__":
diff --git a/defconfig.py b/defconfig.py
index 7b02833..d1b1e4e 100755
--- a/defconfig.py
+++ b/defconfig.py
@@ -35,8 +35,8 @@ def main():
args = parser.parse_args()
kconf = kconfiglib.Kconfig(args.kconfig)
- kconf.load_config(args.config)
- kconf.write_config()
+ print(kconf.load_config(args.config))
+ print(kconf.write_config())
if __name__ == "__main__":
diff --git a/examples/allnoconfig_walk.py b/examples/allnoconfig_walk.py
index 24b2828..5a8cc23 100644
--- a/examples/allnoconfig_walk.py
+++ b/examples/allnoconfig_walk.py
@@ -63,4 +63,4 @@ while True:
if not changed:
break
-kconf.write_config()
+print(kconf.write_config())
diff --git a/examples/defconfig_oldconfig.py b/examples/defconfig_oldconfig.py
index 98f97a0..68336c6 100644
--- a/examples/defconfig_oldconfig.py
+++ b/examples/defconfig_oldconfig.py
@@ -36,4 +36,4 @@ for s in kconf.unique_defined_syms:
s.set_value(0)
# Write the final configuration
-kconf.write_config()
+print(kconf.write_config())
diff --git a/examples/menuconfig_example.py b/examples/menuconfig_example.py
index 4e2560d..b265e69 100644..100755
--- a/examples/menuconfig_example.py
+++ b/examples/menuconfig_example.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Implements a simple configuration interface on top of Kconfiglib to
# demonstrate concepts for building a menuconfig-like. Emulates how the
# standard menuconfig prints menu entries.
@@ -117,6 +119,7 @@
#
# Enter a symbol/choice name, "load_config", or "write_config" (or press CTRL+D to exit): ^D
+from __future__ import print_function
import readline
import sys
@@ -300,27 +303,22 @@ if __name__ == "__main__":
if cmd == "load_config":
config_filename = input(".config file to load: ")
-
try:
- kconf.load_config(config_filename)
+ # Returns a message telling which file got loaded
+ print(kconf.load_config(config_filename))
except IOError as e:
- # Print the (spammy) error from Kconfiglib itself
- print(e.message + "\n")
- else:
- print("Configuration loaded from " + config_filename)
+ print(e, file=sys.stderr)
print_menuconfig(kconf)
continue
if cmd == "write_config":
config_filename = input("To this file: ")
-
try:
- kconf.write_config(config_filename)
+ # Returns a message telling which file got saved
+ print(kconf.write_config(config_filename))
except IOError as e:
- print(e.message)
- else:
- print("Configuration written to " + config_filename)
+ print(e, file=sys.stderr)
continue
@@ -340,5 +338,5 @@ if __name__ == "__main__":
continue
- print("No symbol/choice named '{}' in the configuration"
- .format(cmd))
+ print("No symbol/choice named '{}' in the configuration".format(cmd),
+ file=sys.stderr)
diff --git a/examples/merge_config.py b/examples/merge_config.py
index ec022d5..6f60375 100644..100755
--- a/examples/merge_config.py
+++ b/examples/merge_config.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# This script functions similarly to scripts/kconfig/merge_config.sh from the
# kernel tree, merging multiple configurations fragments to produce a complete
# .config, with unspecified values filled in as for alldefconfig.
@@ -37,7 +39,8 @@
#
# conf3 contents:
#
-# # Ops... assigned twice
+# # Assigned twice (would generate warning if 'warn_assign_override' was
+# # True)
# # CONFIG_FOO is not set
#
# # Ops... this symbol doesn't exist
@@ -54,15 +57,20 @@
# Running:
#
# $ python(3) merge_config.py Kconfig merged conf1 conf2 conf3 conf4
-# conf3:2: warning: FOO (defined at Kconfig:1) set more than once. Old value: "y", new value: "n".
-# conf3:5: warning: attempt to assign the value "y" to the undefined symbol OPS
-# warning: QAZ (defined at Kconfig:10) was assigned the value "y" but got the value "n" -- check dependencies
+# Merged configuration 'conf1'
+# Merged configuration 'conf2'
+# conf3:5: warning: attempt to assign the value 'y' to the undefined symbol OPS
+# Merged configuration 'conf3'
+# Merged configuration 'conf4'
+# Configuration saved to 'merged'
+# warning: QAZ (defined at Kconfig:10) was assigned the value 'y' but got the value 'n' -- check dependencies
# $ cat merged
# Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib)
# # CONFIG_FOO is not set
# CONFIG_BAR=y
# CONFIG_BAZ="baz string"
+from __future__ import print_function
import sys
from kconfiglib import Kconfig, BOOL, TRISTATE, TRI_TO_STR
@@ -86,12 +94,13 @@ kconf.enable_undef_warnings()
kconf.disable_override_warnings()
kconf.disable_redun_warnings()
-# Create a merged configuration by loading the fragments with replace=False
+# Create a merged configuration by loading the fragments with replace=False.
+# load_config() and write_config() returns a message to print.
for config in sys.argv[3:]:
- kconf.load_config(config, replace=False)
+ print(kconf.load_config(config, replace=False))
# Write the merged configuration
-kconf.write_config(sys.argv[2])
+print(kconf.write_config(sys.argv[2]))
# Print warnings for symbols whose actual value doesn't match the assigned
# value
@@ -119,5 +128,6 @@ for sym in kconf.defined_syms:
if user_value != sym.str_value:
print("warning: {} was assigned the value '{}' but got the "
- "value '{}' -- check dependencies"
- .format(name_and_loc(sym), user_value, sym.str_value))
+ "value '{}' -- check dependencies".format(
+ name_and_loc(sym), user_value, sym.str_value),
+ file=sys.stderr)
diff --git a/genconfig.py b/genconfig.py
index ba2bb73..aebff35 100755
--- a/genconfig.py
+++ b/genconfig.py
@@ -77,7 +77,7 @@ def main():
kconf = kconfiglib.Kconfig(args.kconfig_filename)
- kconf.load_config(verbose=False)
+ kconf.load_config()
kconf.write_autoconf(args.header_path)
diff --git a/guiconfig.py b/guiconfig.py
index 9563ab4..ca04e06 100755
--- a/guiconfig.py
+++ b/guiconfig.py
@@ -175,12 +175,12 @@ def menuconfig(kconf):
_create_ui()
- # Load existing configuration and check if it's outdated
- _set_conf_changed(_load_config())
-
# Filename to save configuration to
_conf_filename = standard_config_filename()
+ # Load existing configuration and check if it's outdated
+ _set_conf_changed(_load_config())
+
# Filename to save minimal configuration to
_minconf_filename = "defconfig"
@@ -238,7 +238,8 @@ def _load_config():
# Returns True if .config is missing or outdated. We always prompt for
# saving the configuration in that case.
- if not _kconf.load_config():
+ print(_kconf.load_config())
+ if not os.path.exists(_conf_filename):
# No .config
return True
@@ -639,7 +640,8 @@ def _set_conf_changed(changed):
global _conf_changed
_conf_changed = changed
- _set_status("Modified" if changed else "")
+ if changed:
+ _set_status("Modified")
def _update_tree():
@@ -1341,7 +1343,6 @@ def _save(_=None):
if _try_save(_kconf.write_config, _conf_filename, "configuration"):
_set_conf_changed(False)
- _set_status("Configuration saved to " + _conf_filename)
_tree.focus_set()
@@ -1363,7 +1364,6 @@ def _save_as():
break
if _try_save(_kconf.write_config, filename, "configuration"):
- _set_status("Configuration saved to " + filename)
_conf_filename = filename
break
@@ -1433,7 +1433,6 @@ def _open(_=None):
_update_tree()
- _set_status("Configuration loaded from " + filename)
break
_tree.focus_set()
@@ -1694,8 +1693,10 @@ def _try_save(save_fn, filename, description):
# String describing the thing being saved
try:
- save_fn(filename)
- print("{} saved to '{}'".format(description, filename))
+ # save_fn() returns a message to print
+ msg = save_fn(filename)
+ _set_status(msg)
+ print(msg)
return True
except (OSError, IOError) as e:
messagebox.showerror(
@@ -1714,8 +1715,9 @@ def _try_load(filename):
# Configuration file to load
try:
- _kconf.load_config(filename)
- print("configuration loaded from " + filename)
+ msg = _kconf.load_config(filename)
+ _set_status(msg)
+ print(msg)
return True
except (OSError, IOError) as e:
messagebox.showerror(
diff --git a/kconfiglib.py b/kconfiglib.py
index 01ba0b8..d33a690 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -1058,7 +1058,7 @@ class Kconfig(object):
return None
- def load_config(self, filename=None, replace=True, verbose=True):
+ def load_config(self, filename=None, replace=True, verbose=None):
"""
Loads symbol values from a file in the .config format. Equivalent to
calling Symbol.set_value() to set each of the values.
@@ -1106,36 +1106,40 @@ class Kconfig(object):
If True, all existing user values will be cleared before loading the
.config. Pass False to merge configurations.
- verbose (default: True):
- If True and filename is None (automatically infer configuration
- file), a message will be printed to stdout telling which file got
- loaded (or that no file got loaded). This is meant to reduce
- boilerplate in tools.
+ verbose (default: None):
+ Limited backwards compatibility to prevent crashes. A warning is
+ printed if anything but None is passed.
- Returns True if an existing configuration was loaded (that didn't come
- from the 'option defconfig_list' symbol), and False otherwise. This is
- mostly useful in conjunction with filename=None, as True will always be
- returned otherwise.
+ Prior to Kconfiglib 12.0.0, this option enabled printing of messages
+ to stdout when 'filename' was None. A message is (always) returned
+ now instead, which is more flexible.
+
+ Will probably be removed in some future version.
+
+ Returns a string with a message saying which file got loaded (or
+ possibly that no file got loaded, when 'filename' is None). This is
+ meant to reduce boilerplate in tools, which can do e.g.
+ print(kconf.load_config()).
"""
- loaded_existing = True
+ if verbose is not None:
+ _warn_verbose_deprecated("load_config")
+
+ msg = None
if filename is None:
filename = standard_config_filename()
- if exists(filename):
- if verbose:
- print("Using existing configuration '{}' as base"
- .format(filename))
- else:
- filename = self.defconfig_filename
- if filename is None:
- if verbose:
- print("Using default symbol values as base")
- return False
+ if not exists(filename) and \
+ not exists(join(self.srctree, filename)):
+ defconfig = self.defconfig_filename
+ if defconfig is None:
+ return "Using default symbol values (no '{}')" \
+ .format(filename)
- if verbose:
- print("Using default configuration found in '{}' as "
- "base".format(filename))
+ msg = " default configuration '{}' (no '{}')" \
+ .format(defconfig, filename)
+ filename = defconfig
- loaded_existing = False
+ if not msg:
+ msg = " configuration '{}'".format(filename)
# Disable the warning about assigning to symbols without prompts. This
# is normal and expected within a .config file.
@@ -1149,7 +1153,7 @@ class Kconfig(object):
finally:
self._warn_for_no_prompt = True
- return loaded_existing
+ return ("Loaded" if replace else "Merged") + msg
def _load_config(self, filename, replace):
with self._open_config(filename) as f:
@@ -1367,7 +1371,7 @@ class Kconfig(object):
def write_config(self, filename=None,
header="# Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib)\n",
- save_old=True, verbose=True):
+ save_old=True, verbose=None):
r"""
Writes out symbol values in the .config format. The format matches the
C implementation, including ordering.
@@ -1406,21 +1410,29 @@ class Kconfig(object):
due to being a directory, or <filename> being something like
/dev/null).
- verbose (default: True):
- If True and filename is None (automatically infer configuration
- file), a message will be printed to stdout telling which file got
- written. This is meant to reduce boilerplate in tools.
+ verbose (default: None):
+ Limited backwards compatibility to prevent crashes. A warning is
+ printed if anything but None is passed.
+
+ Prior to Kconfiglib 12.0.0, this option enabled printing of messages
+ to stdout when 'filename' was None. A message is (always) returned
+ now instead, which is more flexible.
+
+ Will probably be removed in some future version.
+
+ Returns a string with a message saying which file got saved. This is
+ meant to reduce boilerplate in tools, which can do e.g.
+ print(kconf.write_config()).
"""
+ if verbose is not None:
+ _warn_verbose_deprecated("write_config")
+
if filename is None:
filename = standard_config_filename()
- else:
- verbose = False
contents = self._config_contents(header)
if self._contents_eq(filename, contents):
- if verbose:
- print("No change to '{}'".format(filename))
- return
+ return "No change to '{}'".format(filename)
if save_old:
_save_old(filename)
@@ -1428,8 +1440,7 @@ class Kconfig(object):
with self._open(filename, "w") as f:
f.write(contents)
- if verbose:
- print("Configuration written to '{}'".format(filename))
+ return "Configuration saved to '{}'".format(filename)
def _config_contents(self, header):
# write_config() helper. Returns the contents to write as a string,
@@ -1524,34 +1535,53 @@ class Kconfig(object):
Text that will be inserted verbatim at the beginning of the file. You
would usually want each line to start with '#' to make it a comment,
and include a final terminating newline.
+
+ Returns a string with a message saying which file got saved. This is
+ meant to reduce boilerplate in tools, which can do e.g.
+ print(kconf.write_min_config()).
"""
+ contents = self._min_config_contents(header)
+ if self._contents_eq(filename, contents):
+ return "No change to '{}'".format(filename)
+
with self._open(filename, "w") as f:
- f.write(header)
+ f.write(contents)
- for sym in self.unique_defined_syms:
- # Skip symbols that cannot be changed. Only check
- # non-choice symbols, as selects don't affect choice
- # symbols.
- if not sym.choice and \
- sym.visibility <= expr_value(sym.rev_dep):
- continue
+ return "Minimal configuration saved to '{}'".format(filename)
- # Skip symbols whose value matches their default
- if sym.str_value == sym._str_default():
- continue
+ def _min_config_contents(self, header):
+ # write_min_config() helper. Returns the contents to write as a string,
+ # with 'header' at the beginning.
- # Skip symbols that would be selected by default in a
- # choice, unless the choice is optional or the symbol type
- # isn't bool (it might be possible to set the choice mode
- # to n or the symbol to m in those cases).
- if sym.choice and \
- not sym.choice.is_optional and \
- sym.choice._get_selection_from_defaults() is sym and \
- sym.orig_type is BOOL and \
- sym.tri_value == 2:
- continue
+ chunks = [header]
+ add = chunks.append
- f.write(sym.config_string)
+ for sym in self.unique_defined_syms:
+ # Skip symbols that cannot be changed. Only check
+ # non-choice symbols, as selects don't affect choice
+ # symbols.
+ if not sym.choice and \
+ sym.visibility <= expr_value(sym.rev_dep):
+ continue
+
+ # Skip symbols whose value matches their default
+ if sym.str_value == sym._str_default():
+ continue
+
+ # Skip symbols that would be selected by default in a
+ # choice, unless the choice is optional or the symbol type
+ # isn't bool (it might be possible to set the choice mode
+ # to n or the symbol to m in those cases).
+ if sym.choice and \
+ not sym.choice.is_optional and \
+ sym.choice._get_selection_from_defaults() is sym and \
+ sym.orig_type is BOOL and \
+ sym.tri_value == 2:
+ continue
+
+ add(sym.config_string)
+
+ return "".join(chunks)
def sync_deps(self, path):
"""
@@ -2083,7 +2113,7 @@ class Kconfig(object):
# filesystem, compare the files, and rename() the temporary file if it
# differs, but it breaks stuff like write_config("/dev/null"), which is
# used out there to force evaluation-related warnings to be generated.
- # This simple version pretty failsafe and portable.
+ # This simple version is pretty failsafe and portable.
if not self._contents_eq(filename, contents):
with self._open(filename, "w") as f:
@@ -5989,6 +6019,10 @@ def load_allconfig(kconf, filename):
Command-specific configuration filename - "allyes.config",
"allno.config", etc.
"""
+ allconfig = os.environ.get("KCONFIG_ALLCONFIG")
+ if allconfig is None:
+ return
+
def std_msg(e):
# "Upcasts" a _KconfigIOError to an IOError, removing the custom
# __str__() message. The standard message is better here.
@@ -5997,25 +6031,23 @@ def load_allconfig(kconf, filename):
kconf.disable_override_warnings()
kconf.disable_redun_warnings()
- allconfig = os.environ.get("KCONFIG_ALLCONFIG")
- if allconfig is not None:
- if allconfig in ("", "1"):
- try:
- kconf.load_config(filename, False)
- except IOError as e1:
- try:
- kconf.load_config("all.config", False)
- except IOError as e2:
- sys.exit("error: KCONFIG_ALLCONFIG is set, but neither {} "
- "nor all.config could be opened: {}, {}"
- .format(filename, std_msg(e1), std_msg(e2)))
- else:
+ if allconfig in ("", "1"):
+ try:
+ print(kconf.load_config(filename, False))
+ except IOError as e1:
try:
- kconf.load_config(allconfig, False)
- except IOError as e:
- sys.exit("error: KCONFIG_ALLCONFIG is set to '{}', which "
- "could not be opened: {}"
- .format(allconfig, std_msg(e)))
+ print(kconf.load_config("all.config", False))
+ except IOError as e2:
+ sys.exit("error: KCONFIG_ALLCONFIG is set, but neither {} "
+ "nor all.config could be opened: {}, {}"
+ .format(filename, std_msg(e1), std_msg(e2)))
+ else:
+ try:
+ print(kconf.load_config(allconfig, False))
+ except IOError as e:
+ sys.exit("error: KCONFIG_ALLCONFIG is set to '{}', which "
+ "could not be opened: {}"
+ .format(allconfig, std_msg(e)))
# API wart: It would be nice if there was a way to query and/or push/pop
# warning settings
@@ -6166,28 +6198,6 @@ def _save_old(path):
pass
-def _decoding_error(e, filename, macro_linenr=None):
- # Gives the filename and context for UnicodeDecodeError's, which are a pain
- # to debug otherwise. 'e' is the UnicodeDecodeError object.
- #
- # If the decoding error is for the output of a $(shell,...) command,
- # macro_linenr holds the line number where it was run (the exact line
- # number isn't available for decoding errors in files).
-
- raise KconfigError(
- "\n"
- "Malformed {} in {}\n"
- "Context: {}\n"
- "Problematic data: {}\n"
- "Reason: {}".format(
- e.encoding,
- "'{}'".format(filename) if macro_linenr is None else
- "output from macro at {}:{}".format(filename, macro_linenr),
- e.object[max(e.start - 40, 0):e.end + 40],
- e.object[e.start:e.end],
- e.reason))
-
-
def _name_and_loc(sc):
# Helper for giving the symbol/choice name and location(s) in e.g. warnings
@@ -6485,6 +6495,38 @@ def _found_dep_loop(loop, cur):
raise KconfigError(msg)
+def _decoding_error(e, filename, macro_linenr=None):
+ # Gives the filename and context for UnicodeDecodeError's, which are a pain
+ # to debug otherwise. 'e' is the UnicodeDecodeError object.
+ #
+ # If the decoding error is for the output of a $(shell,...) command,
+ # macro_linenr holds the line number where it was run (the exact line
+ # number isn't available for decoding errors in files).
+
+ raise KconfigError(
+ "\n"
+ "Malformed {} in {}\n"
+ "Context: {}\n"
+ "Problematic data: {}\n"
+ "Reason: {}".format(
+ e.encoding,
+ "'{}'".format(filename) if macro_linenr is None else
+ "output from macro at {}:{}".format(filename, macro_linenr),
+ e.object[max(e.start - 40, 0):e.end + 40],
+ e.object[e.start:e.end],
+ e.reason))
+
+
+def _warn_verbose_deprecated(fn_name):
+ sys.stderr.write(
+ "Deprecation warning: {0}()'s 'verbose' argument has no effect. Since "
+ "Kconfiglib 12.0.0, the message is returned from {0}() instead, "
+ "and is always generated. Do e.g. print(kconf.{0}()) if you want to "
+ "want to show a message like \"Loaded configuration '.config'\" on "
+ "stdout. The old API required ugly hacks to reuse messages in "
+ "configuration interfaces.\n".format(fn_name))
+
+
# Predefined preprocessor functions
diff --git a/listnewconfig.py b/listnewconfig.py
index 06d0cf1..59de141 100755
--- a/listnewconfig.py
+++ b/listnewconfig.py
@@ -18,7 +18,9 @@ from kconfiglib import standard_kconfig, BOOL, TRISTATE, INT, HEX, STRING, \
def main():
kconf = standard_kconfig()
- kconf.load_config()
+ # Make it possible to filter this message out
+ sys.stderr.write(kconf.load_config() + "\n")
+
for sym in kconf.unique_defined_syms:
# Only show symbols that can be toggled. Choice symbols are a special
# case in that sym.assignable will be (2,) (length 1) for visible
diff --git a/menuconfig.py b/menuconfig.py
index 3dbee95..a7f921b 100755
--- a/menuconfig.py
+++ b/menuconfig.py
@@ -650,12 +650,12 @@ def menuconfig(kconf):
_kconf = kconf
- # Load existing configuration and set _conf_changed True if it is outdated
- _conf_changed = _load_config()
-
# Filename to save configuration to
_conf_filename = standard_config_filename()
+ # Load existing configuration and set _conf_changed True if it is outdated
+ _conf_changed = _load_config()
+
# Filename to save minimal configuration to
_minconf_filename = "defconfig"
@@ -710,7 +710,8 @@ def _load_config():
# Returns True if .config is missing or outdated. We always prompt for
# saving the configuration in that case.
- if not _kconf.load_config():
+ print(_kconf.load_config())
+ if not os.path.exists(_conf_filename):
# No .config
return True
@@ -922,8 +923,9 @@ def _quit_dialog():
return None
if c == "y":
- if _try_save(_kconf.write_config, _conf_filename, "configuration"):
- return "Configuration saved to '{}'".format(_conf_filename)
+ msg = _try_save(_kconf.write_config, _conf_filename, "configuration")
+ if msg:
+ return msg
elif c == "n":
return "Configuration ({}) was not saved".format(_conf_filename)
@@ -1858,29 +1860,33 @@ def _save_dialog(save_fn, default_filename, description):
filename = os.path.expanduser(filename)
- if _try_save(save_fn, filename, description):
- _msg("Success", "{} saved to {}".format(description, filename))
+ msg = _try_save(save_fn, filename, description)
+ if msg:
+ _msg("Success", msg)
return filename
def _try_save(save_fn, filename, description):
- # Tries to save a configuration file. Pops up an error and returns False on
- # failure.
+ # Tries to save a configuration file. Returns a message to print on
+ # success.
#
# save_fn:
# Function to call with 'filename' to save the file
#
# description:
# String describing the thing being saved
+ #
+ # Return value:
+ # A message to print on success, and None on failure
try:
- save_fn(filename)
- return True
+ # save_fn() returns a message to print
+ return save_fn(filename)
except OSError as e:
_error("Error saving {} to '{}'\n\n{} (errno: {})"
.format(description, e.filename, e.strerror,
errno.errorcode[e.errno]))
- return False
+ return None
def _key_dialog(title, text, keys):
diff --git a/oldconfig.py b/oldconfig.py
index 7cc9e5b..042ab44 100755
--- a/oldconfig.py
+++ b/oldconfig.py
@@ -45,7 +45,7 @@ def _main():
global conf_changed
kconf = standard_kconfig()
- kconf.load_config()
+ print(kconf.load_config())
while True:
conf_changed = False
@@ -56,7 +56,7 @@ def _main():
if not conf_changed:
break
- kconf.write_config()
+ print(kconf.write_config())
def oldconfig(node):
diff --git a/olddefconfig.py b/olddefconfig.py
index 1d1bac1..a59a7d4 100755
--- a/olddefconfig.py
+++ b/olddefconfig.py
@@ -20,8 +20,8 @@ import kconfiglib
def main():
kconf = kconfiglib.standard_kconfig()
- kconf.load_config()
- kconf.write_config()
+ print(kconf.load_config())
+ print(kconf.write_config())
if __name__ == "__main__":
diff --git a/savedefconfig.py b/savedefconfig.py
index 8b45fe4..c388f1a 100755
--- a/savedefconfig.py
+++ b/savedefconfig.py
@@ -41,8 +41,8 @@ def main():
args = parser.parse_args()
kconf = kconfiglib.Kconfig(args.kconfig)
- kconf.load_config()
- kconf.write_min_config(args.out)
+ print(kconf.load_config())
+ print(kconf.write_min_config(args.out))
if __name__ == "__main__":
diff --git a/setconfig.py b/setconfig.py
index c92f346..2a14310 100755
--- a/setconfig.py
+++ b/setconfig.py
@@ -60,7 +60,7 @@ def main():
args = parser.parse_args()
kconf = kconfiglib.Kconfig(args.kconfig)
- kconf.load_config()
+ print(kconf.load_config())
for arg in args.assignments:
if "=" not in arg:
@@ -84,7 +84,7 @@ def main():
"sure that it has a prompt."
.format(name, value, sym.str_value))
- kconf.write_config()
+ print(kconf.write_config())
if __name__ == "__main__":