SystemSetupClient to control system setup tui

This class declares the controllers we want to use and consequently,
which views in which orders we present to the user.
Reuse the Welcome controller from subiquity by reimporting it in
system_setup.client.controllers.
Redefine the restart functionality to not depends on snap.
This commit is contained in:
Didier Roche 2021-07-13 14:39:44 +02:00 committed by Jean-Baptiste Lallement
parent d8e0026df5
commit 87002bddeb
3 changed files with 101 additions and 8 deletions

View File

@ -0,0 +1,66 @@
# 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
import os
import sys
from subiquity.client.client import SubiquityClient
log = logging.getLogger('system_setup.client.client')
class SystemSetupClient(SubiquityClient):
snapd_socket_path = None
controllers = [
#"Serial",
"Welcome",
"WSLIdentity",
"Progress",
]
from system_setup.client import controllers as controllers_mod
def restart(self, remove_last_screen=True, restart_server=False):
log.debug(f"restart {remove_last_screen} {restart_server}")
if self.fg_proc is not None:
log.debug(
"killing foreground process %s before restarting",
self.fg_proc)
self.restarting = True
self.aio_loop.create_task(
self._kill_fg_proc(remove_last_screen, restart_server))
return
if remove_last_screen:
self._remove_last_screen()
if restart_server:
self.restarting = True
self.ui.block_input = True
self.aio_loop.create_task(self._restart_server())
return
if self.urwid_loop is not None:
self.urwid_loop.stop()
cmdline = sys.argv
if self.opts.dry_run:
cmdline = [
sys.executable, '-m', 'system_setup.cmd.tui',
] + sys.argv[1:] + ['--socket', self.opts.socket]
if self.opts.server_pid is not None:
cmdline.extend(['--server-pid', self.opts.server_pid])
log.debug("restarting %r", cmdline)
os.execvp(cmdline[0], cmdline)

View File

@ -0,0 +1,27 @@
# 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/>.
from .identity import WSLIdentityController
from subiquity.client.controllers import (ProgressController, WelcomeController)
__all__ = [
'WelcomeController',
'WSLIdentityController',
'ProgressController',
]

16
system_setup/cmd/tui.py Normal file → Executable file
View File

@ -23,11 +23,11 @@ import sys
from subiquitycore.log import setup_logger from subiquitycore.log import setup_logger
from subiquity.common import ( from subiquity.cmd.common import (
LOGDIR, LOGDIR,
setup_environment, setup_environment,
) )
from .server import make_server_args_parser from system_setup.cmd.server import make_server_args_parser
class ClickAction(argparse.Action): class ClickAction(argparse.Action):
@ -80,7 +80,7 @@ def main():
setup_environment() setup_environment()
# setup_environment sets $APPORT_DATA_DIR which must be set before # setup_environment sets $APPORT_DATA_DIR which must be set before
# apport is imported, which is done by this import: # apport is imported, which is done by this import:
from subiquity.client.client import SubiquityClient from system_setup.client.client import SystemSetupClient
parser = make_client_args_parser() parser = make_client_args_parser()
args = sys.argv[1:] args = sys.argv[1:]
if '--dry-run' in args: if '--dry-run' in args:
@ -93,7 +93,7 @@ def main():
server_parser = make_server_args_parser() server_parser = make_server_args_parser()
server_parser.parse_args(server_args) # just to check server_parser.parse_args(server_args) # just to check
server_output = open('.subiquity/server-output', 'w') server_output = open('.subiquity/server-output', 'w')
server_cmd = [sys.executable, '-m', 'subiquity.cmd.server'] + \ server_cmd = [sys.executable, '-m', 'system_setup.cmd.server'] + \
server_args server_args
server_proc = subprocess.Popen( server_proc = subprocess.Popen(
server_cmd, stdout=server_output, stderr=subprocess.STDOUT) server_cmd, stdout=server_output, stderr=subprocess.STDOUT)
@ -111,11 +111,11 @@ def main():
logdir = LOGDIR logdir = LOGDIR
if opts.dry_run: if opts.dry_run:
logdir = ".subiquity" logdir = ".subiquity"
logfiles = setup_logger(dir=logdir, base='subiquity-client') logfiles = setup_logger(dir=logdir, base='system_setup-client')
logger = logging.getLogger('subiquity') logger = logging.getLogger('subiquity')
version = os.environ.get("SNAP_REVISION", "unknown") version = "unknown"
logger.info("Starting Subiquity revision {}".format(version)) logger.info("Starting System Setup revision {}".format(version))
logger.info("Arguments passed: {}".format(sys.argv)) logger.info("Arguments passed: {}".format(sys.argv))
if opts.answers is None and os.path.exists(AUTO_ANSWERS_FILE): if opts.answers is None and os.path.exists(AUTO_ANSWERS_FILE):
@ -132,7 +132,7 @@ def main():
opts.answers.close() opts.answers.close()
opts.answers = None opts.answers = None
subiquity_interface = SubiquityClient(opts) subiquity_interface = SystemSetupClient(opts)
subiquity_interface.note_file_for_apport( subiquity_interface.note_file_for_apport(
"InstallerLog", logfiles['debug']) "InstallerLog", logfiles['debug'])