From b4734ad587c357ce9a1f223d35aa0896bc60efe0 Mon Sep 17 00:00:00 2001 From: Carlos Nihelton Date: Thu, 15 Sep 2022 16:08:35 -0300 Subject: [PATCH] Makes the default_loader for wsl.conf testable --- system_setup/common/wsl_conf.py | 17 +++++++++-------- .../server/controllers/wslconfadvanced.py | 3 ++- system_setup/server/controllers/wslconfbase.py | 3 ++- .../server/controllers/wslsetupoptions.py | 3 ++- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/system_setup/common/wsl_conf.py b/system_setup/common/wsl_conf.py index 41f9aede..f98bfca7 100644 --- a/system_setup/common/wsl_conf.py +++ b/system_setup/common/wsl_conf.py @@ -56,11 +56,11 @@ config_adv_default = { } conf_type_to_file = { - "wsl": "/etc/wsl.conf", + "wsl": "etc/wsl.conf", } -def wsl_config_loader(config_ref, id): +def wsl_config_loader(pathname, config_ref, id): """ Loads the configuration from the given file type, section and reference config. @@ -70,9 +70,6 @@ def wsl_config_loader(config_ref, id): return the data loaded """ data = {} - pathname = conf_type_to_file[id] - if not os.path.exists(pathname): - return data config = ConfigParser() config.read(pathname) for conf_sec in config: @@ -97,15 +94,19 @@ def wsl_config_loader(config_ref, id): return data -def default_loader(is_advanced=False): +def default_loader(root_dir, is_advanced=False): """ This will load the default WSL config for the given type. :param is_advanced: boolean, True if it is WSLConfigurationAdvanced, else is WSLConfigurationBase """ + id = "wsl" + pathname = os.path.join(root_dir, conf_type_to_file[id]) + if not os.path.exists(pathname): + return {} conf_ref = config_adv_default if is_advanced else config_base_default - data = wsl_config_loader(conf_ref, "wsl") + data = wsl_config_loader(pathname, conf_ref, id) return data @@ -134,7 +135,7 @@ def wsl_config_update(config_class, root_dir): config.BasicInterpolation = None os.makedirs(os.path.join(root_dir, "etc"), exist_ok=True) - conf_file = os.path.join(root_dir, conf_type_to_file[config_type][1:]) + conf_file = os.path.join(root_dir, conf_type_to_file[config_type]) config.read(conf_file) diff --git a/system_setup/server/controllers/wslconfadvanced.py b/system_setup/server/controllers/wslconfadvanced.py index baf19c07..0ca95ed0 100644 --- a/system_setup/server/controllers/wslconfadvanced.py +++ b/system_setup/server/controllers/wslconfadvanced.py @@ -49,7 +49,8 @@ class WSLConfigurationAdvancedController(SubiquityController): super().__init__(app) # load the config file - data = default_loader(is_advanced=True) + root_dir = self.app.base_model.root + data = default_loader(root_dir, is_advanced=True) if data: proc_data = \ diff --git a/system_setup/server/controllers/wslconfbase.py b/system_setup/server/controllers/wslconfbase.py index 198deccc..db4b4201 100644 --- a/system_setup/server/controllers/wslconfbase.py +++ b/system_setup/server/controllers/wslconfbase.py @@ -48,7 +48,8 @@ class WSLConfigurationBaseController(SubiquityController): super().__init__(app) # load the config file - data = default_loader() + root_dir = self.app.base_model.root + data = default_loader(root_dir) if data: proc_data = \ diff --git a/system_setup/server/controllers/wslsetupoptions.py b/system_setup/server/controllers/wslsetupoptions.py index c4b20bce..6c7ad608 100644 --- a/system_setup/server/controllers/wslsetupoptions.py +++ b/system_setup/server/controllers/wslsetupoptions.py @@ -45,7 +45,8 @@ class WSLSetupOptionsController(SubiquityController): super().__init__(app) # load the config file - data = default_loader() + root_dir = self.app.base_model.root + data = default_loader(root_dir) conf_data = WSLSetupOptions() if data: