Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/locale_helpers.py
diff options
context:
space:
mode:
authorAnton Hvornum <anton@hvornum.se>2021-05-19 14:45:13 +0000
committerGitHub <noreply@github.com>2021-05-19 16:45:13 +0200
commit49e6cbdc545402e066bdc2daf6054abf6c1bf977 (patch)
treea1d4afcc6473d93bc958eab8241dbad616033dba /archinstall/lib/locale_helpers.py
parent52960bd686c92af4813ce302a21eb63a5aa67343 (diff)
Reworking SysCommand & Moving to localectl for locale related activities
* Moving to `localectl` rather than local file manipulation *(both for listing locales and setting them)*. * Swapped `loadkeys` for localectl. * Renamed `main` to `maim` in awesome profile. * Created `archinstall.Boot(<installation>)` which spawns a `systemd-nspawn` container against the installation target. * Exposing systemd.py's internals to archinstall global scope. * Re-worked `SysCommand` completely, it's now a wrapper for `SysCommandWorker` which supports interacting with the process in a different way. `SysCommand` should behave just like the old one, for backwards compatibility reasons. This fixes #68 and #69. * `SysCommand()` now has a `.decode()` function that defaults to `UTF-8`. * Adding back peak_output=True to pacstrap. Co-authored-by: Anton Hvornum <anton.feeds@gmail.com> Co-authored-by: Dylan Taylor <dylan@dylanmtaylor.com>
Diffstat (limited to 'archinstall/lib/locale_helpers.py')
-rw-r--r--archinstall/lib/locale_helpers.py46
1 files changed, 29 insertions, 17 deletions
diff --git a/archinstall/lib/locale_helpers.py b/archinstall/lib/locale_helpers.py
index 2db429fd..36228edc 100644
--- a/archinstall/lib/locale_helpers.py
+++ b/archinstall/lib/locale_helpers.py
@@ -1,23 +1,18 @@
-import os
-import subprocess
+import logging
-from .exceptions import *
-
-
-# from .general import sys_command
+from .exceptions import ServiceException
+from .general import SysCommand
+from .output import log
def list_keyboard_languages():
- locale_dir = '/usr/share/kbd/keymaps/'
-
- if not os.path.isdir(locale_dir):
- raise RequirementError(f'Directory containing locales does not exist: {locale_dir}')
+ for line in SysCommand("localectl --no-pager list-keymaps", environment_vars={'SYSTEMD_COLORS': '0'}):
+ yield line.decode('UTF-8').strip()
- for root, folders, files in os.walk(locale_dir):
- for file in files:
- if os.path.splitext(file)[1] == '.gz':
- yield file.strip('.gz').strip('.map')
+def list_x11_keyboard_languages():
+ for line in SysCommand("localectl --no-pager list-x11-keymap-layouts", environment_vars={'SYSTEMD_COLORS': '0'}):
+ yield line.decode('UTF-8').strip()
def verify_keyboard_layout(layout):
@@ -27,11 +22,28 @@ def verify_keyboard_layout(layout):
return False
-def search_keyboard_layout(layout_filter):
+def verify_x11_keyboard_layout(layout):
+ for language in list_x11_keyboard_languages():
+ if layout.lower() == language.lower():
+ return True
+ return False
+
+
+def search_keyboard_layout(layout):
for language in list_keyboard_languages():
- if layout_filter.lower() in language.lower():
+ if layout.lower() in language.lower():
yield language
def set_keyboard_language(locale):
- return subprocess.call(['loadkeys', locale]) == 0
+ if len(locale.strip()):
+ if not verify_keyboard_layout(locale):
+ log(f"Invalid keyboard locale specified: {locale}", fg="red", level=logging.ERROR)
+ return False
+
+ if (output := SysCommand(f'localectl set-keymap {locale}')).exit_code != 0:
+ raise ServiceException(f"Unable to set locale '{locale}' for console: {output}")
+
+ return True
+
+ return False