Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
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
parent2d371571783cde70554e3e4e272beab2546ffff9 (diff)
Fix 1117 (#1126)
* Fix 1117 * Update * flake8 Co-authored-by: Daniel Girtler <girtler.daniel@gmail.com>
-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
-rw-r--r--examples/guided.py6
-rw-r--r--examples/swiss.py10
-rw-r--r--profiles/sway.py5
13 files changed, 79 insertions, 59 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)
diff --git a/examples/guided.py b/examples/guided.py
index 15226668..1cee499d 100644
--- a/examples/guided.py
+++ b/examples/guided.py
@@ -3,7 +3,7 @@ import os
import time
import archinstall
-from archinstall import ConfigurationOutput
+from archinstall import ConfigurationOutput, Menu
from archinstall.lib.models.network_configuration import NetworkConfigurationHandler
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")
if not archinstall.arguments.get('silent'):
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()
- if choice == 'yes':
+ choice = Menu(prompt, Menu.yes_no(), default_option=Menu.yes()).run()
+ if choice == Menu.yes():
try:
installation.drop_to_shell()
except:
diff --git a/examples/swiss.py b/examples/swiss.py
index baf7b618..6d357191 100644
--- a/examples/swiss.py
+++ b/examples/swiss.py
@@ -20,7 +20,7 @@ import pathlib
from typing import TYPE_CHECKING, Any
import archinstall
-from archinstall import ConfigurationOutput, NetworkConfigurationHandler
+from archinstall import ConfigurationOutput, NetworkConfigurationHandler, Menu
if TYPE_CHECKING:
_: Any
@@ -38,8 +38,8 @@ TODO exec con return parameter
"""
def select_activate_NTP():
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()
- if choice == 'yes':
+ choice = Menu(prompt, Menu.yes_no(), default_option=Menu.yes()).run()
+ if choice == Menu.yes():
return True
else:
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")
if not archinstall.arguments.get('silent'):
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()
- if choice == 'yes':
+ choice = Menu(prompt, Menu.yes_no(), default_option=Menu.yes()).run()
+ if choice == Menu.yes():
try:
installation.drop_to_shell()
except:
diff --git a/profiles/sway.py b/profiles/sway.py
index e9c71b79..0819db95 100644
--- a/profiles/sway.py
+++ b/profiles/sway.py
@@ -1,5 +1,6 @@
# A desktop environment using "Sway"
import archinstall
+from archinstall import Menu
is_top_level_profile = False
@@ -22,8 +23,8 @@ def _check_driver() -> bool:
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?'
- choice = archinstall.Menu(prompt, ['yes', 'no'], default_option='no').run()
- if choice == 'no':
+ choice = Menu(prompt, Menu.yes_no(), default_option=Menu.no()).run()
+ if choice == Menu.no():
return False
return True