index : archinstall32 | |
Archlinux32 installer | gitolite user |
summaryrefslogtreecommitdiff |
author | Werner Llácer <wllacer@gmail.com> | 2022-02-28 15:02:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-28 15:02:39 +0100 |
commit | f06aabb4d4a50d3a8ab7c07bef8390f72b091293 (patch) | |
tree | 7b079611baeb58bdf0feb9b78a009ef0ee20623e /archinstall/lib/menu | |
parent | 391699497d0c15e7eb6a63a1369209f42f311b2c (diff) |
-rw-r--r-- | archinstall/lib/menu/menu.py | 29 | ||||
-rw-r--r-- | archinstall/lib/menu/selection_menu.py | 66 |
diff --git a/archinstall/lib/menu/menu.py b/archinstall/lib/menu/menu.py index ee4b87e3..962dcc4d 100644 --- a/archinstall/lib/menu/menu.py +++ b/archinstall/lib/menu/menu.py @@ -84,8 +84,6 @@ class Menu(TerminalMenu): self.skip = skip self.default_option = default_option self.multi = multi - self.preselection(preset_values,cursor_index) - menu_title = f'\n{title}\n\n' if skip: @@ -97,6 +95,7 @@ class Menu(TerminalMenu): default = f'{default_option} (default)' self.menu_options = [default] + [o for o in self.menu_options if default_option != o] + self.preselection(preset_values,cursor_index) cursor = "> " main_menu_cursor_style = ("fg_cyan", "bold") main_menu_style = ("bg_blue", "fg_gray") @@ -154,22 +153,28 @@ class Menu(TerminalMenu): def preselection(self,preset_values :list = [],cursor_index :int = None): def from_preset_to_cursor(): if preset_values: - if isinstance(preset_values,str): - self.cursor_index = self.menu_options.index(preset_values) - else: # should return an error, but this is smoother - self.cursor_index = self.menu_options.index(preset_values[0]) + # if the value is not extant return 0 as cursor index + try: + if isinstance(preset_values,str): + self.cursor_index = self.menu_options.index(self.preset_values) + else: # should return an error, but this is smoother + self.cursor_index = self.menu_options.index(self.preset_values[0]) + except ValueError: + self.cursor_index = 0 - self.preset_values = preset_values self.cursor_index = cursor_index - if preset_values and cursor_index is None: - from_preset_to_cursor() - if preset_values and not self.multi: # Not supported by the infraestructure + if not preset_values: self.preset_values = None - from_preset_to_cursor() + return - if self.default_option and self.multi: + self.preset_values = preset_values + if self.default_option: if isinstance(preset_values,str) and self.default_option == preset_values: self.preset_values = f"{preset_values} (default)" elif isinstance(preset_values,(list,tuple)) and self.default_option in preset_values: idx = preset_values.index(self.default_option) self.preset_values[idx] = f"{preset_values[idx]} (default)" + if cursor_index is None or not self.multi: + from_preset_to_cursor() + if not self.multi: # Not supported by the infraestructure + self.preset_values = None diff --git a/archinstall/lib/menu/selection_menu.py b/archinstall/lib/menu/selection_menu.py index 97dfd2a7..a82e8a70 100644 --- a/archinstall/lib/menu/selection_menu.py +++ b/archinstall/lib/menu/selection_menu.py @@ -252,6 +252,7 @@ class GeneralMenu: # we synch all the options just in case for item in self.list_options(): self.synch(item) + self.post_callback # as all the values can vary i have to exec this callback cursor_pos = None while True: # Before continuing, set the preferred keyboard layout/language in the current terminal. @@ -278,7 +279,7 @@ class GeneralMenu: Returns true if the menu shall continue, False if it has ended """ # find the selected option in our option list - option = [[k, v] for k, v in self._menu_options.items() if v.text.strip() == selection] + option = [[k, v] for k, v in self._menu_options.items() if v.text.strip() == selection.strip()] if len(option) != 1: raise ValueError(f'Selection not found: {selection}') selector_name = option[0][0] @@ -303,8 +304,8 @@ class GeneralMenu: result = None if selector.func: - # TODO insert code to allow selector functions with preset value - result = selector.func() + presel_val = self.option(selector_name).get_selection() + result = selector.func(presel_val) self._menu_options[selector_name].set_current_selection(result) self._data_store[selector_name] = result exec_ret_val = selector.exec_func(selector_name,result) if selector.exec_func else False @@ -412,32 +413,33 @@ class GlobalMenu(GeneralMenu): super().__init__(data_store=data_store, auto_cursor=True) def _setup_selection_menu_options(self): + # archinstall.Language will not use preset values self._menu_options['archinstall-language'] = \ Selector( _('Select Archinstall language'), - lambda: self._select_archinstall_language('English'), + lambda x: self._select_archinstall_language('English'), default='English', enabled=True) self._menu_options['keyboard-layout'] = \ - Selector(_('Select keyboard layout'), lambda: select_language('us'), default='us') + Selector(_('Select keyboard layout'), lambda preset: select_language('us',preset), default='us') self._menu_options['mirror-region'] = \ Selector( _('Select mirror region'), - lambda: select_mirror_regions(), + select_mirror_regions, display_func=lambda x: list(x.keys()) if x else '[]', default={}) self._menu_options['sys-language'] = \ - Selector(_('Select locale language'), lambda: select_locale_lang('en_US'), default='en_US') + Selector(_('Select locale language'), lambda preset: select_locale_lang('en_US',preset), default='en_US') self._menu_options['sys-encoding'] = \ - Selector(_('Select locale encoding'), lambda: select_locale_enc('utf-8'), default='utf-8') + Selector(_('Select locale encoding'), lambda preset: select_locale_enc('utf-8',preset), default='utf-8') self._menu_options['harddrives'] = \ Selector( _('Select harddrives'), - lambda: self._select_harddrives()) + self._select_harddrives) self._menu_options['disk_layouts'] = \ Selector( _('Select disk layout'), - lambda: select_disk_layout( + lambda x: select_disk_layout( storage['arguments'].get('harddrives', []), storage['arguments'].get('advanced', False) ), @@ -445,80 +447,82 @@ class GlobalMenu(GeneralMenu): self._menu_options['!encryption-password'] = \ Selector( _('Set encryption password'), - lambda: self._select_encrypted_password(), + lambda x: self._select_encrypted_password(), display_func=lambda x: secret(x) if x else 'None', dependencies=['harddrives']) self._menu_options['swap'] = \ Selector( _('Use swap'), - lambda: ask_for_swap(), + lambda preset: ask_for_swap(preset), default=True) self._menu_options['bootloader'] = \ Selector( _('Select bootloader'), - lambda: ask_for_bootloader(storage['arguments'].get('advanced', False)), + lambda preset: ask_for_bootloader(storage['arguments'].get('advanced', False),preset), default="systemd-bootctl" if has_uefi() else "grub-install") self._menu_options['hostname'] = \ Selector( _('Specify hostname'), - lambda: ask_hostname(), + ask_hostname, default='archlinux') + # root password won't have preset value self._menu_options['!root-password'] = \ Selector( _('Set root password'), - lambda: self._set_root_password(), + lambda preset:self._set_root_password(), display_func=lambda x: secret(x) if x else 'None') self._menu_options['!superusers'] = \ Selector( _('Specify superuser account'), - lambda: self._create_superuser_account(), + lambda x: self._create_superuser_account(), dependencies_not=['!root-password'], display_func=lambda x: list(x.keys()) if x else '') self._menu_options['!users'] = \ Selector( _('Specify user account'), - lambda: self._create_user_account(), + lambda x: self._create_user_account(), default={}, display_func=lambda x: list(x.keys()) if x else '[]') self._menu_options['profile'] = \ Selector( _('Specify profile'), - lambda: self._select_profile(), + lambda x: self._select_profile(), display_func=lambda x: x if x else 'None') self._menu_options['audio'] = \ Selector( _('Select audio'), - lambda: ask_for_audio_selection(is_desktop_profile(storage['arguments'].get('profile', None)))) + lambda preset: ask_for_audio_selection(is_desktop_profile(storage['arguments'].get('profile', None)),preset)) self._menu_options['kernels'] = \ Selector( _('Select kernels'), - lambda: select_kernel(), + lambda preset: select_kernel(preset), default=['linux']) self._menu_options['packages'] = \ Selector( _('Additional packages to install'), - lambda: ask_additional_packages_to_install(storage['arguments'].get('packages', None)), + # lambda x: ask_additional_packages_to_install(storage['arguments'].get('packages', None)), + ask_additional_packages_to_install, default=[]) self._menu_options['additional-repositories'] = \ Selector( _('Additional repositories to enable'), - lambda: select_additional_repositories(), + select_additional_repositories, default=[]) self._menu_options['nic'] = \ Selector( _('Configure network'), - lambda: ask_to_configure_network(), + ask_to_configure_network, display_func=lambda x: x if x else _('Not configured, unavailable unless setup manually'), default={}) self._menu_options['timezone'] = \ Selector( _('Select timezone'), - lambda: ask_for_a_timezone(), + lambda preset: ask_for_a_timezone(preset), default='UTC') self._menu_options['ntp'] = \ Selector( _('Set automatic time sync (NTP)'), - lambda: self._select_ntp(), + lambda preset: self._select_ntp(preset), default=True) self._menu_options['install'] = \ Selector( @@ -591,20 +595,20 @@ class GlobalMenu(GeneralMenu): else: return None - def _select_ntp(self) -> bool: - ntp = ask_ntp() + def _select_ntp(self, preset :bool = True) -> bool: + ntp = ask_ntp(preset) value = str(ntp).lower() SysCommand(f'timedatectl set-ntp {value}') return ntp - def _select_harddrives(self): - old_haddrives = storage['arguments'].get('harddrives', []) - harddrives = select_harddrives() + def _select_harddrives(self, old_harddrives : list) -> list: + # old_haddrives = storage['arguments'].get('harddrives', []) + harddrives = select_harddrives(old_harddrives) # in case the harddrives got changed we have to reset the disk layout as well - if old_haddrives != harddrives: + if old_harddrives != harddrives: self._menu_options.get('disk_layouts').set_current_selection(None) storage['arguments']['disk_layouts'] = {} |