From 55bc8c380869ea663092212e8fe388ad7abae596 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sun, 2 Jun 2019 18:15:59 +0200 Subject: 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). --- setconfig.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setconfig.py') 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__": -- cgit v1.2.3