diff --git a/subiquity/models/locale.py b/subiquity/models/locale.py index cfa60af6..01afbf05 100644 --- a/subiquity/models/locale.py +++ b/subiquity/models/locale.py @@ -15,6 +15,8 @@ import logging +from subiquitycore.utils import split_cmd_output + log = logging.getLogger('subiquity.models.locale') @@ -27,6 +29,9 @@ class LocaleModel: selected_language = None locale_support = "locale-only" + def __init__(self, chroot_prefix): + self.chroot_prefix = chroot_prefix + def switch_language(self, code): self.selected_language = code @@ -42,3 +47,15 @@ class LocaleModel: if '.' not in locale and '_' in locale: locale += '.UTF-8' return {'locale': locale} + + async def target_packages(self): + if self.selected_language is None: + return [] + if self.locale_support != "langpack": + return [] + lang = self.selected_language.split('.')[0] + if lang == "C": + return [] + + return await split_cmd_output( + self.chroot_prefix + ['check-language-support', '-l', lang], None) diff --git a/subiquity/models/subiquity.py b/subiquity/models/subiquity.py index 975ba634..98e89689 100644 --- a/subiquity/models/subiquity.py +++ b/subiquity/models/subiquity.py @@ -116,7 +116,7 @@ class SubiquityModel: self.identity = IdentityModel() self.kernel = KernelModel() self.keyboard = KeyboardModel(self.root) - self.locale = LocaleModel() + self.locale = LocaleModel(self.chroot_prefix) self.mirror = MirrorModel() self.network = NetworkModel() self.packages = [] diff --git a/subiquity/server/controllers/locale.py b/subiquity/server/controllers/locale.py index eb30df5e..064d0888 100644 --- a/subiquity/server/controllers/locale.py +++ b/subiquity/server/controllers/locale.py @@ -60,4 +60,4 @@ class LocaleController(SubiquityController): async def POST(self, data: str): self.model.switch_language(data) - self.configured() + await self.configured() diff --git a/subiquitycore/utils.py b/subiquitycore/utils.py index aacc80fd..34b5e9c4 100644 --- a/subiquitycore/utils.py +++ b/subiquitycore/utils.py @@ -97,6 +97,11 @@ async def astart_command(cmd, *, stdout=subprocess.PIPE, env=_clean_env(env), **kw) +async def split_cmd_output(cmd, split_on): + cp = await arun_command(cmd, check=True) + return cp.stdout.split(split_on) + + def start_command(cmd, *, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8', errors='replace', env=None, **kw): diff --git a/system_setup/models/system_setup.py b/system_setup/models/system_setup.py index b22df4ab..7c23d775 100644 --- a/system_setup/models/system_setup.py +++ b/system_setup/models/system_setup.py @@ -52,10 +52,11 @@ class SystemSetupModel(SubiquityModel): self.root = root if root != '/': self.target = root + self.chroot_prefix = [] self.packages = [] self.userdata = {} - self.locale = LocaleModel() + self.locale = LocaleModel(self.chroot_prefix) self.identity = IdentityModel() self.wslconfbase = WSLConfigurationBaseModel() self.wslconfadvanced = WSLConfigurationAdvancedModel()