From: Michael Tremer Date: Sat, 25 Feb 2023 12:02:32 +0000 (+0000) Subject: Implement selecting a keymap X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9f0a583465f62d031769012b91f2b43f244918b2;p=people%2Fms%2Fbricklayer.git Implement selecting a keymap Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 5afdb7a..4a9044f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -60,6 +60,7 @@ dist_pkgpython_PYTHON = \ src/python/disk.py \ src/python/errors.py \ src/python/i18n.py \ + src/python/keymaps.py \ src/python/logger.py \ src/python/packages.py \ src/python/step.py \ diff --git a/src/python/__init__.py b/src/python/__init__.py index 67ddb27..b57d60f 100644 --- a/src/python/__init__.py +++ b/src/python/__init__.py @@ -31,6 +31,7 @@ import pakfire from . import bootloaders from . import disk from . import i18n +from . import keymaps from . import logger from . import packages from . import step @@ -62,6 +63,7 @@ class Bricklayer(object): # Settings self.settings = { "locale" : i18n.DEFAULT_LOCALE, + "keymap" : "us", "packages" : [ "system-release", @@ -116,6 +118,7 @@ class Bricklayer(object): # An ordered list of all available steps steps = ( step.Welcome, + keymaps.SelectKeymap, timezones.SelectTimezone, disk.Scan, disk.UnattendedSelectDisk, diff --git a/src/python/keymaps.py b/src/python/keymaps.py new file mode 100644 index 0000000..13950db --- /dev/null +++ b/src/python/keymaps.py @@ -0,0 +1,60 @@ +############################################################################### +# # +# Bricklayer - An Installer for IPFire # +# Copyright (C) 2023 IPFire Development Team # +# # +# This program is free software; you can redistribute it and/or # +# modify it under the terms of the GNU General Public License # +# as published by the Free Software Foundation; either version 2 # +# 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 General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +import logging +import subprocess + +from . import step +from .i18n import _ + +# Setup logging +log = logging.getLogger("bricklayer.keymaps") + +class SelectKeymap(step.InteractiveStep): + first_install = True + + def run(self): + # Get a list of all available keymaps + try: + keymaps = self.bricklayer.command(["localectl", "list-keymaps"]) + + # Split the output by line + keymaps = { km : km for km in keymaps.splitlines() } + + # Silently skip this step if no keymaps could be loaded + except subprocess.CalledProcessError: + return + + # Which keymap is currently selected? + keymap = self.bricklayer.settings.get("keymap") + + # Ask the user to select a keymap + keymap = self.tui.select( + _("Keyboard Layout"), + _("Please select your keyboard layout:"), + keymaps, default=keymap, height=10, + ) + + log.info("Selected keymap: %s" % keymap) + + # Save in settings + self.bricklayer.settings["keymap"] = keymap + + # XXX TODO Actually apply this