diff options
author | Tobias Brox <tobias@redpill-linpro.com> | 2022-11-28 01:20:40 +0100 |
---|---|---|
committer | Tobias Brox <tobias@redpill-linpro.com> | 2022-11-28 01:20:40 +0100 |
commit | f655b6b64765216f9f09a2049ccee76e83c7b05f (patch) | |
tree | 2ee7ee92beba3800ed126e9557b8da3d5ff4e408 /calendar_cli/legacy.py | |
parent | c287de35b862a01ec8f6bb443502b10a1ae5eac5 (diff) | |
download | calendar-cli-f655b6b64765216f9f09a2049ccee76e83c7b05f.zip |
config in place now ... and actually trying to use the new cal.py-interface for practical tasks...
Diffstat (limited to 'calendar_cli/legacy.py')
-rwxr-xr-x | calendar_cli/legacy.py | 115 |
1 files changed, 2 insertions, 113 deletions
diff --git a/calendar_cli/legacy.py b/calendar_cli/legacy.py index 69dd3e6..cf17bd5 100755 --- a/calendar_cli/legacy.py +++ b/calendar_cli/legacy.py @@ -26,6 +26,7 @@ from datetime import time as time_ import dateutil.parser from dateutil.rrule import rrulestr from icalendar import Calendar,Event,Todo,Journal,Alarm +from calendar_cli.config import interactive_config, config_section import vobject import caldav import uuid @@ -262,97 +263,6 @@ def calendar_addics(caldav_conn, args): c.subcomponents = timezones + uids[uid] _calendar_addics(caldav_conn, c.to_ical(), uid, args) -def interactive_config(args, config, remaining_argv): - import readline - - new_config = False - section = 'default' - backup = {} - modified = False - - print("Welcome to the interactive calendar configuration mode") - print("Warning - untested code ahead, raise issues at t-calendar-cli@tobixen.no or the github issue tracker") - print("It might be a good idea to read the documentation in parallel if running this for your first time") - if not config or not hasattr(config, 'keys'): - config = {} - print("No valid existing configuration found") - new_config = True - if config: - print("The following sections have been found: ") - print("\n".join(config.keys())) - if args.config_section and args.config_section != 'default': - section = args.config_section - else: - ## TODO: tab completion - section = raw_input("Chose one of those, or a new name / no name for a new configuration section: ") - if section in config: - backup = config[section].copy() - print("Using section " + section) - else: - section = 'default' - - if not section in config: - config[section] = {} - - for config_key in ('caldav_url', 'calendar_url', 'caldav_user', 'caldav_pass', 'caldav_proxy', 'ssl_verify_cert', 'language', 'timezone', 'inherits'): - - if config_key == 'caldav_pass': - print("Config option caldav_pass - old value: **HIDDEN**") - value = getpass(prompt="Enter new value (or just enter to keep the old): ") - else: - print("Config option %s - old value: %s" % (config_key, config[section].get(config_key, '(None)'))) - value = raw_input("Enter new value (or just enter to keep the old): ") - - if value: - config[section][config_key] = value - modified = True - - if not modified: - print("No configuration changes have been done") - else: - 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: - print("Saved config") - state = 'done' - - - - - if args.config_section == 'default' and section != 'default': - config['default'] = config[section] - return config - def create_alarm(message, relative_timedelta): alarm = Alarm() alarm.add('ACTION', 'DISPLAY') @@ -777,15 +687,6 @@ def todo_delete(caldav_conn, args): for task in tasks: task.delete() -def config_section(config, section='default'): - if section in config and 'inherits' in config[section]: - ret = config_section(config, config[section]['inherits']) - else: - ret = {} - if section in config: - ret.update(config[section]) - return ret - def main(): """ the main function does (almost) nothing but parsing command line parameters @@ -819,19 +720,7 @@ def main(): args, remaining_argv = conf_parser.parse_known_args() conf_parser.add_argument("--version", action='version', version='%%(prog)s %s' % metadata["version"]) - config = {} - - try: - with open(args.config_file) as config_file: - config = json.load(config_file) - except IOError: - ## File not found - logging.info("no config file found") - except ValueError: - if args.interactive_config: - logging.error("error in config file. Be aware that the current config file will be ignored and overwritten", exc_info=True) - else: - logging.error("error in config file. You may want to run --interactive-config or fix the config file", exc_info=True) + config = read_config(args.config_file) if args.interactive_config: defaults = interactive_config(args, config, remaining_argv) |