From cbb491bb918e0b553a7965144f10479047e3271d Mon Sep 17 00:00:00 2001 From: Carlos Nihelton Date: Tue, 24 May 2022 13:57:24 -0300 Subject: [PATCH 1/5] Enables customisation of the Help/About message. Variants can set a new message to customize the TUI to their intent. --- subiquity/ui/views/help.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/subiquity/ui/views/help.py b/subiquity/ui/views/help.py index 95b2ef8b..6af9d795 100644 --- a/subiquity/ui/views/help.py +++ b/subiquity/ui/views/help.py @@ -394,8 +394,9 @@ class OpenHelpMenu(WidgetWrap): class HelpMenu(PopUpLauncher): - def __init__(self, app): + def __init__(self, app, about_msg=None): self.app = app + self.about_message = about_msg self.btn = header_btn(_("Help"), on_press=self._open) self.ssh_info = None self.current_help = None @@ -440,7 +441,7 @@ class HelpMenu(PopUpLauncher): self.app.add_global_overlay(stretchy) - def about(self, sender=None): + def _default_about_msg(self): info = lsb_release(dry_run=self.app.opts.dry_run) if 'LTS' in info['description']: template = _(ABOUT_INSTALLER_LTS) @@ -450,11 +451,17 @@ class HelpMenu(PopUpLauncher): 'snap_version': os.environ.get("SNAP_VERSION", "SNAP_VERSION"), 'snap_revision': os.environ.get("SNAP_REVISION", "SNAP_REVISION"), }) + return template.format(**info) + + def about(self, sender=None): + if not self.about_message: + self.about_message = self._default_about_msg() + self._show_overlay( SimpleTextStretchy( self.app, _("About the installer"), - template.format(**info))) + self.about_message)) def ssh_help(self, sender=None): texts = ssh_help_texts(self.ssh_info) From 2adc001693f50d422c7aeba05fce821af6c45c8b Mon Sep 17 00:00:00 2001 From: Carlos Nihelton Date: Tue, 24 May 2022 13:58:13 -0300 Subject: [PATCH 2/5] Customises WSL system_setup Help/About message. --- system_setup/client/client.py | 32 +++++++++++++++++++++++++++++ system_setup/models/system_setup.py | 1 + 2 files changed, 33 insertions(+) diff --git a/system_setup/client/client.py b/system_setup/client/client.py index 05c33d05..2f48c5df 100644 --- a/system_setup/client/client.py +++ b/system_setup/client/client.py @@ -14,12 +14,39 @@ # along with this program. If not, see . import logging +import os import sys +from subiquitycore.lsb_release import lsb_release from subiquity.client.client import SubiquityClient log = logging.getLogger('system_setup.client.client') +ABOUT_UBUNTU_WSL = _(""" +Welcome to the Ubuntu WSL Installer! + +A full Ubuntu environment, deeply integrated with Windows, +for Linux application development and execution. +Optimised for cloud, web, data science, IOT and fun! + +The installer will guide you through installing Ubuntu WSL +{release} LTS. + +The installer only requires the up and down arrow keys, space (or +return) and the occasional bit of typing. + +This is version {snap_version} of the installer. +""") + + +def _about_msg(msg, dry_run): + info = lsb_release(dry_run=dry_run) + info.update({ + 'snap_version': os.environ.get("SNAP_VERSION", "SNAP_VERSION"), + 'snap_revision': os.environ.get("SNAP_REVISION", "SNAP_REVISION"), + }) + return msg.format(**info) + class SystemSetupClient(SubiquityClient): @@ -46,3 +73,8 @@ class SystemSetupClient(SubiquityClient): "Summary", ] } + + def __init__(self, opts): + super().__init__(opts) + self.help_menu.about_message = \ + _about_msg(ABOUT_UBUNTU_WSL, self.opts.dry_run) diff --git a/system_setup/models/system_setup.py b/system_setup/models/system_setup.py index bd1d8f64..2e348954 100644 --- a/system_setup/models/system_setup.py +++ b/system_setup/models/system_setup.py @@ -58,6 +58,7 @@ class SystemSetupModel(SubiquityModel): self.userdata = {} self.locale = LocaleModel(self.chroot_prefix) self.identity = IdentityModel() + self.network = None self.wslconfbase = WSLConfigurationBaseModel() self.wslconfadvanced = WSLConfigurationAdvancedModel() From 3c279829390db6ed6640a7ced25549cfba9c77be Mon Sep 17 00:00:00 2001 From: Carlos Nihelton Date: Tue, 24 May 2022 14:21:18 -0300 Subject: [PATCH 3/5] Programmatic manipulation of the lsb fields For better message composition. --- system_setup/client/client.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/system_setup/client/client.py b/system_setup/client/client.py index 2f48c5df..787fcbda 100644 --- a/system_setup/client/client.py +++ b/system_setup/client/client.py @@ -23,14 +23,13 @@ from subiquity.client.client import SubiquityClient log = logging.getLogger('system_setup.client.client') ABOUT_UBUNTU_WSL = _(""" -Welcome to the Ubuntu WSL Installer! +Welcome to the {id} Installer! A full Ubuntu environment, deeply integrated with Windows, for Linux application development and execution. Optimised for cloud, web, data science, IOT and fun! -The installer will guide you through installing Ubuntu WSL -{release} LTS. +The installer will guide you through installing {description}. The installer only requires the up and down arrow keys, space (or return) and the occasional bit of typing. @@ -41,9 +40,11 @@ This is version {snap_version} of the installer. def _about_msg(msg, dry_run): info = lsb_release(dry_run=dry_run) + newId = info["id"] + " WSL" info.update({ - 'snap_version': os.environ.get("SNAP_VERSION", "SNAP_VERSION"), - 'snap_revision': os.environ.get("SNAP_REVISION", "SNAP_REVISION"), + 'id': newId, + 'description': info["description"].replace(info["id"], newId), + 'snap_version': os.environ.get("SNAP_VERSION", "SNAP_VERSION") }) return msg.format(**info) From c6fedfb8e10ebfdadd6244cc1764afcead3809f5 Mon Sep 17 00:00:00 2001 From: Carlos Nihelton Date: Thu, 26 May 2022 07:36:12 -0300 Subject: [PATCH 4/5] Set the about message on client initialization Inherently better than being a public field to be set later. Achieves a more declarative API. --- subiquity/client/client.py | 4 ++-- subiquity/ui/views/help.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/subiquity/client/client.py b/subiquity/client/client.py index 1f49d078..2dde8384 100644 --- a/subiquity/client/client.py +++ b/subiquity/client/client.py @@ -120,13 +120,13 @@ class SubiquityClient(TuiApplication): variant_to_controllers: Dict[str, List[str]] = {} - def __init__(self, opts): + def __init__(self, opts, about_msg=None): if is_linux_tty(): self.input_filter = KeyCodesFilter() else: self.input_filter = DummyKeycodesFilter() - self.help_menu = HelpMenu(self) + self.help_menu = HelpMenu(self, about_msg) super().__init__(opts) self.interactive = None self.server_updated = None diff --git a/subiquity/ui/views/help.py b/subiquity/ui/views/help.py index 6af9d795..9c55a682 100644 --- a/subiquity/ui/views/help.py +++ b/subiquity/ui/views/help.py @@ -396,7 +396,7 @@ class HelpMenu(PopUpLauncher): def __init__(self, app, about_msg=None): self.app = app - self.about_message = about_msg + self._about_message = about_msg self.btn = header_btn(_("Help"), on_press=self._open) self.ssh_info = None self.current_help = None @@ -454,14 +454,14 @@ class HelpMenu(PopUpLauncher): return template.format(**info) def about(self, sender=None): - if not self.about_message: - self.about_message = self._default_about_msg() + if not self._about_message: + self._about_message = self._default_about_msg() self._show_overlay( SimpleTextStretchy( self.app, _("About the installer"), - self.about_message)) + self._about_message)) def ssh_help(self, sender=None): texts = ssh_help_texts(self.ssh_info) From 87112ebecfb0b413849acbdf4d1e7905daa279e3 Mon Sep 17 00:00:00 2001 From: Carlos Nihelton Date: Thu, 26 May 2022 07:37:35 -0300 Subject: [PATCH 5/5] Sets TUI about help message on super init. --- system_setup/client/client.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/system_setup/client/client.py b/system_setup/client/client.py index 787fcbda..aeb999f4 100644 --- a/system_setup/client/client.py +++ b/system_setup/client/client.py @@ -76,6 +76,4 @@ class SystemSetupClient(SubiquityClient): } def __init__(self, opts): - super().__init__(opts) - self.help_menu.about_message = \ - _about_msg(ABOUT_UBUNTU_WSL, self.opts.dry_run) + super().__init__(opts, _about_msg(ABOUT_UBUNTU_WSL, opts.dry_run))