Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall
diff options
context:
space:
mode:
authorDaniel Girtler <blackrabbit256@gmail.com>2022-05-05 20:48:01 +1000
committerGitHub <noreply@github.com>2022-05-05 12:48:01 +0200
commitbcd810d2d20e657d96f36e0007facff71e9532bc (patch)
treeb3b50f73b6b159bab19d5caaa279f0e3d637568c /archinstall
parent2d371571783cde70554e3e4e272beab2546ffff9 (diff)
Fix 1117 (#1126)
* Fix 1117 * Update * flake8 Co-authored-by: Daniel Girtler <girtler.daniel@gmail.com>
Diffstat (limited to 'archinstall')
-rw-r--r--archinstall/lib/disk/user_guides.py36
-rw-r--r--archinstall/lib/menu/global_menu.py4
-rw-r--r--archinstall/lib/menu/menu.py14
-rw-r--r--archinstall/lib/user_interaction/disk_conf.py4
-rw-r--r--archinstall/lib/user_interaction/general_conf.py8
-rw-r--r--archinstall/lib/user_interaction/manage_users_conf.py8
-rw-r--r--archinstall/lib/user_interaction/partitioning_conf.py12
-rw-r--r--archinstall/lib/user_interaction/subvolume_config.py2
-rw-r--r--archinstall/lib/user_interaction/system_conf.py18
-rw-r--r--archinstall/lib/user_interaction/utils.py11
10 files changed, 68 insertions, 49 deletions
diff --git a/archinstall/lib/disk/user_guides.py b/archinstall/lib/disk/user_guides.py
index 63ec1d9b..77da52e4 100644
--- a/archinstall/lib/disk/user_guides.py
+++ b/archinstall/lib/disk/user_guides.py
@@ -5,6 +5,7 @@ from typing import Optional, Dict, Any, List, TYPE_CHECKING
# https://stackoverflow.com/a/39757388/929999
if TYPE_CHECKING:
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 ..hardware import has_uefi
@@ -26,13 +27,13 @@ def suggest_single_disk_layout(block_device :BlockDevice,
compression = False
if default_filesystem == 'btrfs':
- prompt = 'Would you like to use BTRFS subvolumes with a default structure?'
- choice = Menu(prompt, ['yes', 'no'], skip=False, default_option='yes').run()
- using_subvolumes = choice == 'yes'
+ prompt = str(_('Would you like to use BTRFS subvolumes with a default structure?'))
+ choice = Menu(prompt, Menu.yes_no(), skip=False, default_option=Menu.yes()).run()
+ using_subvolumes = choice == Menu.yes()
- prompt = 'Would you like to use BTRFS compression?'
- choice = Menu(prompt, ['yes', 'no'], skip=False, default_option='yes').run()
- compression = choice == 'yes'
+ prompt = str(_('Would you like to use BTRFS compression?'))
+ choice = Menu(prompt, Menu.yes_no(), skip=False, default_option=Menu.yes()).run()
+ compression = choice == Menu.yes()
layout = {
block_device.path : {
@@ -87,9 +88,9 @@ def suggest_single_disk_layout(block_device :BlockDevice,
layout[block_device.path]['partitions'][-1]['start'] = '513MiB'
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?'
- choice = Menu(prompt, ['yes', 'no'], skip=False, default_option='yes').run()
- using_home_partition = choice == 'yes'
+ prompt = str(_('Would you like to create a separate partition for /home?'))
+ choice = Menu(prompt, Menu.yes_no(), skip=False, default_option=Menu.yes()).run()
+ using_home_partition = choice == Menu.yes()
# Set a size for / (/root)
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
-def suggest_multi_disk_layout(block_devices :List[BlockDevice],
- default_filesystem :Optional[str] = None,
- advanced_options :bool = False) -> Dict[str, Any]:
+def suggest_multi_disk_layout(block_devices :List[BlockDevice], default_filesystem :Optional[str] = None, advanced_options :bool = False):
if not default_filesystem:
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)
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
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()
# using_subvolumes = choice == 'yes'
- prompt = 'Would you like to use BTRFS compression?'
- choice = Menu(prompt, ['yes', 'no'], skip=False, default_option='yes').run()
- compression = choice == 'yes'
+ prompt = str(_('Would you like to use BTRFS compression?'))
+ choice = Menu(prompt, Menu.yes_no(), skip=False, default_option=Menu.yes()).run()
+ 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)
diff --git a/archinstall/lib/menu/global_menu.py b/archinstall/lib/menu/global_menu.py
index 63b8c03e..b3c5c6a2 100644
--- a/archinstall/lib/menu/global_menu.py
+++ b/archinstall/lib/menu/global_menu.py
@@ -262,9 +262,9 @@ class GlobalMenu(GeneralMenu):
"Do you wish to continue?"
).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)
return harddrives
diff --git a/archinstall/lib/menu/menu.py b/archinstall/lib/menu/menu.py
index d254e0f9..48ea4635 100644
--- a/archinstall/lib/menu/menu.py
+++ b/archinstall/lib/menu/menu.py
@@ -12,7 +12,21 @@ import logging
if TYPE_CHECKING:
_: Any
+
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__(
self,
title :str,
diff --git a/archinstall/lib/user_interaction/disk_conf.py b/archinstall/lib/user_interaction/disk_conf.py
index a51f10b8..e84f647a 100644
--- a/archinstall/lib/user_interaction/disk_conf.py
+++ b/archinstall/lib/user_interaction/disk_conf.py
@@ -1,6 +1,6 @@
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 ..disk import BlockDevice
@@ -36,7 +36,7 @@ def select_individual_blockdevice_usage(block_devices: list) -> Dict[str, Any]:
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'))
custome_mode = str(_('Select what to do with each individual drive (followed by partition usage)'))
modes = [wipe_mode, custome_mode]
diff --git a/archinstall/lib/user_interaction/general_conf.py b/archinstall/lib/user_interaction/general_conf.py
index c42e9e27..78f6b460 100644
--- a/archinstall/lib/user_interaction/general_conf.py
+++ b/archinstall/lib/user_interaction/general_conf.py
@@ -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(_('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:
- preset_val = 'yes'
+ preset_val = Menu.yes()
else:
- preset_val = 'no'
- choice = Menu(prompt, ['yes', 'no'], skip=False, preset_values=preset_val, default_option='yes').run()
- return False if choice == 'no' else True
+ preset_val = Menu.no()
+ choice = Menu(prompt, Menu.yes_no(), skip=False, preset_values=preset_val, default_option=Menu.yes()).run()
+ return False if choice == Menu.no() else True
def ask_hostname(preset: str = None) -> str:
diff --git a/archinstall/lib/user_interaction/manage_users_conf.py b/archinstall/lib/user_interaction/manage_users_conf.py
index d69ccce9..ea909f35 100644
--- a/archinstall/lib/user_interaction/manage_users_conf.py
+++ b/archinstall/lib/user_interaction/manage_users_conf.py
@@ -109,11 +109,11 @@ class UserList(ListManager):
sudoer = False
else:
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,
- preset_values='yes' if sudoer else 'no',
- default_option='no').run()
- sudoer = True if sudo_choice == 'yes' else False
+ preset_values=Menu.yes() if sudoer else Menu.no(),
+ default_option=Menu.no()).run()
+ sudoer = True if sudo_choice == Menu.yes() else False
password = get_password(prompt=str(_('Password for user "{}": ').format(userid)))
diff --git a/archinstall/lib/user_interaction/partitioning_conf.py b/archinstall/lib/user_interaction/partitioning_conf.py
index 2182c6b3..afca1cef 100644
--- a/archinstall/lib/user_interaction/partitioning_conf.py
+++ b/archinstall/lib/user_interaction/partitioning_conf.py
@@ -1,6 +1,6 @@
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 ..output import log
@@ -97,8 +97,10 @@ def select_partition(title :str, partitions :List[Partition], multiple :bool = F
return None
-def get_default_partition_layout(block_devices: Union['BlockDevice', List['BlockDevice']],
- advanced_options: bool = False) -> Dict[str, Any]:
+def get_default_partition_layout(
+ 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
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"]):
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
block_device_struct.update(suggest_single_disk_layout(block_device)[block_device.path])
diff --git a/archinstall/lib/user_interaction/subvolume_config.py b/archinstall/lib/user_interaction/subvolume_config.py
index adbb7430..bb159a8b 100644
--- a/archinstall/lib/user_interaction/subvolume_config.py
+++ b/archinstall/lib/user_interaction/subvolume_config.py
@@ -1,4 +1,4 @@
-from typing import Any, Dict
+from typing import Dict
from ..menu.list_manager import ListManager
from ..menu.selection_menu import Selector, GeneralMenu
diff --git a/archinstall/lib/user_interaction/system_conf.py b/archinstall/lib/user_interaction/system_conf.py
index 5d4c80dc..17c093c1 100644
--- a/archinstall/lib/user_interaction/system_conf.py
+++ b/archinstall/lib/user_interaction/system_conf.py
@@ -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:
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':
- preset_val = 'grub' if advanced_options else 'yes'
+ preset_val = 'grub' if advanced_options else Menu.yes()
else:
preset_val = preset
@@ -112,11 +112,11 @@ def ask_for_bootloader(advanced_options: bool = False, preset: str = None) -> st
if has_uefi():
if not advanced_options:
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,
- default_option='no').run()
+ default_option=Menu.no()).run()
- if bootloader_choice == "yes":
+ if bootloader_choice == Menu.yes():
bootloader = "grub-install"
else:
# 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:
if preset:
- preset_val = 'yes'
+ preset_val = Menu.yes()
else:
- preset_val = 'no'
+ preset_val = Menu.no()
prompt = _('Would you like to use swap on zram?')
- choice = Menu(prompt, ['yes', 'no'], default_option='yes', preset_values=preset_val).run()
- return False if choice == 'no' else True
+ choice = Menu(prompt, Menu.yes_no(), default_option=Menu.yes(), preset_values=preset_val).run()
+ return False if choice == Menu.no() else True
diff --git a/archinstall/lib/user_interaction/utils.py b/archinstall/lib/user_interaction/utils.py
index 48b55e8c..59f2dfbc 100644
--- a/archinstall/lib/user_interaction/utils.py
+++ b/archinstall/lib/user_interaction/utils.py
@@ -28,12 +28,9 @@ def check_password_strong(passwd: str) -> bool:
symbol_count += 40
if symbol_count**len(passwd) < 10e20:
-
- prompt = _("The password you are using seems to be weak,")
- prompt += _("are you sure you want to use it?")
-
- choice = Menu(prompt, ["yes", "no"], default_option="yes").run()
- return choice == "yes"
+ prompt = str(_("The password you are using seems to be weak, are you sure you want to use it?"))
+ choice = Menu(prompt, Menu.yes_no(), default_option=Menu.yes()).run()
+ return choice == Menu.yes()
return True
@@ -84,7 +81,7 @@ def do_countdown() -> bool:
if SIG_TRIGGER:
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':
exit(0)