Makes the default_loader for wsl.conf testable
This commit is contained in:
parent
80869d23f2
commit
b4734ad587
|
@ -56,11 +56,11 @@ config_adv_default = {
|
||||||
}
|
}
|
||||||
|
|
||||||
conf_type_to_file = {
|
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,
|
Loads the configuration from the given file type,
|
||||||
section and reference config.
|
section and reference config.
|
||||||
|
@ -70,9 +70,6 @@ def wsl_config_loader(config_ref, id):
|
||||||
return the data loaded
|
return the data loaded
|
||||||
"""
|
"""
|
||||||
data = {}
|
data = {}
|
||||||
pathname = conf_type_to_file[id]
|
|
||||||
if not os.path.exists(pathname):
|
|
||||||
return data
|
|
||||||
config = ConfigParser()
|
config = ConfigParser()
|
||||||
config.read(pathname)
|
config.read(pathname)
|
||||||
for conf_sec in config:
|
for conf_sec in config:
|
||||||
|
@ -97,15 +94,19 @@ def wsl_config_loader(config_ref, id):
|
||||||
return data
|
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.
|
This will load the default WSL config for the given type.
|
||||||
|
|
||||||
:param is_advanced: boolean, True if it is WSLConfigurationAdvanced,
|
:param is_advanced: boolean, True if it is WSLConfigurationAdvanced,
|
||||||
else is WSLConfigurationBase
|
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
|
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
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
@ -134,7 +135,7 @@ def wsl_config_update(config_class, root_dir):
|
||||||
config.BasicInterpolation = None
|
config.BasicInterpolation = None
|
||||||
|
|
||||||
os.makedirs(os.path.join(root_dir, "etc"), exist_ok=True)
|
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)
|
config.read(conf_file)
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,8 @@ class WSLConfigurationAdvancedController(SubiquityController):
|
||||||
super().__init__(app)
|
super().__init__(app)
|
||||||
|
|
||||||
# load the config file
|
# 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:
|
if data:
|
||||||
proc_data = \
|
proc_data = \
|
||||||
|
|
|
@ -48,7 +48,8 @@ class WSLConfigurationBaseController(SubiquityController):
|
||||||
super().__init__(app)
|
super().__init__(app)
|
||||||
|
|
||||||
# load the config file
|
# load the config file
|
||||||
data = default_loader()
|
root_dir = self.app.base_model.root
|
||||||
|
data = default_loader(root_dir)
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
proc_data = \
|
proc_data = \
|
||||||
|
|
|
@ -45,7 +45,8 @@ class WSLSetupOptionsController(SubiquityController):
|
||||||
super().__init__(app)
|
super().__init__(app)
|
||||||
|
|
||||||
# load the config file
|
# load the config file
|
||||||
data = default_loader()
|
root_dir = self.app.base_model.root
|
||||||
|
data = default_loader(root_dir)
|
||||||
conf_data = WSLSetupOptions()
|
conf_data = WSLSetupOptions()
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
|
|
Loading…
Reference in New Issue