From 6489a417aa8d43bd58ec0fd1268d0dd734b0073f Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 15 Feb 2022 18:44:58 +1100 Subject: Fix #966 - DeferredTranslation errors (#976) * Fix #966 * Add types to parameters * Update network configuration * Backwards compability for nic config * Update Co-authored-by: Daniel Girtler --- archinstall/__init__.py | 8 +++++++- archinstall/lib/menu/menu.py | 19 ++++++++++++++++++- archinstall/lib/translation.py | 8 ++++++++ archinstall/lib/user_interaction.py | 31 ++++++++++++++----------------- examples/guided.py | 2 +- examples/swiss.py | 2 +- 6 files changed, 49 insertions(+), 21 deletions(-) diff --git a/archinstall/__init__.py b/archinstall/__init__.py index c24a7806..9afefa0e 100644 --- a/archinstall/__init__.py +++ b/archinstall/__init__.py @@ -203,7 +203,13 @@ def load_config(): storage['gfx_driver_packages'] = AVAILABLE_GFX_DRIVERS.get(arguments.get('gfx_driver', None), None) if arguments.get('servers', None) is not None: storage['_selected_servers'] = arguments.get('servers', None) - + if nic_config := arguments.get('nic', {}): + if nic_config.get('nic', '') == 'Copy ISO network configuration to installation': + arguments['nic'] = {'type': 'iso_config'} + elif 'NetworkManager' in nic_config: + arguments['nic'] = {'type': 'network_manager', 'NetworkManager': True} + else: + arguments['nic'] = {k if k != 'nic' else 'type': v for k, v in nic_config.items()} def post_process_arguments(arguments): storage['arguments'] = arguments diff --git a/archinstall/lib/menu/menu.py b/archinstall/lib/menu/menu.py index ac075b66..ee4b87e3 100644 --- a/archinstall/lib/menu/menu.py +++ b/archinstall/lib/menu/menu.py @@ -1,3 +1,5 @@ +from typing import Dict, List, Union, Any + from archinstall.lib.menu.simple_menu import TerminalMenu from ..exceptions import RequirementError from ..output import log @@ -7,7 +9,17 @@ import sys import logging class Menu(TerminalMenu): - def __init__(self, title, p_options, skip=True, multi=False, default_option=None, sort=True, preset_values=None, cursor_index=None): + def __init__( + self, + title :str, + p_options :Union[List[str], Dict[str, Any]], + skip :bool = True, + multi :bool = False, + default_option :str = None, + sort :bool = True, + preset_values :Union[str, List[str]] = None, + cursor_index :int = None + ): """ Creates a new menu @@ -60,6 +72,11 @@ class Menu(TerminalMenu): log(f"invalid parameter at Menu() call was at <{sys._getframe(1).f_code.co_name}>",level=logging.WARNING) raise RequirementError('Menu.__init__() requires at least one option to proceed.') + if any([o for o in options if not isinstance(o, str)]): + log(" * Menu options must be of type string * ", fg='red') + log(f"invalid parameter at Menu() call was at <{sys._getframe(1).f_code.co_name}>",level=logging.WARNING) + raise RequirementError('Menu.__init__() requires the options to be of type string') + if sort: options = sorted(options) diff --git a/archinstall/lib/translation.py b/archinstall/lib/translation.py index b8a27fed..767d6d36 100644 --- a/archinstall/lib/translation.py +++ b/archinstall/lib/translation.py @@ -8,6 +8,7 @@ from pathlib import Path from typing import List, Dict from .exceptions import TranslationError + class Languages: def __init__(self): self._mappings = self._get_language_mappings() @@ -46,6 +47,13 @@ class DeferredTranslation: def __gt__(self, other) -> bool: return self.message > other + def __add__(self, other) -> DeferredTranslation: + if isinstance(other, str): + other = DeferredTranslation(other) + + concat = self.message + other.message + return DeferredTranslation(concat) + def format(self, *args) -> str: return self.message.format(*args) diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index f8822bac..94a05e89 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -30,7 +30,7 @@ from .mirrors import list_mirrors # TODO: Some inconsistencies between the selection processes. # Some return the keys from the options, some the values? -from .translation import Translation +from .translation import Translation, DeferredTranslation from .disk.validators import fs_types from .packages.packages import validate_package_list @@ -428,22 +428,22 @@ def ask_to_configure_network() -> Dict[str, Any]: # Optionally configure one network interface. # while 1: # {MAC: Ifname} - - iso_config = _('Copy ISO network configuration to installation') - network_manager = _('Use NetworkManager (necessary to configure internet graphically in GNOME and KDE)') - interfaces = { - 'ISO-CONFIG': iso_config, - 'NetworkManager': network_manager, + 'iso_config': str(_('Copy ISO network configuration to installation')), + 'network_manager': str(_('Use NetworkManager (necessary to configure internet graphically in GNOME and KDE)')), **list_interfaces() } nic = Menu(_('Select one network interface to configure'), list(interfaces.values())).run() - if nic and nic != iso_config: - if nic == network_manager: - return {'nic': nic, 'NetworkManager': True} + if not nic: + return {} + if nic == interfaces['iso_config']: + return {'type': 'iso_config'} + elif nic == interfaces['network_manager']: + return {'type': 'network_manager', 'NetworkManager': True} + else: # Current workaround: # For selecting modes without entering text within brackets, # printing out this part separate from options, passed in @@ -491,13 +491,10 @@ def ask_to_configure_network() -> Dict[str, Any]: if len(dns_input): dns = dns_input.split(' ') - return {'nic': nic, 'dhcp': False, 'ip': ip, 'gateway': gateway, 'dns': dns} + return {'type': nic, 'dhcp': False, 'ip': ip, 'gateway': gateway, 'dns': dns} else: - return {'nic': nic} - elif nic: - return nic - - return {} + # this will contain network iface names + return {'type': nic} def partition_overlap(partitions :list, start :str, end :str) -> bool: @@ -925,7 +922,7 @@ def select_driver(options :Dict[str, Any] = AVAILABLE_GFX_DRIVERS, force_ask :bo if drivers: arguments = storage.get('arguments', {}) - title = '' + title = DeferredTranslation('') if has_amd_graphics(): title += _('For the best compatibility with your AMD hardware, you may want to use either the all open-source or AMD / ATI options.') + '\n' diff --git a/examples/guided.py b/examples/guided.py index 24db7eb4..23fd45a6 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -163,7 +163,7 @@ def perform_installation(mountpoint): # If user selected to copy the current ISO network configuration # Perform a copy of the config - if archinstall.arguments.get('nic', {}) == 'Copy ISO network configuration to installation': + if archinstall.arguments.get('nic', {}).get('type', '') == 'iso_config': installation.copy_iso_network_config(enable_services=True) # Sources the ISO network configuration to the install medium. elif archinstall.arguments.get('nic', {}).get('NetworkManager', False): installation.add_additional_packages("networkmanager") diff --git a/examples/swiss.py b/examples/swiss.py index fa2d1fb6..9f3cf9dd 100644 --- a/examples/swiss.py +++ b/examples/swiss.py @@ -395,7 +395,7 @@ def os_setup(installation): # If user selected to copy the current ISO network configuration # Perform a copy of the config - if archinstall.arguments.get('nic', {}) == 'Copy ISO network configuration to installation': + if archinstall.arguments.get('nic', {}).get('type', '') == 'iso_config': installation.copy_iso_network_config( enable_services=True) # Sources the ISO network configuration to the install medium. elif archinstall.arguments.get('nic', {}).get('NetworkManager', False): -- cgit v1.2.3-70-g09d2