diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2019-06-02 18:15:59 +0200 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2019-06-03 06:50:06 +0200 |
| commit | 55bc8c380869ea663092212e8fe388ad7abae596 (patch) | |
| tree | 200d557c614845bd017de4e411c66c5c0b19fae5 /guiconfig.py | |
| parent | 455e3661c6f50b088b35a3b2662052e7e2a24769 (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).
Diffstat (limited to 'guiconfig.py')
| -rwxr-xr-x | guiconfig.py | 26 |
1 files changed, 14 insertions, 12 deletions
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( |
