* Fix 1117

* Update

* flake8

Co-authored-by: Daniel Girtler <girtler.daniel@gmail.com>
This commit is contained in:
Daniel Girtler 2022-05-05 20:48:01 +10:00 committed by GitHub
parent 2d37157178
commit bcd810d2d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 79 additions and 59 deletions

View File

@ -5,6 +5,7 @@ from typing import Optional, Dict, Any, List, TYPE_CHECKING
# https://stackoverflow.com/a/39757388/929999 # https://stackoverflow.com/a/39757388/929999
if TYPE_CHECKING: if TYPE_CHECKING:
from .blockdevice import BlockDevice from .blockdevice import BlockDevice
_: Any
from .helpers import sort_block_devices_based_on_performance, select_largest_device, select_disk_larger_than_or_close_to from .helpers import sort_block_devices_based_on_performance, select_largest_device, select_disk_larger_than_or_close_to
from ..hardware import has_uefi from ..hardware import has_uefi
@ -26,13 +27,13 @@ def suggest_single_disk_layout(block_device :BlockDevice,
compression = False compression = False
if default_filesystem == 'btrfs': if default_filesystem == 'btrfs':
prompt = 'Would you like to use BTRFS subvolumes with a default structure?' prompt = str(_('Would you like to use BTRFS subvolumes with a default structure?'))
choice = Menu(prompt, ['yes', 'no'], skip=False, default_option='yes').run() choice = Menu(prompt, Menu.yes_no(), skip=False, default_option=Menu.yes()).run()
using_subvolumes = choice == 'yes' using_subvolumes = choice == Menu.yes()
prompt = 'Would you like to use BTRFS compression?' prompt = str(_('Would you like to use BTRFS compression?'))
choice = Menu(prompt, ['yes', 'no'], skip=False, default_option='yes').run() choice = Menu(prompt, Menu.yes_no(), skip=False, default_option=Menu.yes()).run()
compression = choice == 'yes' compression = choice == Menu.yes()
layout = { layout = {
block_device.path : { block_device.path : {
@ -87,9 +88,9 @@ def suggest_single_disk_layout(block_device :BlockDevice,
layout[block_device.path]['partitions'][-1]['start'] = '513MiB' layout[block_device.path]['partitions'][-1]['start'] = '513MiB'
if not using_subvolumes and block_device.size >= MIN_SIZE_TO_ALLOW_HOME_PART: if not using_subvolumes and block_device.size >= MIN_SIZE_TO_ALLOW_HOME_PART:
prompt = 'Would you like to create a separate partition for /home?' prompt = str(_('Would you like to create a separate partition for /home?'))
choice = Menu(prompt, ['yes', 'no'], skip=False, default_option='yes').run() choice = Menu(prompt, Menu.yes_no(), skip=False, default_option=Menu.yes()).run()
using_home_partition = choice == 'yes' using_home_partition = choice == Menu.yes()
# Set a size for / (/root) # Set a size for / (/root)
if using_subvolumes or block_device.size < MIN_SIZE_TO_ALLOW_HOME_PART or not using_home_partition: if using_subvolumes or block_device.size < MIN_SIZE_TO_ALLOW_HOME_PART or not using_home_partition:
@ -138,9 +139,7 @@ def suggest_single_disk_layout(block_device :BlockDevice,
return layout return layout
def suggest_multi_disk_layout(block_devices :List[BlockDevice], def suggest_multi_disk_layout(block_devices :List[BlockDevice], default_filesystem :Optional[str] = None, advanced_options :bool = False):
default_filesystem :Optional[str] = None,
advanced_options :bool = False) -> Dict[str, Any]:
if not default_filesystem: if not default_filesystem:
from ..user_interaction import ask_for_main_filesystem_format from ..user_interaction import ask_for_main_filesystem_format
@ -158,6 +157,13 @@ def suggest_multi_disk_layout(block_devices :List[BlockDevice],
home_device = select_largest_device(block_devices, gigabytes=MIN_SIZE_TO_ALLOW_HOME_PART) home_device = select_largest_device(block_devices, gigabytes=MIN_SIZE_TO_ALLOW_HOME_PART)
root_device = select_disk_larger_than_or_close_to(block_devices, gigabytes=ARCH_LINUX_INSTALLED_SIZE, filter_out=[home_device]) root_device = select_disk_larger_than_or_close_to(block_devices, gigabytes=ARCH_LINUX_INSTALLED_SIZE, filter_out=[home_device])
if home_device is None or root_device is None:
text = _('The selected drives do not have the minimum capacity required for an automatic suggestion\n')
text += _('Minimum capacity for /home partition: {}GB\n').format(MIN_SIZE_TO_ALLOW_HOME_PART)
text += _('Minimum capacity for Arch Linux partition: {}GB').format(ARCH_LINUX_INSTALLED_SIZE)
Menu(str(text), [str(_('Continue'))], skip=False).run()
return None
compression = False compression = False
if default_filesystem == 'btrfs': if default_filesystem == 'btrfs':
@ -165,9 +171,9 @@ def suggest_multi_disk_layout(block_devices :List[BlockDevice],
# choice = Menu(prompt, ['yes', 'no'], skip=False, default_option='yes').run() # choice = Menu(prompt, ['yes', 'no'], skip=False, default_option='yes').run()
# using_subvolumes = choice == 'yes' # using_subvolumes = choice == 'yes'
prompt = 'Would you like to use BTRFS compression?' prompt = str(_('Would you like to use BTRFS compression?'))
choice = Menu(prompt, ['yes', 'no'], skip=False, default_option='yes').run() choice = Menu(prompt, Menu.yes_no(), skip=False, default_option=Menu.yes()).run()
compression = choice == 'yes' compression = choice == Menu.yes()
log(f"Suggesting multi-disk-layout using {len(block_devices)} disks, where {root_device} will be /root and {home_device} will be /home", level=logging.DEBUG) log(f"Suggesting multi-disk-layout using {len(block_devices)} disks, where {root_device} will be /root and {home_device} will be /home", level=logging.DEBUG)

View File

@ -262,9 +262,9 @@ class GlobalMenu(GeneralMenu):
"Do you wish to continue?" "Do you wish to continue?"
).format(storage['MOUNT_POINT']) ).format(storage['MOUNT_POINT'])
choice = Menu(prompt, ['yes', 'no'], default_option='yes').run() choice = Menu(prompt, Menu.yes_no(), default_option=Menu.yes()).run()
if choice == 'no': if choice == Menu.no():
exit(1) exit(1)
return harddrives return harddrives

View File

@ -12,7 +12,21 @@ import logging
if TYPE_CHECKING: if TYPE_CHECKING:
_: Any _: Any
class Menu(TerminalMenu): class Menu(TerminalMenu):
@classmethod
def yes(cls):
return str(_('yes'))
@classmethod
def no(cls):
return str(_('no'))
@classmethod
def yes_no(cls):
return [cls.yes(), cls.no()]
def __init__( def __init__(
self, self,
title :str, title :str,

View File

@ -1,6 +1,6 @@
from __future__ import annotations from __future__ import annotations
from typing import Any, Dict, TYPE_CHECKING from typing import Any, Dict, TYPE_CHECKING, Optional
from .partitioning_conf import manage_new_and_existing_partitions, get_default_partition_layout from .partitioning_conf import manage_new_and_existing_partitions, get_default_partition_layout
from ..disk import BlockDevice from ..disk import BlockDevice
@ -36,7 +36,7 @@ def select_individual_blockdevice_usage(block_devices: list) -> Dict[str, Any]:
return result return result
def select_disk_layout(block_devices: list, advanced_options=False) -> Dict[str, Any]: def select_disk_layout(block_devices: list, advanced_options=False) -> Optional[Dict[str, Any]]:
wipe_mode = str(_('Wipe all selected drives and use a best-effort default partition layout')) wipe_mode = str(_('Wipe all selected drives and use a best-effort default partition layout'))
custome_mode = str(_('Select what to do with each individual drive (followed by partition usage)')) custome_mode = str(_('Select what to do with each individual drive (followed by partition usage)'))
modes = [wipe_mode, custome_mode] modes = [wipe_mode, custome_mode]

View File

@ -22,11 +22,11 @@ def ask_ntp(preset: bool = True) -> bool:
prompt = str(_('Would you like to use automatic time synchronization (NTP) with the default time servers?\n')) prompt = str(_('Would you like to use automatic time synchronization (NTP) with the default time servers?\n'))
prompt += str(_('Hardware time and other post-configuration steps might be required in order for NTP to work.\nFor more information, please check the Arch wiki')) prompt += str(_('Hardware time and other post-configuration steps might be required in order for NTP to work.\nFor more information, please check the Arch wiki'))
if preset: if preset:
preset_val = 'yes' preset_val = Menu.yes()
else: else:
preset_val = 'no' preset_val = Menu.no()
choice = Menu(prompt, ['yes', 'no'], skip=False, preset_values=preset_val, default_option='yes').run() choice = Menu(prompt, Menu.yes_no(), skip=False, preset_values=preset_val, default_option=Menu.yes()).run()
return False if choice == 'no' else True return False if choice == Menu.no() else True
def ask_hostname(preset: str = None) -> str: def ask_hostname(preset: str = None) -> str:

View File

@ -109,11 +109,11 @@ class UserList(ListManager):
sudoer = False sudoer = False
else: else:
sudoer = False sudoer = False
sudo_choice = Menu(str(_('Should {} be a superuser (sudoer)?')).format(userid), ['yes', 'no'], sudo_choice = Menu(str(_('Should {} be a superuser (sudoer)?')).format(userid), Menu.yes_no(),
skip=False, skip=False,
preset_values='yes' if sudoer else 'no', preset_values=Menu.yes() if sudoer else Menu.no(),
default_option='no').run() default_option=Menu.no()).run()
sudoer = True if sudo_choice == 'yes' else False sudoer = True if sudo_choice == Menu.yes() else False
password = get_password(prompt=str(_('Password for user "{}": ').format(userid))) password = get_password(prompt=str(_('Password for user "{}": ').format(userid)))

View File

@ -1,6 +1,6 @@
from __future__ import annotations from __future__ import annotations
from typing import List, Any, Dict, Union, TYPE_CHECKING, Callable from typing import List, Any, Dict, Union, TYPE_CHECKING, Callable, Optional
from ..menu import Menu from ..menu import Menu
from ..output import log from ..output import log
@ -97,8 +97,10 @@ def select_partition(title :str, partitions :List[Partition], multiple :bool = F
return None return None
def get_default_partition_layout(block_devices: Union['BlockDevice', List['BlockDevice']], def get_default_partition_layout(
advanced_options: bool = False) -> Dict[str, Any]: block_devices: Union['BlockDevice', List['BlockDevice']],
advanced_options: bool = False
) -> Optional[Dict[str, Any]]:
from ..disk import suggest_single_disk_layout, suggest_multi_disk_layout from ..disk import suggest_single_disk_layout, suggest_multi_disk_layout
if len(block_devices) == 1: if len(block_devices) == 1:
@ -224,9 +226,9 @@ def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str,
if len(block_device_struct["partitions"]): if len(block_device_struct["partitions"]):
prompt = _('{} contains queued partitions, this will remove those, are you sure?').format(block_device) prompt = _('{} contains queued partitions, this will remove those, are you sure?').format(block_device)
choice = Menu(prompt, ['yes', 'no'], default_option='no').run() choice = Menu(prompt, Menu.yes_no(), default_option=Menu.no()).run()
if choice == 'no': if choice == Menu.no():
continue continue
block_device_struct.update(suggest_single_disk_layout(block_device)[block_device.path]) block_device_struct.update(suggest_single_disk_layout(block_device)[block_device.path])

View File

@ -1,4 +1,4 @@
from typing import Any, Dict from typing import Dict
from ..menu.list_manager import ListManager from ..menu.list_manager import ListManager
from ..menu.selection_menu import Selector, GeneralMenu from ..menu.selection_menu import Selector, GeneralMenu

View File

@ -102,9 +102,9 @@ def select_driver(options: Dict[str, Any] = AVAILABLE_GFX_DRIVERS) -> str:
def ask_for_bootloader(advanced_options: bool = False, preset: str = None) -> str: def ask_for_bootloader(advanced_options: bool = False, preset: str = None) -> str:
if preset == 'systemd-bootctl': if preset == 'systemd-bootctl':
preset_val = 'systemd-boot' if advanced_options else 'no' preset_val = 'systemd-boot' if advanced_options else Menu.no()
elif preset == 'grub-install': elif preset == 'grub-install':
preset_val = 'grub' if advanced_options else 'yes' preset_val = 'grub' if advanced_options else Menu.yes()
else: else:
preset_val = preset preset_val = preset
@ -112,11 +112,11 @@ def ask_for_bootloader(advanced_options: bool = False, preset: str = None) -> st
if has_uefi(): if has_uefi():
if not advanced_options: if not advanced_options:
bootloader_choice = Menu(_('Would you like to use GRUB as a bootloader instead of systemd-boot?'), bootloader_choice = Menu(_('Would you like to use GRUB as a bootloader instead of systemd-boot?'),
['yes', 'no'], Menu.yes_no(),
preset_values=preset_val, preset_values=preset_val,
default_option='no').run() default_option=Menu.no()).run()
if bootloader_choice == "yes": if bootloader_choice == Menu.yes():
bootloader = "grub-install" bootloader = "grub-install"
else: else:
# We use the common names for the bootloader as the selection, and map it back to the expected values. # We use the common names for the bootloader as the selection, and map it back to the expected values.
@ -135,9 +135,9 @@ def ask_for_bootloader(advanced_options: bool = False, preset: str = None) -> st
def ask_for_swap(preset: bool = True) -> bool: def ask_for_swap(preset: bool = True) -> bool:
if preset: if preset:
preset_val = 'yes' preset_val = Menu.yes()
else: else:
preset_val = 'no' preset_val = Menu.no()
prompt = _('Would you like to use swap on zram?') prompt = _('Would you like to use swap on zram?')
choice = Menu(prompt, ['yes', 'no'], default_option='yes', preset_values=preset_val).run() choice = Menu(prompt, Menu.yes_no(), default_option=Menu.yes(), preset_values=preset_val).run()
return False if choice == 'no' else True return False if choice == Menu.no() else True

View File

@ -28,12 +28,9 @@ def check_password_strong(passwd: str) -> bool:
symbol_count += 40 symbol_count += 40
if symbol_count**len(passwd) < 10e20: if symbol_count**len(passwd) < 10e20:
prompt = str(_("The password you are using seems to be weak, are you sure you want to use it?"))
prompt = _("The password you are using seems to be weak,") choice = Menu(prompt, Menu.yes_no(), default_option=Menu.yes()).run()
prompt += _("are you sure you want to use it?") return choice == Menu.yes()
choice = Menu(prompt, ["yes", "no"], default_option="yes").run()
return choice == "yes"
return True return True
@ -84,7 +81,7 @@ def do_countdown() -> bool:
if SIG_TRIGGER: if SIG_TRIGGER:
prompt = _('Do you really want to abort?') prompt = _('Do you really want to abort?')
choice = Menu(prompt, ['yes', 'no'], skip=False).run() choice = Menu(prompt, Menu.yes_no(), skip=False).run()
if choice == 'yes': if choice == 'yes':
exit(0) exit(0)

View File

@ -3,7 +3,7 @@ import os
import time import time
import archinstall import archinstall
from archinstall import ConfigurationOutput from archinstall import ConfigurationOutput, Menu
from archinstall.lib.models.network_configuration import NetworkConfigurationHandler from archinstall.lib.models.network_configuration import NetworkConfigurationHandler
if archinstall.arguments.get('help'): if archinstall.arguments.get('help'):
@ -258,8 +258,8 @@ def perform_installation(mountpoint):
installation.log("For post-installation tips, see https://wiki.archlinux.org/index.php/Installation_guide#Post-installation", fg="yellow") installation.log("For post-installation tips, see https://wiki.archlinux.org/index.php/Installation_guide#Post-installation", fg="yellow")
if not archinstall.arguments.get('silent'): if not archinstall.arguments.get('silent'):
prompt = 'Would you like to chroot into the newly created installation and perform post-installation configuration?' prompt = 'Would you like to chroot into the newly created installation and perform post-installation configuration?'
choice = archinstall.Menu(prompt, ['yes', 'no'], default_option='yes').run() choice = Menu(prompt, Menu.yes_no(), default_option=Menu.yes()).run()
if choice == 'yes': if choice == Menu.yes():
try: try:
installation.drop_to_shell() installation.drop_to_shell()
except: except:

View File

@ -20,7 +20,7 @@ import pathlib
from typing import TYPE_CHECKING, Any from typing import TYPE_CHECKING, Any
import archinstall import archinstall
from archinstall import ConfigurationOutput, NetworkConfigurationHandler from archinstall import ConfigurationOutput, NetworkConfigurationHandler, Menu
if TYPE_CHECKING: if TYPE_CHECKING:
_: Any _: Any
@ -38,8 +38,8 @@ TODO exec con return parameter
""" """
def select_activate_NTP(): def select_activate_NTP():
prompt = "Would you like to use automatic time synchronization (NTP) with the default time servers? [Y/n]: " prompt = "Would you like to use automatic time synchronization (NTP) with the default time servers? [Y/n]: "
choice = archinstall.Menu(prompt, ['yes', 'no'], default_option='yes').run() choice = Menu(prompt, Menu.yes_no(), default_option=Menu.yes()).run()
if choice == 'yes': if choice == Menu.yes():
return True return True
else: else:
return False return False
@ -480,8 +480,8 @@ def perform_installation(mountpoint, mode):
installation.log("For post-installation tips, see https://wiki.archlinux.org/index.php/Installation_guide#Post-installation", fg="yellow") installation.log("For post-installation tips, see https://wiki.archlinux.org/index.php/Installation_guide#Post-installation", fg="yellow")
if not archinstall.arguments.get('silent'): if not archinstall.arguments.get('silent'):
prompt = 'Would you like to chroot into the newly created installation and perform post-installation configuration?' prompt = 'Would you like to chroot into the newly created installation and perform post-installation configuration?'
choice = archinstall.Menu(prompt, ['yes', 'no'], default_option='yes').run() choice = Menu(prompt, Menu.yes_no(), default_option=Menu.yes()).run()
if choice == 'yes': if choice == Menu.yes():
try: try:
installation.drop_to_shell() installation.drop_to_shell()
except: except:

View File

@ -1,5 +1,6 @@
# A desktop environment using "Sway" # A desktop environment using "Sway"
import archinstall import archinstall
from archinstall import Menu
is_top_level_profile = False is_top_level_profile = False
@ -22,8 +23,8 @@ def _check_driver() -> bool:
if packages and "nvidia" in packages: if packages and "nvidia" in packages:
prompt = 'The proprietary Nvidia driver is not supported by Sway. It is likely that you will run into issues, are you okay with that?' prompt = 'The proprietary Nvidia driver is not supported by Sway. It is likely that you will run into issues, are you okay with that?'
choice = archinstall.Menu(prompt, ['yes', 'no'], default_option='no').run() choice = Menu(prompt, Menu.yes_no(), default_option=Menu.no()).run()
if choice == 'no': if choice == Menu.no():
return False return False
return True return True