system_setup: write files to .subiquity when dryrun

This commit is contained in:
Patrick Wu 2021-10-06 22:10:56 +08:00
parent e367e7b4b1
commit 1c111c764c
No known key found for this signature in database
GPG Key ID: 9DD33DF28FC324F1
2 changed files with 7 additions and 10 deletions

View File

@ -110,16 +110,13 @@ def default_loader(is_advanced=False):
return data
# TODO: remove dryrun and add root param once we write the option to .subiquity
def wsl_config_update(config_class, is_dry_run):
def wsl_config_update(config_class, root_dir):
"""
This update the configuration file for the given class.zzd
:param config_class: WSLConfigurationBase or WSLConfigurationAdvanced
:param is_dry_run: boolean, True if it is a dry run
"""
if is_dry_run:
log.debug("mimicking setting config %s", config_class)
temp_conf_default = {}
temp_confname = config_class.__str__()
if temp_confname.startswith("WSLConfigurationBase"):
@ -128,8 +125,6 @@ def wsl_config_update(config_class, is_dry_run):
temp_conf_default = config_adv_default
else:
raise TypeError("Invalid type name.")
if is_dry_run:
return
# update the config file
for config_type in temp_conf_default:
@ -138,7 +133,8 @@ def wsl_config_update(config_class, is_dry_run):
config = ConfigParser()
config.BasicInterpolcation = None
conf_file = conf_type_to_file[config_type]
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:])
config.read(conf_file)
@ -149,7 +145,7 @@ def wsl_config_update(config_class, is_dry_run):
config_api_name = \
config_section.lower() + "_" + config_setting.lower()
config_value = config_class.__dict__[config_api_name]
# if the value for the setting is defualt value, drop it
# if the value for the setting is default value, drop it
if config_default_value == config_value:
if config_setting in config[config_section]:
config.remove_option(config_section, config_setting)

View File

@ -68,6 +68,7 @@ class ConfigureController(SubiquityController):
dryrun = self.app.opts.dry_run
variant = self.app.variant
root_dir = self.model.root
if variant == "wsl_setup":
wsl_id = self.model.identity.user
if dryrun:
@ -96,9 +97,9 @@ class ConfigureController(SubiquityController):
assign_grp_act.stderr))
else:
wsl_config_update(self.model.wslconfadvanced.wslconfadvanced,
dryrun)
root_dir)
wsl_config_update(self.model.wslconfbase.wslconfbase, dryrun)
wsl_config_update(self.model.wslconfbase.wslconfbase, root_dir)
self.app.update_state(ApplicationState.DONE)
except Exception: