From 4424d3d6c1dffd68eeed1654e82387355ce74871 Mon Sep 17 00:00:00 2001 From: rasmusthog Date: Sun, 9 Oct 2022 18:37:14 +0200 Subject: [PATCH] Remove need for required_options --- nafuma/auxillary.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/nafuma/auxillary.py b/nafuma/auxillary.py index 4734802..8044914 100644 --- a/nafuma/auxillary.py +++ b/nafuma/auxillary.py @@ -6,10 +6,12 @@ import shutil import time from datetime import datetime -def update_options(options, required_options, default_options): +def update_options(options, default_options, required_options=None): ''' Takes a dictionary of options along with a list of required options and dictionary of default options, and sets all keyval-pairs of options that is not already defined to the default values''' + #FIXME This has been updated so that required_options is not needed. But lots of scripts still passes required_options, so for now it is still accepted, but has a default value and remains unused. Needs to go through all scripts to stop passing of this variable to remove it. - for option in required_options: + + for option in default_options.keys(): if option not in options.keys(): options[option] = default_options[option] @@ -145,4 +147,20 @@ def get_unique(full_list): if not entry in unique_list: unique_list.append(entry) - return unique_list \ No newline at end of file + return unique_list + + +def swap_values(options: dict, key1, key2): + + if not isinstance(key1,list): + key1 = [key1] + if not isinstance(key2,list): + key2 = [key2] + + assert len(key1) == len(key2) + + for k1, k2 in zip(key1, key2): + options[k1], options[k2] = options[k2], options[k1] + + + return options \ No newline at end of file