Skip to content

Commit

Permalink
Raise exception on unsupported layouts from Live
Browse files Browse the repository at this point in the history
The Live system (Gnome Shell) supports ibus input methods which are not
supported by Anaconda. Anaconda can't support ibus because vconsole nor
localed supports this because they need to be usable in TTY environment.
  • Loading branch information
jkonecny12 committed Mar 3, 2025
1 parent 5151ad1 commit 3c9e234
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 19 deletions.
24 changes: 15 additions & 9 deletions pyanaconda/modules/localization/live_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from pyanaconda.anaconda_loggers import get_module_logger
from pyanaconda.core.configuration.anaconda import conf
from pyanaconda.core.util import execWithCaptureAsLiveUser
from pyanaconda.modules.common.errors.configuration import KeyboardConfigurationError

log = get_module_logger(__name__)

Expand Down Expand Up @@ -91,14 +92,19 @@ def _convert_to_xkb_format(self, sources):
result = []

for t in sources:
# keep only 'xkb' type and ignore 'ibus' variants which can't be used in localed
if t[0] == "xkb":
layout = t[1]
# change layout variant from 'cz+qwerty' to 'cz (qwerty)'
if '+' in layout:
layout, variant = layout.split('+')
result.append(f"{layout} ({variant})")
else:
result.append(layout)
# keep only 'xkb' type and raise an error on 'ibus' variants which can't
# be used in localed
if t[0] != "xkb":
raise KeyboardConfigurationError(
f"Live system has layout which can't be used by Anaconda - {t}"
)

layout = t[1]
# change layout variant from 'cz+qwerty' to 'cz (qwerty)'
if '+' in layout:
layout, variant = layout.split('+')
result.append(f"{layout} ({variant})")
else:
result.append(layout)

return result
2 changes: 2 additions & 0 deletions pyanaconda/modules/localization/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def run(self):
:returns: tuple of X layouts and VC keyboard settings
:rtype: (list(str), str))
:raises: KeyboardConfigurationError exception when we should use unsupported layouts
from Live
"""
return get_missing_keyboard_configuration(self._localed_wrapper,
self._x_layouts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import unittest
from unittest.mock import patch

import pytest

from pyanaconda.modules.common.errors.configuration import KeyboardConfigurationError
from pyanaconda.modules.localization.live_keyboard import (
GnomeShellKeyboard,
get_live_keyboard_instance,
Expand All @@ -35,13 +38,24 @@ def test_get_live_keyboard_instance(self, mocked_conf):
mocked_conf.system.provides_liveuser = False
assert get_live_keyboard_instance() is None

def _check_gnome_shell_layouts_conversion(self, mocked_exec_with_capture, system_input, output):
def _check_gnome_shell_layouts_conversion(self,
mocked_exec_with_capture,
system_input,
output,
should_raise):
mocked_exec_with_capture.reset_mock()
mocked_exec_with_capture.return_value = system_input

gs = GnomeShellKeyboard()

assert gs.read_keyboard_layouts() == output
if should_raise:
with pytest.raises(KeyboardConfigurationError):
gs.read_keyboard_layouts()
return

result = gs.read_keyboard_layouts()

assert result == output
mocked_exec_with_capture.assert_called_once_with(
"gsettings",
["get", "org.gnome.desktop.input-sources", "sources"]
Expand All @@ -54,40 +68,46 @@ def test_gnome_shell_keyboard(self, mocked_exec_with_capture):
self._check_gnome_shell_layouts_conversion(
mocked_exec_with_capture=mocked_exec_with_capture,
system_input=r"[('xkb', 'cz')]",
output=["cz"]
output=["cz"],
should_raise=False
)

# test one complex layout is set
self._check_gnome_shell_layouts_conversion(
mocked_exec_with_capture=mocked_exec_with_capture,
system_input=r"[('xkb', 'cz+qwerty')]",
output=["cz (qwerty)"]
output=["cz (qwerty)"],
should_raise=False
)

# test multiple layouts are set
self._check_gnome_shell_layouts_conversion(
mocked_exec_with_capture=mocked_exec_with_capture,
system_input=r"[('xkb', 'cz+qwerty'), ('xkb', 'us'), ('xkb', 'cz+dvorak-ucw')]",
output=["cz (qwerty)", "us", "cz (dvorak-ucw)"]
output=["cz (qwerty)", "us", "cz (dvorak-ucw)"],
should_raise=False
)

# test layouts with ibus (ibus is ignored)
# test layouts with ibus (ibus will raise error)
self._check_gnome_shell_layouts_conversion(
mocked_exec_with_capture=mocked_exec_with_capture,
system_input=r"[('xkb', 'cz'), ('ibus', 'libpinyin')]",
output=["cz"]
output=[],
should_raise=True
)

# test only ibus layout
# test only ibus layout (raise the error)
self._check_gnome_shell_layouts_conversion(
mocked_exec_with_capture=mocked_exec_with_capture,
system_input=r"[('ibus', 'libpinyin')]",
output=[]
output=[],
should_raise=True
)

# test wrong input
self._check_gnome_shell_layouts_conversion(
mocked_exec_with_capture=mocked_exec_with_capture,
system_input=r"wrong input",
output=[]
output=[],
should_raise=False
)

0 comments on commit 3c9e234

Please sign in to comment.