summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2021-05-25 20:42:51 +0200
committercos <cos>2021-05-25 20:48:34 +0200
commit25ded8c464024e6bef81d6678c69110fdbf15618 (patch)
tree3de9187340959343604cc19a5f83ed24d5c117a8
parent7639aea0aef14ce29d49e249a1af1da62733f609 (diff)
downloadcalendar-cli-fix/loop_on_save.zip
Wrap question about how to handle config in a loopfix/loop_on_save
This commit attempts to address these two issues: Whenever calendar-cli is run on a clean new user account lacking a ~/.config directory, configuration is lost and has to be remade. There might be other cases for an Exception here and they are all annoying enough to warrant a change in behaviour. From a usability perspective, it is easy to be pressing enter a bit too quickly to stop at the save prompt. This is especially true if merely changing one or a couple of values while leaving the rest of them at their old value. Reasking to require an actual answer on what to do would be an improvement.
-rwxr-xr-xcalendar-cli.py60
1 files changed, 36 insertions, 24 deletions
diff --git a/calendar-cli.py b/calendar-cli.py
index e9a36a5..da7a615 100755
--- a/calendar-cli.py
+++ b/calendar-cli.py
@@ -274,31 +274,43 @@ def interactive_config(args, config, remaining_argv):
if not modified:
print("No configuration changes have been done")
else:
- options = []
- if section:
- options.append(('save', 'save configuration into section %s' % section))
- if backup or not section:
- options.append(('save_other', 'add this new configuration into a new section in the configuration file'))
- if remaining_argv:
- options.append(('use', 'use this configuration without saving'))
- options.append(('abort', 'abort without saving'))
- print("CONFIGURATION DONE ...")
- for o in options:
- print("Type %s if you want to %s" % o)
- cmd = raw_input("Enter a command: ")
- if cmd in ('save', 'save_other'):
- if cmd == 'save_other':
- new_section = raw_input("New config section name: ")
- config[new_section] = config[section]
- if backup:
- config[section] = backup
+ state = 'start'
+ while state == 'start':
+ options = []
+ if section:
+ options.append(('save', 'save configuration into section %s' % section))
+ if backup or not section:
+ options.append(('save_other', 'add this new configuration into a new section in the configuration file'))
+ if remaining_argv:
+ options.append(('use', 'use this configuration without saving'))
+ options.append(('abort', 'abort without saving'))
+ print("CONFIGURATION DONE ...")
+ for o in options:
+ print("Type %s if you want to %s" % o)
+ cmd = raw_input("Enter a command: ")
+ if cmd in ('use', 'abort'):
+ state = 'done'
+ if cmd in ('save', 'save_other'):
+ if cmd == 'save_other':
+ new_section = raw_input("New config section name: ")
+ config[new_section] = config[section]
+ if backup:
+ config[section] = backup
+ else:
+ del config[section]
+ section = new_section
+ try:
+ if os.path.isfile(args.config_file):
+ os.rename(args.config_file, "%s.%s.bak" % (args.config_file, int(time.time())))
+ with open(args.config_file, 'w') as outfile:
+ json.dump(config, outfile, indent=4)
+ except Exception as e:
+ print(e)
else:
- del config[section]
- section = new_section
- if os.path.isfile(args.config_file):
- os.rename(args.config_file, "%s.%s.bak" % (args.config_file, int(time.time())))
- with open(args.config_file, 'w') as outfile:
- json.dump(config, outfile, indent=4)
+ print("Saved config")
+ state = 'done'
+
+
if args.config_section == 'default' and section != 'default':