Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Hvornum <anton@hvornum.se>2021-04-22 12:43:31 +0000
committerGitHub <noreply@github.com>2021-04-22 12:43:31 +0000
commit935b878c962699cb4dc2f4ad209022de2046c7d9 (patch)
tree0da116f72216e64613598a80753fc4bf8b776f78
parentc88034fa8a76b4bff4f626b5467767457d6fef62 (diff)
parentd1560d98ec566e2951841f193b79d107cca8daeb (diff)
Merge pull request #336 from SecondThundeR/patch-2
Fix other issues of language selection
-rw-r--r--archinstall/lib/locale_helpers.py6
-rw-r--r--archinstall/lib/user_interaction.py23
2 files changed, 23 insertions, 6 deletions
diff --git a/archinstall/lib/locale_helpers.py b/archinstall/lib/locale_helpers.py
index 736bfc47..3c373bc6 100644
--- a/archinstall/lib/locale_helpers.py
+++ b/archinstall/lib/locale_helpers.py
@@ -16,6 +16,12 @@ def list_keyboard_languages():
if os.path.splitext(file)[1] == '.gz':
yield file.strip('.gz').strip('.map')
+def verify_keyboard_layout(layout):
+ for language in list_keyboard_languages():
+ if layout.lower() == language.lower():
+ return True
+ return False
+
def search_keyboard_layout(filter):
for language in list_keyboard_languages():
if filter.lower() in language.lower():
diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py
index fc62f44c..77b3d771 100644
--- a/archinstall/lib/user_interaction.py
+++ b/archinstall/lib/user_interaction.py
@@ -2,7 +2,7 @@ import getpass, pathlib, os, shutil, re
import sys, time, signal, ipaddress
from .exceptions import *
from .profiles import Profile
-from .locale_helpers import search_keyboard_layout
+from .locale_helpers import list_keyboard_languages, verify_keyboard_layout, search_keyboard_layout
from .output import log, LOG_LEVELS
from .storage import storage
from .networking import list_interfaces
@@ -360,10 +360,13 @@ def select_language(options, show_only_country_codes=True):
"""
Asks the user to select a language from the `options` dictionary parameter.
Usually this is combined with :ref:`archinstall.list_keyboard_languages`.
- :param options: A `dict` where keys are the language name, value should be a dict containing language information.
- :type options: dict
+
+ :param options: A `generator` or `list` where keys are the language name, value should be a dict containing language information.
+ :type options: generator or list
+
:param show_only_country_codes: Filters out languages that are not len(lang) == 2. This to limit the number of results from stuff like dvorak and x-latin1 alternatives.
:type show_only_country_codes: bool
+
:return: The language/dictionary key of the selected language
:rtype: str
"""
@@ -387,11 +390,17 @@ def select_language(options, show_only_country_codes=True):
return DEFAULT_KEYBOARD_LANGUAGE
elif selected_language.lower() in ('?', 'help'):
while True:
- filter_string = input('Search for layout containing (example: "sv-"): ')
+ filter_string = input("Search for layout containing (example: \"sv-\") or enter 'exit' to exit from search: ")
+
+ if filter_string.lower() == 'exit':
+ return select_language(list_keyboard_languages())
+
new_options = list(search_keyboard_layout(filter_string))
+
if len(new_options) <= 0:
- log(f"Search string '{filter_string}' yielded no results, please try another search or Ctrl+D to abort.", fg='yellow')
+ log(f"Search string '{filter_string}' yielded no results, please try another search.", fg='yellow')
continue
+
return select_language(new_options, show_only_country_codes=False)
elif selected_language.isnumeric():
selected_language = int(selected_language)
@@ -399,11 +408,13 @@ def select_language(options, show_only_country_codes=True):
log(' * Selected option is out of range * ', fg='red')
continue
return languages[selected_language]
- elif search_keyboard_layout(selected_language):
+ elif verify_keyboard_layout(selected_language):
return selected_language
else:
log(" * Given language wasn't found * ", fg='red')
+ raise RequirementError("Selecting languages require a least one language to be given as an option.")
+
def select_mirror_regions(mirrors, show_top_mirrors=True):
"""
Asks the user to select a mirror or region from the `mirrors` dictionary parameter.