Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/user_interaction/general_conf.py
diff options
context:
space:
mode:
Diffstat (limited to 'archinstall/lib/user_interaction/general_conf.py')
-rw-r--r--archinstall/lib/user_interaction/general_conf.py68
1 files changed, 43 insertions, 25 deletions
diff --git a/archinstall/lib/user_interaction/general_conf.py b/archinstall/lib/user_interaction/general_conf.py
index 7a6bb358..9722dc4d 100644
--- a/archinstall/lib/user_interaction/general_conf.py
+++ b/archinstall/lib/user_interaction/general_conf.py
@@ -3,7 +3,6 @@ from __future__ import annotations
import logging
import pathlib
from typing import List, Any, Optional, Dict, TYPE_CHECKING
-from typing import Union
from ..locale_helpers import list_keyboard_languages, list_timezones
from ..menu import MenuSelectionType, Menu, TextInput
@@ -29,13 +28,18 @@ def ask_ntp(preset: bool = True) -> bool:
return False if choice.value == Menu.no() else True
-def ask_hostname(preset: str = None) -> str:
+def ask_hostname(preset: str = '') -> str:
while True:
- hostname = TextInput(_('Desired hostname for the installation: '), preset).run().strip()
+ hostname = TextInput(
+ str(_('Desired hostname for the installation: ')),
+ preset
+ ).run().strip()
+
if hostname:
return hostname
-def ask_for_a_timezone(preset: str = None) -> str:
+
+def ask_for_a_timezone(preset: Optional[str] = None) -> Optional[str]:
timezones = list_timezones()
default = 'UTC'
@@ -48,10 +52,12 @@ def ask_for_a_timezone(preset: str = None) -> str:
match choice.type_:
case MenuSelectionType.Skip: return preset
- case MenuSelectionType.Selection: return choice.value
+ case MenuSelectionType.Selection: return choice.single_value
+
+ return None
-def ask_for_audio_selection(desktop: bool = True, preset: Union[str, None] = None) -> Union[str, None]:
+def ask_for_audio_selection(desktop: bool = True, preset: Optional[str] = None) -> Optional[str]:
no_audio = str(_('No audio server'))
choices = ['pipewire', 'pulseaudio'] if desktop else ['pipewire', 'pulseaudio', no_audio]
default = 'pipewire' if desktop else no_audio
@@ -60,10 +66,12 @@ def ask_for_audio_selection(desktop: bool = True, preset: Union[str, None] = Non
match choice.type_:
case MenuSelectionType.Skip: return preset
- case MenuSelectionType.Selection: return choice.value
+ case MenuSelectionType.Selection: return choice.single_value
+ return None
-def select_language(preset_value: str = None) -> str:
+
+def select_language(preset: Optional[str] = None) -> Optional[str]:
"""
Asks the user to select a language
Usually this is combined with :ref:`archinstall.list_keyboard_languages`.
@@ -75,17 +83,18 @@ def select_language(preset_value: str = None) -> str:
# sort alphabetically and then by length
sorted_kb_lang = sorted(sorted(list(kb_lang)), key=len)
- selected_lang = Menu(
+ choice = Menu(
_('Select keyboard layout'),
sorted_kb_lang,
- preset_values=preset_value,
+ preset_values=preset,
sort=False
).run()
- if selected_lang.value is None:
- return preset_value
+ match choice.type_:
+ case MenuSelectionType.Skip: return preset
+ case MenuSelectionType.Selection: return choice.single_value
- return selected_lang.value
+ return None
def select_mirror_regions(preset_values: Dict[str, Any] = {}) -> Dict[str, Any]:
@@ -100,8 +109,10 @@ def select_mirror_regions(preset_values: Dict[str, Any] = {}) -> Dict[str, Any]:
preselected = None
else:
preselected = list(preset_values.keys())
+
mirrors = list_mirrors()
- selected_mirror = Menu(
+
+ choice = Menu(
_('Select one of the regions to download packages from'),
list(mirrors.keys()),
preset_values=preselected,
@@ -109,13 +120,18 @@ def select_mirror_regions(preset_values: Dict[str, Any] = {}) -> Dict[str, Any]:
allow_reset=True
).run()
- match selected_mirror.type_:
- case MenuSelectionType.Reset: return {}
- case MenuSelectionType.Skip: return preset_values
- case _: return {selected: mirrors[selected] for selected in selected_mirror.value}
+ match choice.type_:
+ case MenuSelectionType.Reset:
+ return {}
+ case MenuSelectionType.Skip:
+ return preset_values
+ case MenuSelectionType.Selection:
+ return {selected: mirrors[selected] for selected in choice.multi_value}
+
+ return {}
-def select_archinstall_language(languages: List[Language], preset_value: Language) -> Language:
+def select_archinstall_language(languages: List[Language], preset: Language) -> Language:
# these are the displayed language names which can either be
# the english name of a language or, if present, the
# name of the language in its own language
@@ -128,15 +144,15 @@ def select_archinstall_language(languages: List[Language], preset_value: Languag
choice = Menu(
title,
list(options.keys()),
- default_option=preset_value.display_name,
+ default_option=preset.display_name,
preview_size=0.5
).run()
match choice.type_:
- case MenuSelectionType.Skip:
- return preset_value
- case MenuSelectionType.Selection:
- return options[choice.value]
+ case MenuSelectionType.Skip: return preset
+ case MenuSelectionType.Selection: return options[choice.single_value]
+
+ raise ValueError('Language selection not handled')
def ask_additional_packages_to_install(pre_set_packages: List[str] = []) -> List[str]:
@@ -223,4 +239,6 @@ def select_additional_repositories(preset: List[str]) -> List[str]:
match choice.type_:
case MenuSelectionType.Skip: return preset
case MenuSelectionType.Reset: return []
- case MenuSelectionType.Selection: return choice.value
+ case MenuSelectionType.Selection: return choice.single_value
+
+ return []