system_setup: unify api names and simply WSLconfig class into function
This commit is contained in:
parent
5c0e64e78a
commit
1a7274dbba
|
@ -6,9 +6,9 @@ WSLIdentity:
|
|||
# ubuntu
|
||||
password: '$6$wdAcoXrU039hKYPd$508Qvbe7ObUnxoj15DRCkzC3qO7edjH0VV7BPNRDYK4QR8ofJaEEF2heacn0QgD.f8pO8SNp83XNdWG6tocBM1'
|
||||
WSLConfigurationBase:
|
||||
custom_path: '/custom_mnt_path'
|
||||
custom_mount_opt: 'metadata'
|
||||
gen_host: false
|
||||
gen_resolvconf: false
|
||||
automount_root: '/custom_mnt_path'
|
||||
automount_options: 'metadata'
|
||||
network_generatehosts: false
|
||||
network_generateresolvconf: false
|
||||
Summary:
|
||||
reboot: yes
|
|
@ -356,21 +356,21 @@ class ShutdownMode(enum.Enum):
|
|||
|
||||
@attr.s(auto_attribs=True)
|
||||
class WSLConfigurationBase:
|
||||
custom_path: str = attr.ib(default='/mnt/')
|
||||
custom_mount_opt: str = ''
|
||||
gen_host: bool = attr.ib(default=True)
|
||||
gen_resolvconf: bool = attr.ib(default=True)
|
||||
automount_root: str = attr.ib(default='/mnt/')
|
||||
automount_options: str = ''
|
||||
network_generatehosts: bool = attr.ib(default=True)
|
||||
network_generateresolvconf: bool = attr.ib(default=True)
|
||||
|
||||
|
||||
@attr.s(auto_attribs=True)
|
||||
class WSLConfigurationAdvanced:
|
||||
gui_theme: str = attr.ib(default='default')
|
||||
gui_followwintheme: bool = attr.ib(default=True)
|
||||
legacy_gui: bool = attr.ib(default=False)
|
||||
legacy_audio: bool = attr.ib(default=False)
|
||||
adv_ip_detect: bool = attr.ib(default=False)
|
||||
wsl_motd_news: bool = attr.ib(default=True)
|
||||
automount: bool = attr.ib(default=True)
|
||||
mountfstab: bool = attr.ib(default=True)
|
||||
interop_guiintegration: bool = attr.ib(default=False)
|
||||
interop_audiointegration: bool = attr.ib(default=False)
|
||||
interop_advancedipdetection: bool = attr.ib(default=False)
|
||||
motd_wslnewsenabled: bool = attr.ib(default=True)
|
||||
automount_enabled: bool = attr.ib(default=True)
|
||||
automount_mountfstab: bool = attr.ib(default=True)
|
||||
interop_enabled: bool = attr.ib(default=True)
|
||||
interop_appendwindowspath: bool = attr.ib(default=True)
|
||||
|
|
|
@ -33,21 +33,24 @@ class WSLConfigurationAdvancedController(SubiquityTuiController):
|
|||
def run_answers(self):
|
||||
if all(elem in self.answers for elem in
|
||||
['interop_enabled', 'interop_appendwindowspath',
|
||||
'gui_theme', 'gui_followwintheme', 'legacy_gui',
|
||||
'legacy_audio', 'adv_ip_detect',
|
||||
'wsl_motd_news', 'automount', 'mountfstab']):
|
||||
'gui_theme', 'gui_followwintheme', 'interop_guiintegration',
|
||||
'interop_audiointegration', 'interop_advancedipdetection',
|
||||
'motd_wslnewsenabled', 'automount_enabled',
|
||||
'automount_mountfstab']):
|
||||
reconfiguration = WSLConfigurationAdvanced(
|
||||
interop_enabled=self.answers['interop_enabled'],
|
||||
interop_appendwindowspath=self
|
||||
.answers['interop_appendwindowspath'],
|
||||
gui_theme=self.answers['gui_theme'],
|
||||
gui_followwintheme=self.answers['gui_followwintheme'],
|
||||
legacy_gui=self.answers['legacy_gui'],
|
||||
legacy_audio=self.answers['legacy_audio'],
|
||||
adv_ip_detect=self.answers['adv_ip_detect'],
|
||||
wsl_motd_news=self.answers['wsl_motd_news'],
|
||||
automount=self.answers['automount'],
|
||||
mountfstab=self.answers['mountfstab']
|
||||
interop_guiintegration=self.answers['interop_guiintegration'],
|
||||
interop_audiointegration=self
|
||||
.answers['interop_audiointegration'],
|
||||
interop_advancedipdetection=self
|
||||
.answers['interop_advancedipdetection'],
|
||||
motd_wslnewsenabled=self.answers['motd_wslnewsenabled'],
|
||||
automount_enabled=self.answers['automount_enabled'],
|
||||
automount_mountfstab=self.answers['automount_mountfstab']
|
||||
)
|
||||
self.done(reconfiguration)
|
||||
|
||||
|
|
|
@ -16,13 +16,14 @@ class WSLConfigurationBaseController(SubiquityTuiController):
|
|||
|
||||
def run_answers(self):
|
||||
if all(elem in self.answers for elem in
|
||||
['custom_path', 'custom_mount_opt',
|
||||
'gen_host', 'gen_resolvconf']):
|
||||
['automount_root', 'automount_options',
|
||||
'network_generatehosts', 'network_generateresolvconf']):
|
||||
configuration = WSLConfigurationBase(
|
||||
custom_path=self.answers['custom_path'],
|
||||
custom_mount_opt=self.answers['custom_mount_opt'],
|
||||
gen_host=self.answers['gen_host'],
|
||||
gen_resolvconf=self.answers['gen_resolvconf'])
|
||||
automount_root=self.answers['automount_root'],
|
||||
automount_options=self.answers['automount_options'],
|
||||
network_generatehosts=self.answers['network_generatehosts'],
|
||||
network_generateresolvconf=self
|
||||
.answers['network_generateresolvconf'])
|
||||
self.done(configuration)
|
||||
|
||||
def done(self, configuration_data):
|
||||
|
|
|
@ -17,25 +17,12 @@
|
|||
# original code from ubuntuwslctl.core.loader
|
||||
# Copyright (C) 2021 Canonical Ltd.
|
||||
|
||||
import os
|
||||
import logging
|
||||
from configparser import ConfigParser
|
||||
from os import path
|
||||
|
||||
log = logging.getLogger("system_setup.common.wsl_conf")
|
||||
|
||||
config_base_ref = {
|
||||
"wsl": {
|
||||
"automount": {
|
||||
"root": "custom_path",
|
||||
"options": "custom_mount_opt",
|
||||
},
|
||||
"network": {
|
||||
"generatehosts": "gen_host",
|
||||
"generateresolvconf": "gen_resolvconf",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
config_base_default = {
|
||||
"wsl": {
|
||||
"automount": {
|
||||
|
@ -49,33 +36,6 @@ config_base_default = {
|
|||
}
|
||||
}
|
||||
|
||||
config_adv_ref = {
|
||||
"wsl": {
|
||||
"automount": {
|
||||
"enabled": "automount",
|
||||
"mountfstab": "mountfstab",
|
||||
},
|
||||
"interop": {
|
||||
"enabled": "interop_enabled",
|
||||
"appendwindowspath": "interop_appendwindowspath",
|
||||
}
|
||||
},
|
||||
"ubuntu": {
|
||||
"GUI": {
|
||||
"theme": "gui_theme",
|
||||
"followwintheme": "gui_followwintheme",
|
||||
},
|
||||
"Interop": {
|
||||
"guiintegration": "legacy_gui",
|
||||
"audiointegration": "legacy_audio",
|
||||
"advancedipdetection": "adv_ip_detect",
|
||||
},
|
||||
"Motd": {
|
||||
"wslnewsenabled": "wsl_motd_news",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
config_adv_default = {
|
||||
"wsl": {
|
||||
"automount": {
|
||||
|
@ -105,22 +65,38 @@ config_adv_default = {
|
|||
|
||||
|
||||
def wsl_config_loader(data, pathname, config_ref, id):
|
||||
if path.exists(pathname):
|
||||
config = ConfigParser()
|
||||
config.read(pathname)
|
||||
for conf_sec in config:
|
||||
if conf_sec in config_ref[id]:
|
||||
conf_sec_list = config[conf_sec]
|
||||
for conf_item in conf_sec_list:
|
||||
if conf_item in config_ref[id][conf_sec]:
|
||||
data[config_ref[id][conf_sec][conf_item]] = \
|
||||
conf_sec_list[conf_item]
|
||||
"""
|
||||
Loads the configuration from the given file type,
|
||||
section and reference config.
|
||||
|
||||
:param data: dict, the data to load into
|
||||
:param pathname: string, the path to the file to load
|
||||
:param id: string, the name of the section to load
|
||||
"""
|
||||
if not os.path.exists(pathname):
|
||||
return data
|
||||
config = ConfigParser()
|
||||
config.read(pathname)
|
||||
for conf_sec in config:
|
||||
if conf_sec in config_ref[id]:
|
||||
conf_sec_list = config[conf_sec]
|
||||
for conf_item in conf_sec_list:
|
||||
if conf_item in config_ref[id][conf_sec]:
|
||||
data[conf_sec.lower()
|
||||
+ "_" + conf_item.lower()] = \
|
||||
conf_sec_list[conf_item]
|
||||
return data
|
||||
|
||||
|
||||
def default_loader(is_advanced):
|
||||
"""
|
||||
This will load the default WSL config for the given type.
|
||||
|
||||
:param is_advanced: boolean, True if it is WSLConfigurationAdvanced,
|
||||
else is WSLConfigurationBase
|
||||
"""
|
||||
data = {}
|
||||
conf_ref = config_adv_ref if is_advanced else config_base_ref
|
||||
conf_ref = config_adv_default if is_advanced else config_base_default
|
||||
data = wsl_config_loader(data, "/etc/wsl.conf", conf_ref, "wsl")
|
||||
if is_advanced:
|
||||
data = \
|
||||
|
@ -128,74 +104,67 @@ def default_loader(is_advanced):
|
|||
return data
|
||||
|
||||
|
||||
class WSLConfig:
|
||||
def __init__(self, conf_file):
|
||||
self.conf_file = conf_file
|
||||
# TODO: remove dryrun and add root param once we write the option to .subiquity
|
||||
def wsl_config_update(config_class, is_dry_run):
|
||||
"""
|
||||
This update the configuration file for the given class.zzd
|
||||
|
||||
self.config = ConfigParser()
|
||||
self.config.BasicInterpolcation = None
|
||||
self.config.read(conf_file)
|
||||
: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"):
|
||||
temp_conf_default = config_base_default
|
||||
elif temp_confname.startswith("WSLConfigurationAdvanced"):
|
||||
temp_conf_default = config_adv_default
|
||||
else:
|
||||
raise TypeError("Invalid type name.")
|
||||
if is_dry_run:
|
||||
return
|
||||
|
||||
def drop_if_exists(self, config_section, config_setting):
|
||||
if config_setting in self.config[config_section]:
|
||||
self.config.remove_option(config_section, config_setting)
|
||||
with open(self.conf_file, 'w') as configfile:
|
||||
self.config.write(configfile)
|
||||
# update the config file
|
||||
for config_type in temp_conf_default:
|
||||
config_sections = temp_conf_default[config_type]
|
||||
|
||||
def update(self, config_section, config_setting, config_value):
|
||||
self.config[config_section][config_setting] = config_value
|
||||
with open(self.conf_file, 'w') as configfile:
|
||||
self.config.write(configfile)
|
||||
config = ConfigParser()
|
||||
config.BasicInterpolcation = None
|
||||
|
||||
|
||||
class WSLConfigHandler:
|
||||
|
||||
def __init__(self, is_dry_run):
|
||||
self.is_dry_run = is_dry_run
|
||||
self.ubuntu_conf = \
|
||||
WSLConfig("/etc/ubuntu-wsl.conf")
|
||||
self.wsl_conf = WSLConfig("/etc/wsl.conf")
|
||||
|
||||
def _select_config(self, type_input):
|
||||
type_input = type_input.lower()
|
||||
if type_input == "ubuntu":
|
||||
return self.ubuntu_conf
|
||||
elif type_input == "wsl":
|
||||
return self.wsl_conf
|
||||
if config_type == "wsl":
|
||||
conf_file = "/etc/wsl.conf"
|
||||
elif config_type == "ubuntu":
|
||||
conf_file = "/etc/ubuntu-wsl.conf"
|
||||
else:
|
||||
raise ValueError("Invalid config type '{}'.".format(type_input))
|
||||
raise TypeError("Invalid type name " % config_type)
|
||||
|
||||
def update(self, config_class):
|
||||
if self.is_dry_run:
|
||||
log.debug("mimicking setting config %s",
|
||||
config_class)
|
||||
temp_conf_ref = {}
|
||||
temp_conf_default = {}
|
||||
test_confname = config_class.__str__()
|
||||
if test_confname.startswith("WSLConfigurationBase"):
|
||||
temp_conf_ref = config_base_ref
|
||||
temp_conf_default = config_base_default
|
||||
elif test_confname.startswith("WSLConfigurationAdvanced"):
|
||||
temp_conf_ref = config_adv_ref
|
||||
temp_conf_default = config_adv_default
|
||||
else:
|
||||
raise TypeError("Invalid type name.")
|
||||
if self.is_dry_run:
|
||||
return
|
||||
for config_type in temp_conf_ref:
|
||||
config_sections = temp_conf_ref[config_type]
|
||||
for config_section in config_sections:
|
||||
config_settings = config_sections[config_section]
|
||||
for config_setting in config_settings:
|
||||
config_realname = config_settings[config_setting]
|
||||
config_value = config_class.__dict__[config_realname]
|
||||
if temp_conf_default[config_type][config_section][
|
||||
config_setting] == config_value:
|
||||
self._select_config(config_type). \
|
||||
drop_if_exists(config_section,
|
||||
config_setting)
|
||||
else:
|
||||
self._select_config(config_type). \
|
||||
update(config_section,
|
||||
config_setting,
|
||||
config_value)
|
||||
config.read(conf_file)
|
||||
|
||||
for config_section in config_sections:
|
||||
config_settings = config_sections[config_section]
|
||||
for config_setting in config_settings:
|
||||
config_default_value = config_settings[config_setting]
|
||||
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 config_default_value == config_value:
|
||||
if config_setting in config[config_section]:
|
||||
config.remove_option(config_section, config_setting)
|
||||
# drop the section if it become empty
|
||||
if config[config_section] == {}:
|
||||
config.remove_section(config_section)
|
||||
else:
|
||||
if config_section not in config:
|
||||
config.add_section(config_section)
|
||||
if isinstance(config_value, bool):
|
||||
config_value = str(config_value).lower()
|
||||
config[config_section][config_setting] = config_value
|
||||
|
||||
with open(conf_file + ".new", 'w+') as configfile:
|
||||
config.write(configfile)
|
||||
|
||||
if os.isfile(conf_file):
|
||||
os.rename(conf_file, conf_file + ".old")
|
||||
os.move(conf_file + ".new", conf_file)
|
||||
|
|
|
@ -23,12 +23,12 @@ log = logging.getLogger('system_setup.models.wsl_configuration_advanced')
|
|||
class WSLConfigurationAdvanced(object):
|
||||
gui_theme = attr.ib()
|
||||
gui_followwintheme = attr.ib()
|
||||
legacy_gui = attr.ib()
|
||||
legacy_audio = attr.ib()
|
||||
adv_ip_detect = attr.ib()
|
||||
wsl_motd_news = attr.ib()
|
||||
automount = attr.ib()
|
||||
mountfstab = attr.ib()
|
||||
interop_guiintegration = attr.ib()
|
||||
interop_audiointegration = attr.ib()
|
||||
interop_advancedipdetection = attr.ib()
|
||||
motd_wslnewsenabled = attr.ib()
|
||||
automount_enabled = attr.ib()
|
||||
automount_mountfstab = attr.ib()
|
||||
interop_enabled = attr.ib()
|
||||
interop_appendwindowspath = attr.ib()
|
||||
|
||||
|
@ -48,12 +48,12 @@ class WSLConfigurationAdvancedModel(object):
|
|||
d['interop_appendwindowspath'] = result.interop_appendwindowspath
|
||||
d['gui_theme'] = result.gui_theme
|
||||
d['gui_followwintheme'] = result.gui_followwintheme
|
||||
d['legacy_gui'] = result.legacy_gui
|
||||
d['legacy_audio'] = result.legacy_audio
|
||||
d['adv_ip_detect'] = result.adv_ip_detect
|
||||
d['wsl_motd_news'] = result.wsl_motd_news
|
||||
d['automount'] = result.automount
|
||||
d['mountfstab'] = result.mountfstab
|
||||
d['interop_guiintegration'] = result.interop_guiintegration
|
||||
d['interop_audiointegration'] = result.interop_audiointegration
|
||||
d['interop_advancedipdetection'] = result.interop_advancedipdetection
|
||||
d['motd_wslnewsenabled'] = result.motd_wslnewsenabled
|
||||
d['automount_enabled'] = result.automount_enabled
|
||||
d['automount_mountfstab'] = result.automount_mountfstab
|
||||
self._wslconfadvanced = WSLConfigurationAdvanced(**d)
|
||||
|
||||
@property
|
||||
|
|
|
@ -21,10 +21,10 @@ log = logging.getLogger('system_setup.models.wsl_configuration_base')
|
|||
|
||||
@attr.s
|
||||
class WSLConfigurationBase(object):
|
||||
custom_path = attr.ib()
|
||||
custom_mount_opt = attr.ib()
|
||||
gen_host = attr.ib()
|
||||
gen_resolvconf = attr.ib()
|
||||
automount_root = attr.ib()
|
||||
automount_options = attr.ib()
|
||||
network_generatehosts = attr.ib()
|
||||
network_generateresolvconf = attr.ib()
|
||||
|
||||
|
||||
class WSLConfigurationBaseModel(object):
|
||||
|
@ -37,10 +37,10 @@ class WSLConfigurationBaseModel(object):
|
|||
|
||||
def apply_settings(self, result):
|
||||
d = {}
|
||||
d['custom_path'] = result.custom_path
|
||||
d['custom_mount_opt'] = result.custom_mount_opt
|
||||
d['gen_host'] = result.gen_host
|
||||
d['gen_resolvconf'] = result.gen_resolvconf
|
||||
d['automount_root'] = result.automount_root
|
||||
d['automount_options'] = result.automount_options
|
||||
d['network_generatehosts'] = result.network_generatehosts
|
||||
d['network_generateresolvconf'] = result.network_generateresolvconf
|
||||
self._wslconfbase = WSLConfigurationBase(**d)
|
||||
|
||||
@property
|
||||
|
|
|
@ -20,7 +20,7 @@ from subiquity.common.types import ApplicationState
|
|||
from subiquity.server.controller import SubiquityController
|
||||
from subiquitycore.context import with_context
|
||||
from subiquitycore.utils import run_command
|
||||
from system_setup.common.wsl_conf import WSLConfigHandler
|
||||
from system_setup.common.wsl_conf import wsl_config_update
|
||||
from system_setup.common.wsl_utils import get_userandgroups
|
||||
|
||||
log = logging.getLogger("system_setup.server.controllers.configure")
|
||||
|
@ -68,7 +68,6 @@ class ConfigureController(SubiquityController):
|
|||
|
||||
dryrun = self.app.opts.dry_run
|
||||
variant = self.app.variant
|
||||
config = WSLConfigHandler(dryrun)
|
||||
if variant == "wsl_setup":
|
||||
wsl_id = self.model.identity.user
|
||||
if dryrun:
|
||||
|
@ -93,9 +92,10 @@ class ConfigureController(SubiquityController):
|
|||
raise Exception("Failed to assign groups to user %s" %
|
||||
wsl_id.username)
|
||||
else:
|
||||
config.update(self.model.wslconfadvanced.wslconfadvanced)
|
||||
wsl_config_update(self.model.wslconfadvanced.wslconfadvanced,
|
||||
dryrun)
|
||||
|
||||
config.update(self.model.wslconfbase.wslconfbase)
|
||||
wsl_config_update(self.model.wslconfbase.wslconfbase, dryrun)
|
||||
|
||||
self.app.update_state(ApplicationState.DONE)
|
||||
except Exception:
|
||||
|
|
|
@ -40,12 +40,12 @@ class WSLConfigurationAdvancedController(SubiquityController):
|
|||
'interop_appendwindowspath': {'type': 'boolean'},
|
||||
'gui_theme': {'type': 'string'},
|
||||
'gui_followwintheme': {'type': 'boolean'},
|
||||
'legacy_gui': {'type': 'boolean'},
|
||||
'legacy_audio': {'type': 'boolean'},
|
||||
'adv_ip_detect': {'type': 'boolean'},
|
||||
'wsl_motd_news': {'type': 'boolean'},
|
||||
'automount': {'type': 'boolean'},
|
||||
'mountfstab': {'type': 'boolean'}
|
||||
'interop_guiintegration': {'type': 'boolean'},
|
||||
'interop_audiointegration': {'type': 'boolean'},
|
||||
'interop_advancedipdetection': {'type': 'boolean'},
|
||||
'motd_wslnewsenabled': {'type': 'boolean'},
|
||||
'automount_enabled': {'type': 'boolean'},
|
||||
'automount_mountfstab': {'type': 'boolean'}
|
||||
},
|
||||
'additionalProperties': False,
|
||||
}
|
||||
|
@ -65,12 +65,17 @@ class WSLConfigurationAdvancedController(SubiquityController):
|
|||
data['interop_appendwindowspath']),
|
||||
gui_theme=data['gui_theme'],
|
||||
gui_followwintheme=bool_converter(data['gui_followwintheme']),
|
||||
legacy_gui=bool_converter(data['legacy_gui']),
|
||||
legacy_audio=bool_converter(data['legacy_audio']),
|
||||
adv_ip_detect=bool_converter(data['adv_ip_detect']),
|
||||
wsl_motd_news=bool_converter(data['wsl_motd_news']),
|
||||
automount=bool_converter(data['automount']),
|
||||
mountfstab=bool_converter(data['mountfstab']),
|
||||
interop_guiintegration=bool_converter(
|
||||
data['interop_guiintegration']),
|
||||
interop_audiointegration=bool_converter(
|
||||
data['interop_audiointegration']),
|
||||
interop_advancedipdetection=bool_converter(
|
||||
data['interop_advancedipdetection']),
|
||||
motd_wslnewsenabled=bool_converter(
|
||||
data['motd_wslnewsenabled']),
|
||||
automount_enabled=bool_converter(data['automount_enabled']),
|
||||
automount_mountfstab=bool_converter(
|
||||
data['automount_mountfstab']),
|
||||
)
|
||||
self.model.apply_settings(reconf_data)
|
||||
|
||||
|
@ -81,12 +86,13 @@ class WSLConfigurationAdvancedController(SubiquityController):
|
|||
interop_appendwindowspath=data['interop_appendwindowspath'],
|
||||
gui_theme=data['gui_theme'],
|
||||
gui_followwintheme=data['gui_followwintheme'],
|
||||
legacy_gui=data['legacy_gui'],
|
||||
legacy_audio=data['legacy_audio'],
|
||||
adv_ip_detect=data['adv_ip_detect'],
|
||||
wsl_motd_news=data['wsl_motd_news'],
|
||||
automount=data['automount'],
|
||||
mountfstab=data['mountfstab']
|
||||
interop_guiintegration=data['interop_guiintegration'],
|
||||
interop_audiointegration=data['interop_audiointegration'],
|
||||
interop_advancedipdetection=data[
|
||||
'interop_advancedipdetection'],
|
||||
motd_wslnewsenabled=data['motd_wslnewsenabled'],
|
||||
automount_enabled=data['automount_enabled'],
|
||||
automount_mountfstab=data['automount_mountfstab']
|
||||
)
|
||||
self.model.apply_settings(reconf_data)
|
||||
|
||||
|
@ -101,18 +107,26 @@ class WSLConfigurationAdvancedController(SubiquityController):
|
|||
async def GET(self) -> WSLConfigurationAdvanced:
|
||||
data = WSLConfigurationAdvanced()
|
||||
if self.model.wslconfadvanced is not None:
|
||||
data.interop_enabled = self.model.wslconfadvanced.interop_enabled
|
||||
data.interop_enabled = \
|
||||
self.model.wslconfadvanced.interop_enabled
|
||||
data.interop_appendwindowspath = \
|
||||
self.model.wslconfadvanced.interop_appendwindowspath
|
||||
data.gui_theme = self.model.wslconfadvanced.gui_theme
|
||||
data.gui_theme = \
|
||||
self.model.wslconfadvanced.gui_theme
|
||||
data.gui_followwintheme = \
|
||||
self.model.wslconfadvanced.gui_followwintheme
|
||||
data.legacy_gui = self.model.wslconfadvanced.legacy_gui
|
||||
data.legacy_audio = self.model.wslconfadvanced.legacy_audio
|
||||
data.adv_ip_detect = self.model.wslconfadvanced.adv_ip_detect
|
||||
data.wsl_motd_news = self.model.wslconfadvanced.wsl_motd_news
|
||||
data.automount = self.model.wslconfadvanced.automount
|
||||
data.mountfstab = self.model.wslconfadvanced.mountfstab
|
||||
data.interop_guiintegration = \
|
||||
self.model.wslconfadvanced.interop_guiintegration
|
||||
data.interop_audiointegration = \
|
||||
self.model.wslconfadvanced.interop_audiointegration
|
||||
data.interop_advancedipdetection = \
|
||||
self.model.wslconfadvanced.interop_advancedipdetection
|
||||
data.motd_wslnewsenabled = \
|
||||
self.model.wslconfadvanced.motd_wslnewsenabled
|
||||
data.automount_enabled = \
|
||||
self.model.wslconfadvanced.automount_enabled
|
||||
data.automount_mountfstab = \
|
||||
self.model.wslconfadvanced.automount_mountfstab
|
||||
return data
|
||||
|
||||
async def POST(self, data: WSLConfigurationAdvanced):
|
||||
|
|
|
@ -36,10 +36,10 @@ class WSLConfigurationBaseController(SubiquityController):
|
|||
autoinstall_schema = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'custom_path': {'type': 'string'},
|
||||
'custom_mount_opt': {'type': 'string'},
|
||||
'gen_host': {'type': 'boolean'},
|
||||
'gen_resolvconf': {'type': 'boolean'},
|
||||
'automount_root': {'type': 'string'},
|
||||
'automount_options': {'type': 'string'},
|
||||
'network_generatehosts': {'type': 'boolean'},
|
||||
'network_generateresolvconf': {'type': 'boolean'},
|
||||
},
|
||||
'additionalProperties': False,
|
||||
}
|
||||
|
@ -54,20 +54,22 @@ class WSLConfigurationBaseController(SubiquityController):
|
|||
def bool_converter(x):
|
||||
return x.lower() == 'true'
|
||||
conf_data = WSLConfigurationBase(
|
||||
custom_path=data['custom_path'],
|
||||
custom_mount_opt=data['custom_mount_opt'],
|
||||
gen_host=bool_converter(data['gen_host']),
|
||||
gen_resolvconf=bool_converter(data['gen_resolvconf']),
|
||||
automount_root=data['automount_root'],
|
||||
automount_options=data['automount_options'],
|
||||
network_generatehosts=bool_converter(
|
||||
data['network_generatehosts']),
|
||||
network_generateresolvconf=bool_converter(
|
||||
data['network_generateresolvconf']),
|
||||
)
|
||||
self.model.apply_settings(conf_data)
|
||||
|
||||
def load_autoinstall_data(self, data):
|
||||
if data is not None:
|
||||
identity_data = WSLConfigurationBase(
|
||||
custom_path=data['custom_path'],
|
||||
custom_mount_opt=data['custom_mount_opt'],
|
||||
gen_host=data['gen_host'],
|
||||
gen_resolvconf=data['gen_resolvconf'],
|
||||
automount_root=data['automount_root'],
|
||||
automount_options=data['automount_options'],
|
||||
network_generatehosts=data['network_generatehosts'],
|
||||
network_generateresolvconf=data['network_generateresolvconf'],
|
||||
)
|
||||
self.model.apply_settings(identity_data)
|
||||
|
||||
|
@ -82,10 +84,12 @@ class WSLConfigurationBaseController(SubiquityController):
|
|||
async def GET(self) -> WSLConfigurationBase:
|
||||
data = WSLConfigurationBase()
|
||||
if self.model.wslconfbase is not None:
|
||||
data.custom_path = self.model.wslconfbase.custom_path
|
||||
data.custom_mount_opt = self.model.wslconfbase.custom_mount_opt
|
||||
data.gen_host = self.model.wslconfbase.gen_host
|
||||
data.gen_resolvconf = self.model.wslconfbase.gen_resolvconf
|
||||
data.automount_root = self.model.wslconfbase.automount_root
|
||||
data.automount_options = self.model.wslconfbase.automount_options
|
||||
data.network_generatehosts = \
|
||||
self.model.wslconfbase.network_generatehosts
|
||||
data.network_generateresolvconf = \
|
||||
self.model.wslconfbase.network_generateresolvconf
|
||||
return data
|
||||
|
||||
async def POST(self, data: WSLConfigurationBase):
|
||||
|
|
|
@ -42,55 +42,53 @@ class WSLConfigurationAdvancedForm(Form):
|
|||
def __init__(self, initial):
|
||||
super().__init__(initial=initial)
|
||||
|
||||
automount = BooleanField(_("Enable Auto-Mount"),
|
||||
help=_("Whether the Auto-Mount freature is"
|
||||
" enabled. This feature allows you "
|
||||
"to mount Windows drive in WSL"))
|
||||
mountfstab = BooleanField(_("Mount `/etc/fstab`"),
|
||||
help=_("Whether `/etc/fstab` will be mounted."
|
||||
" The configuration file `/etc/fstab` "
|
||||
"contains the necessary information to"
|
||||
" automate the process of mounting "
|
||||
"partitions. "))
|
||||
interop_enabled = BooleanField(_("Enable Interop"),
|
||||
help=_("Whether the interoperability is"
|
||||
" enabled"))
|
||||
interop_appendwindowspath = BooleanField(_("Append Windows Path"),
|
||||
help=_("Whether Windows Path "
|
||||
"will be append in the"
|
||||
" PATH environment "
|
||||
"variable in WSL."))
|
||||
gui_theme = ChoiceField(_("GUI Theme"),
|
||||
help=_("This option changes the Ubuntu theme."),
|
||||
choices=["default", "light", "dark"])
|
||||
gui_followwintheme = BooleanField(_("Follow Windows Theme"),
|
||||
help=_("This option manages whether the"
|
||||
" Ubuntu theme follows the "
|
||||
"Windows theme; that is, when "
|
||||
"Windows uses dark theme, "
|
||||
"Ubuntu also uses dark theme."
|
||||
" Requires WSL interoperability"
|
||||
" enabled. "))
|
||||
legacy_gui = BooleanField(_("Legacy GUI Integration"),
|
||||
help=_("This option enables the Legacy GUI "
|
||||
"Integration on Windows 10. Requires"
|
||||
" a Third-party X Server."))
|
||||
legacy_audio = BooleanField(_("Legacy Audio Integration"),
|
||||
help=_("This option enables the Legacy "
|
||||
"Audio Integration on Windows 10. "
|
||||
"Requires PulseAudio for "
|
||||
"Windows Installed."))
|
||||
adv_ip_detect = BooleanField(_("Advanced IP Detection"),
|
||||
help=_("This option enables advanced "
|
||||
"detection of IP by Windows "
|
||||
"IPv4 Address which is more "
|
||||
"reliable to use with WSL2. "
|
||||
"Requires WSL interoperability"
|
||||
" enabled."))
|
||||
wsl_motd_news = BooleanField(_("Enable WSL News"),
|
||||
help=_("This options allows you to control"
|
||||
" your MOTD News. Toggling it on "
|
||||
"allows you to see the MOTD."))
|
||||
automount_enabled = \
|
||||
BooleanField(_("Enable Auto-Mount"),
|
||||
help=_("Whether the Auto-Mount freature is enabled. "
|
||||
"This feature allows you to mount Windows drive"
|
||||
" in WSL."))
|
||||
automount_mountfstab = \
|
||||
BooleanField(_("Mount `/etc/fstab`"),
|
||||
help=_("Whether `/etc/fstab` will be mounted. The "
|
||||
"configuration file `/etc/fstab` contains "
|
||||
"the necessary information to automate the"
|
||||
" process of mounting partitions. "))
|
||||
interop_enabled = \
|
||||
BooleanField(_("Enable Interop"),
|
||||
help=_("Whether the interoperability is enabled"))
|
||||
interop_appendwindowspath = \
|
||||
BooleanField(_("Append Windows Path"),
|
||||
help=_("Whether Windows Path will be append in the"
|
||||
" PATH environment variable in WSL."))
|
||||
gui_theme = \
|
||||
ChoiceField(_("GUI Theme"),
|
||||
help=_("This option changes the Ubuntu theme."),
|
||||
choices=["default", "light", "dark"])
|
||||
gui_followwintheme = \
|
||||
BooleanField(_("Follow Windows Theme"),
|
||||
help=_("This option manages whether the Ubuntu theme"
|
||||
" follows the Windows theme; that is, when "
|
||||
"Windows uses dark theme, Ubuntu also uses dark"
|
||||
" theme. Requires WSL interoperability enabled. "))
|
||||
interop_guiintegration = \
|
||||
BooleanField(_("Legacy GUI Integration"),
|
||||
help=_("This option enables the Legacy GUI Integration "
|
||||
"on Windows 10. Requires a Third-party X Server."))
|
||||
interop_audiointegration = \
|
||||
BooleanField(_("Legacy Audio Integration"),
|
||||
help=_("This option enables the Legacy Audio Integration "
|
||||
"on Windows 10. Requires PulseAudio for Windows "
|
||||
"Installed."))
|
||||
interop_advancedipdetection = \
|
||||
BooleanField(_("Advanced IP Detection"),
|
||||
help=_("This option enables advanced detection of IP by "
|
||||
"Windows IPv4 Address which is more reliable to "
|
||||
"use with WSL2. Requires WSL interoperability "
|
||||
"enabled."))
|
||||
motd_wslnewsenabled = \
|
||||
BooleanField(_("Enable WSL News"),
|
||||
help=_("This option allows you to control your MOTD News."
|
||||
" Toggling it on allows you to see the MOTD."))
|
||||
|
||||
|
||||
class WSLConfigurationAdvancedView(BaseView):
|
||||
|
@ -107,12 +105,15 @@ class WSLConfigurationAdvancedView(BaseView):
|
|||
configuration_data.interop_appendwindowspath,
|
||||
'gui_theme': configuration_data.gui_theme,
|
||||
'gui_followwintheme': configuration_data.gui_followwintheme,
|
||||
'legacy_gui': configuration_data.legacy_gui,
|
||||
'legacy_audio': configuration_data.legacy_audio,
|
||||
'adv_ip_detect': configuration_data.adv_ip_detect,
|
||||
'wsl_motd_news': configuration_data.wsl_motd_news,
|
||||
'automount': configuration_data.automount,
|
||||
'mountfstab': configuration_data.mountfstab,
|
||||
'interop_guiintegration': configuration_data
|
||||
.interop_guiintegration,
|
||||
'interop_audiointegration': configuration_data
|
||||
.interop_audiointegration,
|
||||
'interop_advancedipdetection': configuration_data
|
||||
.interop_advancedipdetection,
|
||||
'motd_wslnewsenabled': configuration_data.motd_wslnewsenabled,
|
||||
'automount_enabled': configuration_data.automount_enabled,
|
||||
'automount_mountfstab': configuration_data.automount_mountfstab,
|
||||
}
|
||||
self.form = WSLConfigurationAdvancedForm(initial=initial)
|
||||
|
||||
|
@ -133,10 +134,11 @@ class WSLConfigurationAdvancedView(BaseView):
|
|||
.interop_appendwindowspath.value,
|
||||
gui_theme=self.form.gui_theme.value,
|
||||
gui_followwintheme=self.form.gui_followwintheme.value,
|
||||
legacy_gui=self.form.legacy_gui.value,
|
||||
legacy_audio=self.form.legacy_audio.value,
|
||||
adv_ip_detect=self.form.adv_ip_detect.value,
|
||||
wsl_motd_news=self.form.wsl_motd_news.value,
|
||||
automount=self.form.automount.value,
|
||||
mountfstab=self.form.mountfstab.value,
|
||||
interop_guiintegration=self.form.interop_guiintegration.value,
|
||||
interop_audiointegration=self.form.interop_audiointegration.value,
|
||||
interop_advancedipdetection=self
|
||||
.form.interop_advancedipdetection.value,
|
||||
motd_wslnewsenabled=self.form.motd_wslnewsenabled.value,
|
||||
automount_enabled=self.form.automount_enabled.value,
|
||||
automount_mountfstab=self.form.automount_mountfstab.value,
|
||||
))
|
||||
|
|
|
@ -41,24 +41,28 @@ class WSLConfBaseForm(Form):
|
|||
def __init__(self, initial):
|
||||
super().__init__(initial=initial)
|
||||
|
||||
custom_path = MountField(_("Mount Location"),
|
||||
help=_("Location for the automount"))
|
||||
custom_mount_opt = StringField(_("Mount Option"),
|
||||
help=_("Mount option passed "
|
||||
"for the automount"))
|
||||
gen_host = BooleanField(_("Enable Host Generation"), help=_(
|
||||
"Selecting enables /etc/host re-generation at every start"))
|
||||
gen_resolvconf = BooleanField(_("Enable resolv.conf Generation"), help=_(
|
||||
"Selecting enables /etc/resolv.conf re-generation at every start"))
|
||||
automount_root = MountField(_("Mount Location"),
|
||||
help=_("Location for the automount"))
|
||||
automount_options = StringField(_("Mount Option"),
|
||||
help=_("Mount option passed "
|
||||
"for the automount"))
|
||||
network_generatehosts = \
|
||||
BooleanField(_("Enable Host Generation"),
|
||||
help=_("Selecting enables /etc/host re-generation at"
|
||||
" every start"))
|
||||
network_generateresolvconf = \
|
||||
BooleanField(_("Enable resolv.conf Generation"),
|
||||
help=_("Selecting enables /etc/resolv.conf re-generation"
|
||||
" at every start"))
|
||||
|
||||
def validate_custom_path(self):
|
||||
p = self.custom_path.value
|
||||
def validate_automount_root(self):
|
||||
p = self.automount_root.value
|
||||
if p != "" and (re.fullmatch(r"(/[^/ ]*)+/?", p) is None):
|
||||
return _("Mount location must be a absolute UNIX path"
|
||||
" without space.")
|
||||
|
||||
def validate_custom_mount_opt(self):
|
||||
o = self.custom_mount_opt.value
|
||||
def validate_automount_options(self):
|
||||
o = self.automount_options.value
|
||||
# filesystem independent mount option
|
||||
fsimo = [r"async", r"(no)?atime", r"(no)?auto",
|
||||
r"(fs|def|root)?context=\w+", r"(no)?dev", r"(no)?diratime",
|
||||
|
@ -99,10 +103,11 @@ class WSLConfigurationBaseView(BaseView):
|
|||
self.controller = controller
|
||||
|
||||
initial = {
|
||||
'custom_path': configuration_data.custom_path,
|
||||
'custom_mount_opt': configuration_data.custom_mount_opt,
|
||||
'gen_host': configuration_data.gen_host,
|
||||
'gen_resolvconf': configuration_data.gen_resolvconf,
|
||||
'automount_root': configuration_data.automount_root,
|
||||
'automount_options': configuration_data.automount_options,
|
||||
'network_generatehosts': configuration_data.network_generatehosts,
|
||||
'network_generateresolvconf': configuration_data
|
||||
.network_generateresolvconf,
|
||||
}
|
||||
self.form = WSLConfBaseForm(initial=initial)
|
||||
|
||||
|
@ -118,8 +123,9 @@ class WSLConfigurationBaseView(BaseView):
|
|||
|
||||
def done(self, result):
|
||||
self.controller.done(WSLConfigurationBase(
|
||||
custom_path=self.form.custom_path.value,
|
||||
custom_mount_opt=self.form.custom_mount_opt.value,
|
||||
gen_host=self.form.gen_host.value,
|
||||
gen_resolvconf=self.form.gen_resolvconf.value
|
||||
automount_root=self.form.automount_root.value,
|
||||
automount_options=self.form.automount_options.value,
|
||||
network_generatehosts=self.form.network_generatehosts.value,
|
||||
network_generateresolvconf=self
|
||||
.form.network_generateresolvconf.value
|
||||
))
|
||||
|
|
Loading…
Reference in New Issue