Moving logic form SystemSetupModel to controllers.
- In order to stay confined into system_setup, WSLLocaleController had to be recriated.
This commit is contained in:
parent
10f209ad81
commit
4c0ad44738
|
@ -80,7 +80,7 @@ def main():
|
||||||
logger.info("Arguments passed: {}".format(sys.argv))
|
logger.info("Arguments passed: {}".format(sys.argv))
|
||||||
|
|
||||||
prefillFile = opts.prefill
|
prefillFile = opts.prefill
|
||||||
if opts.prefill:
|
if prefillFile:
|
||||||
if os.path.exists(prefillFile):
|
if os.path.exists(prefillFile):
|
||||||
statInfo = os.stat(prefillFile)
|
statInfo = os.stat(prefillFile)
|
||||||
mode = statInfo.st_mode
|
mode = statInfo.st_mode
|
||||||
|
|
|
@ -20,8 +20,8 @@ from subiquity.server.controllers.cmdlist import (
|
||||||
)
|
)
|
||||||
from subiquity.server.controllers.reporting import ReportingController
|
from subiquity.server.controllers.reporting import ReportingController
|
||||||
from subiquity.server.controllers.userdata import UserdataController
|
from subiquity.server.controllers.userdata import UserdataController
|
||||||
from subiquity.server.controllers.locale import LocaleController
|
|
||||||
from .identity import WSLIdentityController
|
from .identity import WSLIdentityController
|
||||||
|
from .locale import WSLLocaleController
|
||||||
from .wslconfbase import WSLConfigurationBaseController
|
from .wslconfbase import WSLConfigurationBaseController
|
||||||
from .wslconfadvanced import WSLConfigurationAdvancedController
|
from .wslconfadvanced import WSLConfigurationAdvancedController
|
||||||
from .configure import ConfigureController
|
from .configure import ConfigureController
|
||||||
|
@ -32,7 +32,7 @@ __all__ = [
|
||||||
'ErrorController',
|
'ErrorController',
|
||||||
'WSLIdentityController',
|
'WSLIdentityController',
|
||||||
'LateController',
|
'LateController',
|
||||||
'LocaleController',
|
'WSLLocaleController',
|
||||||
'ReportingController',
|
'ReportingController',
|
||||||
'SetupShutdownController',
|
'SetupShutdownController',
|
||||||
'UserdataController',
|
'UserdataController',
|
||||||
|
|
|
@ -36,6 +36,28 @@ class WSLIdentityController(IdentityController):
|
||||||
'additionalProperties': False,
|
'additionalProperties': False,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def __init__(self, app):
|
||||||
|
super().__init__(app)
|
||||||
|
if app.prefillInfo is None or self.interactive() is False:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Only applies when interactive and prefill Info is set.
|
||||||
|
idata = app.prefillInfo.get('WSLIdentity', None)
|
||||||
|
if idata is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Cannot call load_autoinstall_data because password is
|
||||||
|
# required in that context, but not here.
|
||||||
|
identity_data = IdentityData(
|
||||||
|
realname=idata.get('realname', ''),
|
||||||
|
username=idata.get('username', ''),
|
||||||
|
hostname='',
|
||||||
|
crypted_password='',
|
||||||
|
)
|
||||||
|
|
||||||
|
self.model.add_user(identity_data)
|
||||||
|
log.debug('Prefilled Identity: {}'.format(self.model.user))
|
||||||
|
|
||||||
def load_autoinstall_data(self, data):
|
def load_autoinstall_data(self, data):
|
||||||
if data is not None:
|
if data is not None:
|
||||||
identity_data = IdentityData(
|
identity_data = IdentityData(
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
# Copyright 2021 Canonical, Ltd.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from subiquity.server.controllers.locale import LocaleController
|
||||||
|
|
||||||
|
log = logging.getLogger('system_setup.server.controllers.locale')
|
||||||
|
|
||||||
|
|
||||||
|
class WSLLocaleController(LocaleController):
|
||||||
|
def start(self):
|
||||||
|
if self.app.prefillInfo:
|
||||||
|
welcome = self.app.prefillInfo.get('Welcome', {'lang': None})
|
||||||
|
win_lang = welcome.get('lang')
|
||||||
|
if win_lang:
|
||||||
|
self.model.selected_language = win_lang
|
||||||
|
log.debug('Prefilled Language: {}'
|
||||||
|
.format(self.model.selected_language))
|
||||||
|
|
||||||
|
super().start()
|
|
@ -39,13 +39,14 @@ POSTINSTALL_MODEL_NAMES = ModelNames(set())
|
||||||
|
|
||||||
|
|
||||||
class SystemSetupServer(SubiquityServer):
|
class SystemSetupServer(SubiquityServer):
|
||||||
|
prefillInfo = None
|
||||||
|
|
||||||
from system_setup.server import controllers as controllers_mod
|
from system_setup.server import controllers as controllers_mod
|
||||||
controllers = [
|
controllers = [
|
||||||
"Early",
|
"Early",
|
||||||
"Reporting",
|
"Reporting",
|
||||||
"Error",
|
"Error",
|
||||||
"Locale",
|
"WSLLocale",
|
||||||
"WSLIdentity",
|
"WSLIdentity",
|
||||||
"WSLConfigurationBase",
|
"WSLConfigurationBase",
|
||||||
"WSLConfigurationAdvanced",
|
"WSLConfigurationAdvanced",
|
||||||
|
@ -63,6 +64,16 @@ class SystemSetupServer(SubiquityServer):
|
||||||
self.log_syslog_id = ""
|
self.log_syslog_id = ""
|
||||||
if is_reconfigure(opts.dry_run):
|
if is_reconfigure(opts.dry_run):
|
||||||
self.set_source_variant("wsl_configuration")
|
self.set_source_variant("wsl_configuration")
|
||||||
|
if self.opts.prefill:
|
||||||
|
with open(self.opts.prefill, 'r') as stream:
|
||||||
|
try:
|
||||||
|
# Shared with controllers thru self.app.
|
||||||
|
self.prefillInfo = yaml.safe_load(stream)
|
||||||
|
except yaml.YAMLError as exc:
|
||||||
|
log.error('Exception while parsing prefill file: {}.'
|
||||||
|
' Ignoring file.'.format(self.opts.prefill))
|
||||||
|
log.error(exc)
|
||||||
|
self.prefillInfo = None
|
||||||
|
|
||||||
def make_model(self):
|
def make_model(self):
|
||||||
root = '/'
|
root = '/'
|
||||||
|
|
Loading…
Reference in New Issue