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.feeds+github@gmail.com>2020-09-01 09:01:14 +0200
committerAnton Hvornum <anton.feeds+github@gmail.com>2020-09-01 09:01:14 +0200
commit8f35f449396493de4327d015bfe87f700c154d44 (patch)
treec962d1de41fe292ea4795ae257f2a47dd84ba090 /archinstall/lib/locale_helpers.py
parente4b9ad9d37704eb9cac725a7b5b44ad05b244fdd (diff)
Added locale helpers in terms of keyboard language/layout. archinstall.list_keyboard_languages(), archinstall.search_keyboard_layout() and archinstall.set_keyboard_language() work together to help listing, finding and setting a keyboard layout in terminals. Won't work for X-frontends, but will do for CLI installation methods. Added a language selector-helper-function with a crude search functionality. Added all this to the guided template.
Diffstat (limited to 'archinstall/lib/locale_helpers.py')
-rw-r--r--archinstall/lib/locale_helpers.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/archinstall/lib/locale_helpers.py b/archinstall/lib/locale_helpers.py
new file mode 100644
index 00000000..2917a17d
--- /dev/null
+++ b/archinstall/lib/locale_helpers.py
@@ -0,0 +1,29 @@
+import os
+
+from .exceptions import *
+# from .general import sys_command
+
+def list_keyboard_languages(layout='qwerty'):
+ locale_dir = '/usr/share/kbd/keymaps/'
+
+ if not os.path.isdir(locale_dir):
+ raise RequirementError(f'Directory containing locales does not excist: {locale_dir}')
+
+ for root, folders, files in os.walk(locale_dir):
+ # Since qwerty is under /i386/ but other layouts are
+ # in different spots, we'll need to filter the last foldername
+ # of the path to verify against the desired layout.
+ if os.path.basename(root) != layout:
+ continue
+
+ for file in files:
+ if os.path.splitext(file)[1] == '.gz':
+ yield file.strip('.gz').strip('.map')
+
+def search_keyboard_layout(filter, layout='qwerty'):
+ for language in list_keyboard_languages(layout):
+ if filter.lower() in language.lower():
+ yield language
+
+def set_keyboard_language(locale):
+ return os.system(f'loadkeys {locale}') == 0 \ No newline at end of file