Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/global_menu.py
diff options
context:
space:
mode:
Diffstat (limited to 'archinstall/lib/global_menu.py')
-rw-r--r--archinstall/lib/global_menu.py95
1 files changed, 67 insertions, 28 deletions
diff --git a/archinstall/lib/global_menu.py b/archinstall/lib/global_menu.py
index fc58a653..91ebc6a0 100644
--- a/archinstall/lib/global_menu.py
+++ b/archinstall/lib/global_menu.py
@@ -4,6 +4,7 @@ from typing import Any, List, Optional, Union, Dict, TYPE_CHECKING
from . import disk
from .general import secret
+from .locale.locale_menu import LocaleConfiguration, LocaleMenu
from .menu import Selector, AbstractMenu
from .mirrors import MirrorConfiguration, MirrorMenu
from .models import NetworkConfiguration
@@ -24,9 +25,7 @@ from .interactions import ask_to_configure_network
from .interactions import get_password, ask_for_a_timezone
from .interactions import select_additional_repositories
from .interactions import select_kernel
-from .interactions import select_language
-from .interactions import select_locale_enc
-from .interactions import select_locale_lang
+from .utils.util import format_cols
from .interactions import ask_ntp
from .interactions.disk_conf import select_disk_config
@@ -36,6 +35,7 @@ if TYPE_CHECKING:
class GlobalMenu(AbstractMenu):
def __init__(self, data_store: Dict[str, Any]):
+ self._defined_text = str(_('Defined'))
super().__init__(data_store=data_store, auto_cursor=True, preview_size=0.3)
def setup_selection_menu_options(self):
@@ -46,28 +46,19 @@ class GlobalMenu(AbstractMenu):
lambda x: self._select_archinstall_language(x),
display_func=lambda x: x.display_name,
default=self.translation_handler.get_language_by_abbr('en'))
- self._menu_options['keyboard-layout'] = \
+ self._menu_options['locale_config'] = \
Selector(
- _('Keyboard layout'),
- lambda preset: select_language(preset),
- default='us')
+ _('Locales'),
+ lambda preset: self._locale_selection(preset),
+ preview_func=self._prev_locale,
+ display_func=lambda x: self._defined_text if x else '')
self._menu_options['mirror_config'] = \
Selector(
_('Mirrors'),
lambda preset: self._mirror_configuration(preset),
- display_func=lambda x: str(_('Defined')) if x else '',
+ display_func=lambda x: self._defined_text if x else '',
preview_func=self._prev_mirror_config
)
- self._menu_options['sys-language'] = \
- Selector(
- _('Locale language'),
- lambda preset: select_locale_lang(preset),
- default='en_US')
- self._menu_options['sys-encoding'] = \
- Selector(
- _('Locale encoding'),
- lambda preset: select_locale_enc(preset),
- default='UTF-8')
self._menu_options['disk_config'] = \
Selector(
_('Disk configuration'),
@@ -103,32 +94,32 @@ class GlobalMenu(AbstractMenu):
Selector(
_('Root password'),
lambda preset:self._set_root_password(),
- display_func=lambda x: secret(x) if x else 'None')
+ display_func=lambda x: secret(x) if x else '')
self._menu_options['!users'] = \
Selector(
_('User account'),
lambda x: self._create_user_account(x),
default=[],
- display_func=lambda x: f'{len(x)} {_("User(s)")}' if len(x) > 0 else None,
+ display_func=lambda x: f'{len(x)} {_("User(s)")}' if len(x) > 0 else '',
preview_func=self._prev_users)
self._menu_options['profile_config'] = \
Selector(
_('Profile'),
lambda preset: self._select_profile(preset),
- display_func=lambda x: x.profile.name if x else 'None',
+ display_func=lambda x: x.profile.name if x else '',
preview_func=self._prev_profile
)
self._menu_options['audio'] = \
Selector(
_('Audio'),
lambda preset: self._select_audio(preset),
- display_func=lambda x: x if x else 'None',
+ display_func=lambda x: x if x else '',
default=None
)
self._menu_options['parallel downloads'] = \
Selector(
_('Parallel Downloads'),
- add_number_of_parrallel_downloads,
+ lambda preset: add_number_of_parrallel_downloads(preset),
display_func=lambda x: x if x else '0',
default=0
)
@@ -141,19 +132,20 @@ class GlobalMenu(AbstractMenu):
self._menu_options['packages'] = \
Selector(
_('Additional packages'),
- # lambda x: ask_additional_packages_to_install(storage['arguments'].get('packages', None)),
- ask_additional_packages_to_install,
+ lambda preset: ask_additional_packages_to_install(preset),
+ display_func=lambda x: self._defined_text if x else '',
+ preview_func=self._prev_additional_pkgs,
default=[])
self._menu_options['additional-repositories'] = \
Selector(
_('Optional repositories'),
- select_additional_repositories,
+ lambda preset: select_additional_repositories(preset),
display_func=lambda x: ', '.join(x) if x else None,
default=[])
self._menu_options['nic'] = \
Selector(
_('Network configuration'),
- ask_to_configure_network,
+ lambda preset: ask_to_configure_network(preset),
display_func=lambda x: self._display_network_conf(x),
preview_func=self._prev_network_config,
default={})
@@ -177,12 +169,37 @@ class GlobalMenu(AbstractMenu):
self._menu_options['install'] = \
Selector(
self._install_text(),
- exec_func=lambda n,v: True if len(self._missing_configs()) == 0 else False,
+ exec_func=lambda n, v: True if len(self._missing_configs()) == 0 else False,
preview_func=self._prev_install_missing_config,
no_store=True)
self._menu_options['abort'] = Selector(_('Abort'), exec_func=lambda n,v:exit(1))
+ def _missing_configs(self) -> List[str]:
+ def check(s):
+ return self._menu_options.get(s).has_selection()
+
+ def has_superuser() -> bool:
+ sel = self._menu_options['!users']
+ if sel.current_selection:
+ return any([u.sudo for u in sel.current_selection])
+ return False
+
+ mandatory_fields = dict(filter(lambda x: x[1].is_mandatory(), self._menu_options.items()))
+ missing = set()
+
+ for key, selector in mandatory_fields.items():
+ if key in ['!root-password', '!users']:
+ if not check('!root-password') and not has_superuser():
+ missing.add(
+ str(_('Either root-password or at least 1 user with sudo privileges must be specified'))
+ )
+ elif key == 'disk_config':
+ if not check('disk_config'):
+ missing.add(self._menu_options['disk_config'].description)
+
+ return list(missing)
+
def _update_install_text(self, name: str, value: str):
text = self._install_text()
self._menu_options['install'].update_description(text)
@@ -216,6 +233,21 @@ class GlobalMenu(AbstractMenu):
disk_encryption = disk.DiskEncryptionMenu(mods, data_store, preset=preset).run()
return disk_encryption
+ def _locale_selection(self, preset: LocaleConfiguration) -> LocaleConfiguration:
+ data_store: Dict[str, Any] = {}
+ locale_config = LocaleMenu(data_store, preset).run()
+ return locale_config
+
+ def _prev_locale(self) -> Optional[str]:
+ selector = self._menu_options['locale_config']
+ if selector.has_selection():
+ config: LocaleConfiguration = selector.current_selection # type: ignore
+ output = '{}: {}\n'.format(str(_('Keyboard layout')), config.kb_layout)
+ output += '{}: {}\n'.format(str(_('Locale language')), config.sys_lang)
+ output += '{}: {}'.format(str(_('Locale encoding')), config.sys_enc)
+ return output
+ return None
+
def _prev_network_config(self) -> Optional[str]:
selector = self._menu_options['nic']
if selector.has_selection():
@@ -224,6 +256,13 @@ class GlobalMenu(AbstractMenu):
return FormattedOutput.as_table(ifaces)
return None
+ def _prev_additional_pkgs(self):
+ selector = self._menu_options['packages']
+ if selector.has_selection():
+ packages: List[str] = selector.current_selection
+ return format_cols(packages, None)
+ return None
+
def _prev_disk_layouts(self) -> Optional[str]:
selector = self._menu_options['disk_config']
disk_layout_conf: Optional[disk.DiskLayoutConfiguration] = selector.current_selection