system and disk conf
This commit is contained in:
parent
61391a6f4f
commit
d28ceaeeb4
|
@ -267,6 +267,15 @@ class GlobalMenu(GeneralMenu):
|
|||
return FormattedOutput.as_table(drives)
|
||||
return None
|
||||
|
||||
def _prev_lvmdrives(self) -> Optional[str]:
|
||||
selector = self._menu_options['lvmdrives']
|
||||
if selector.has_selection():
|
||||
drives = selector.current_selection
|
||||
# print("------lvm drives--->>>",drives)
|
||||
as_table = FormattedOutput.as_table(drives)
|
||||
return as_table
|
||||
return None
|
||||
|
||||
def _prev_disk_layouts(self) -> Optional[str]:
|
||||
selector = self._menu_options['disk_layouts']
|
||||
if selector.has_selection():
|
||||
|
@ -281,6 +290,22 @@ class GlobalMenu(GeneralMenu):
|
|||
return output.rstrip()
|
||||
|
||||
return None
|
||||
|
||||
def _prev_lvm_layouts(self) -> Optional[str]:
|
||||
|
||||
selector = self._menu_options['lvm_layouts']
|
||||
if selector.has_selection():
|
||||
layouts: Dict[str, Dict[str, Any]] = selector.current_selection
|
||||
|
||||
output = ''
|
||||
for device, layout in layouts.items():
|
||||
output += f'{_("LVM Device")}: {device}\n\n'
|
||||
output += current_lvm_layout(layout['partitions'], with_title=False)
|
||||
output += '\n\n'
|
||||
|
||||
return output.rstrip()
|
||||
|
||||
return None
|
||||
|
||||
def _display_disk_layout(self, current_value: Optional[Dict[str, Any]]) -> str:
|
||||
if current_value:
|
||||
|
@ -289,6 +314,13 @@ class GlobalMenu(GeneralMenu):
|
|||
return f'{total_nr} {_("Partitions")}'
|
||||
return ''
|
||||
|
||||
def _display_lvm_layout(self, current_value: Optional[Dict[str, Any]]) -> str:
|
||||
if current_value:
|
||||
total_partitions = [entry['partitions'] for entry in current_value.values()]
|
||||
total_nr = sum([len(p) for p in total_partitions])
|
||||
return f'{total_nr} {_("Partitions")}'
|
||||
return ''
|
||||
|
||||
def _prev_install_missing_config(self) -> Optional[str]:
|
||||
if missing := self._missing_configs():
|
||||
text = str(_('Missing configurations:\n'))
|
||||
|
@ -373,6 +405,33 @@ class GlobalMenu(GeneralMenu):
|
|||
|
||||
return harddrives
|
||||
|
||||
def _select_lvmdrives(self, old_lvmdrives: List[str] = [], disk_layouts: List[Dict[str,Any]] = []) -> List:
|
||||
# print("_select_lvmdrivesdisk_layouts-=====>>>",disk_layouts)
|
||||
lvmdrives = select_lvmdrives(old_lvmdrives, disk_layouts)
|
||||
storage['arguments']['lvmdrives'] = lvmdrives
|
||||
# print("_select_lvmdrives-=====>>>",storage['arguments']['lvmdrives'])
|
||||
if lvmdrives is not None:
|
||||
if len(lvmdrives) == 0:
|
||||
prompt = _(
|
||||
"You decided to skip harddrive selection\nand will use whatever drive-setup is mounted at {} (experimental)\n"
|
||||
"WARNING: Archinstall won't check the suitability of this setup\n"
|
||||
"Do you wish to continue?"
|
||||
).format(storage['MOUNT_POINT'])
|
||||
|
||||
choice = Menu(prompt, Menu.yes_no(), default_option=Menu.yes(), skip=False).run()
|
||||
|
||||
if choice.value == Menu.no():
|
||||
self._disk_check = True
|
||||
return self._select_lvmdrives(old_lvmdrives)
|
||||
else:
|
||||
self._disk_check = False
|
||||
|
||||
# in case the harddrives got changed we have to reset the disk layout as well
|
||||
if old_lvmdrives != lvmdrives:
|
||||
self._menu_options['lvm_layouts'].set_current_selection(None)
|
||||
storage['arguments']['lvm_layouts'] = {}
|
||||
return lvmdrives
|
||||
|
||||
def _select_profile(self, preset):
|
||||
profile = select_profile(preset)
|
||||
ret = None
|
||||
|
|
|
@ -2,96 +2,143 @@ from __future__ import annotations
|
|||
|
||||
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,manage_new_and_existing_lvm_partitions
|
||||
from ..disk import BlockDevice
|
||||
from ..exceptions import DiskError
|
||||
from ..menu import Menu
|
||||
from ..menu.menu import MenuSelectionType
|
||||
import time
|
||||
|
||||
if TYPE_CHECKING:
|
||||
_: Any
|
||||
_: Any
|
||||
|
||||
def ask_for_lvm_partition_format() -> bool:
|
||||
prompt = str(_('Would you like to use LVM structure,it will wipe all select disks?'))
|
||||
choice = Menu(prompt, Menu.yes_no(), skip=False, default_option=Menu.no()).run()
|
||||
return choice.value == Menu.yes()
|
||||
|
||||
def ask_for_main_filesystem_format(advanced_options=False) -> str:
|
||||
options = {'btrfs': 'btrfs', 'ext4': 'ext4', 'xfs': 'xfs', 'f2fs': 'f2fs'}
|
||||
def ask_for_main_filesystem_format(advanced_options=False,excludes:list[str] = []) -> str:
|
||||
options = {'btrfs': 'btrfs', 'ext4': 'ext4', 'xfs': 'xfs', 'f2fs': 'f2fs'}
|
||||
|
||||
advanced = {'ntfs': 'ntfs'}
|
||||
for key in excludes:
|
||||
options.pop(key)
|
||||
|
||||
if advanced_options:
|
||||
options.update(advanced)
|
||||
advanced = {'ntfs': 'ntfs'}
|
||||
|
||||
prompt = _('Select which filesystem your main partition should use')
|
||||
choice = Menu(prompt, options, skip=False).run()
|
||||
return choice.value
|
||||
if advanced_options:
|
||||
options.update(advanced)
|
||||
|
||||
prompt = _('Select which filesystem your main partition should use')
|
||||
choice = Menu(prompt, options, skip=False).run()
|
||||
return choice.value
|
||||
|
||||
def select_individual_blockdevice_usage(block_devices: list) -> Dict[str, Any]:
|
||||
result = {}
|
||||
result = {}
|
||||
|
||||
for device in block_devices:
|
||||
layout = manage_new_and_existing_partitions(device)
|
||||
result[device.path] = layout
|
||||
for device in block_devices:
|
||||
layout = manage_new_and_existing_partitions(device)
|
||||
result[device.path] = layout
|
||||
print("select_individual_blockdevice_usage=====>>>>",result)
|
||||
# time.sleep(1000)
|
||||
return result
|
||||
|
||||
return result
|
||||
def select_individual_lvmdevice_usage(block_lvm_devices: list) -> Dict[str, Any]:
|
||||
result = {}
|
||||
|
||||
print("select_individual_lvmdevice_usage=1====>",block_lvm_devices)
|
||||
for inx,device in enumerate(block_lvm_devices):
|
||||
lvmpartitions = manage_new_and_existing_lvm_partitions(device)
|
||||
block_lvm_devices[inx]['partitions'] = lvmpartitions["partitions"]
|
||||
result[device["vg_name"]] = block_lvm_devices[inx]
|
||||
print("select_individual_lvmdevice_usage==2===>",block_lvm_devices)
|
||||
return result
|
||||
|
||||
def select_disk_layout(preset: Optional[Dict[str, Any]], 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]
|
||||
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]
|
||||
|
||||
warning = str(_('Are you sure you want to reset this setting?'))
|
||||
warning = str(_('Are you sure you want to reset this setting?'))
|
||||
|
||||
choice = Menu(
|
||||
_('Select what you wish to do with the selected block devices'),
|
||||
modes,
|
||||
raise_error_on_interrupt=True,
|
||||
raise_error_warning_msg=warning
|
||||
).run()
|
||||
choice = Menu(
|
||||
_('Select what you wish to do with the selected block devices'),
|
||||
modes,
|
||||
raise_error_on_interrupt=True,
|
||||
raise_error_warning_msg=warning
|
||||
).run()
|
||||
|
||||
# match choice.type_:
|
||||
# case MenuSelectionType.Esc: return preset
|
||||
# case MenuSelectionType.Ctrl_c: return None
|
||||
# case MenuSelectionType.Selection:
|
||||
# if choice.value == wipe_mode:
|
||||
# return get_default_partition_layout(block_devices, advanced_options)
|
||||
# else:
|
||||
# return select_individual_blockdevice_usage(block_devices)
|
||||
|
||||
if choice.type_ == MenuSelectionType.Esc:
|
||||
return preset
|
||||
elif choice.type_ == MenuSelectionType.Ctrl_c:
|
||||
return None
|
||||
elif choice.type_ == MenuSelectionType.Selection:
|
||||
if choice.value == wipe_mode:
|
||||
return get_default_partition_layout(block_devices, advanced_options)
|
||||
else:
|
||||
return select_individual_blockdevice_usage(block_devices)
|
||||
# match choice.type_:
|
||||
# case MenuSelectionType.Esc: return preset
|
||||
# case MenuSelectionType.Ctrl_c: return None
|
||||
# case MenuSelectionType.Selection:
|
||||
# if choice.value == wipe_mode:
|
||||
# return get_default_partition_layout(block_devices, advanced_options)
|
||||
# else:
|
||||
# return select_individual_blockdevice_usage(block_devices)
|
||||
|
||||
if choice.type_ == MenuSelectionType.Esc:
|
||||
return preset
|
||||
elif choice.type_ == MenuSelectionType.Ctrl_c:
|
||||
return None
|
||||
elif choice.type_ == MenuSelectionType.Selection:
|
||||
|
||||
layout = {}
|
||||
if choice.value == wipe_mode:
|
||||
layout = get_default_partition_layout(block_devices, advanced_options)
|
||||
else:
|
||||
layout = select_individual_blockdevice_usage(block_devices)
|
||||
return layout
|
||||
|
||||
def select_lvm_layout(preset: Optional[Dict[str, Any]], lvmdrives:list, advanced_options=False) -> Optional[Dict[str, Any]]:
|
||||
# if len(lvmdrives)==1:
|
||||
# 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]
|
||||
|
||||
# warning = str(_('Are you sure you want to reset this setting?'))
|
||||
|
||||
# choice = Menu(
|
||||
# _('Select what you wish to do with the selected block devices'),
|
||||
# modes,
|
||||
# raise_error_on_interrupt=True,
|
||||
# raise_error_warning_msg=warning
|
||||
# ).run()
|
||||
# if choice.type_ == MenuSelectionType.Esc:
|
||||
# return preset
|
||||
# elif choice.type_ == MenuSelectionType.Ctrl_c:
|
||||
# return None
|
||||
# elif choice.type_ == MenuSelectionType.Selection:
|
||||
# layout = {}
|
||||
# if choice.value == wipe_mode:
|
||||
# layout = get_default_partition_layout(lvmdrives, advanced_options)
|
||||
# else:
|
||||
# layout = select_individual_blockdevice_usage(lvmdrives)
|
||||
# return layout
|
||||
# else:
|
||||
return select_individual_lvmdevice_usage(lvmdrives)
|
||||
|
||||
def select_disk(dict_o_disks: Dict[str, BlockDevice]) -> Optional[BlockDevice]:
|
||||
"""
|
||||
Asks the user to select a harddrive from the `dict_o_disks` selection.
|
||||
Usually this is combined with :ref:`archinstall.list_drives`.
|
||||
"""
|
||||
Asks the user to select a harddrive from the `dict_o_disks` selection.
|
||||
Usually this is combined with :ref:`archinstall.list_drives`.
|
||||
|
||||
:param dict_o_disks: A `dict` where keys are the drive-name, value should be a dict containing drive information.
|
||||
:type dict_o_disks: dict
|
||||
:param dict_o_disks: A `dict` where keys are the drive-name, value should be a dict containing drive information.
|
||||
:type dict_o_disks: dict
|
||||
|
||||
:return: The name/path (the dictionary key) of the selected drive
|
||||
:rtype: str
|
||||
"""
|
||||
drives = sorted(list(dict_o_disks.keys()))
|
||||
if len(drives) >= 1:
|
||||
title = str(_('You can skip selecting a drive and partitioning and use whatever drive-setup is mounted at /mnt (experimental)')) + '\n'
|
||||
title += str(_('Select one of the disks or skip and use /mnt as default'))
|
||||
:return: The name/path (the dictionary key) of the selected drive
|
||||
:rtype: str
|
||||
"""
|
||||
drives = sorted(list(dict_o_disks.keys()))
|
||||
if len(drives) >= 1:
|
||||
title = str(_('You can skip selecting a drive and partitioning and use whatever drive-setup is mounted at /mnt (experimental)')) + '\n'
|
||||
title += str(_('Select one of the disks or skip and use /mnt as default'))
|
||||
|
||||
choice = Menu(title, drives).run()
|
||||
choice = Menu(title, drives).run()
|
||||
|
||||
if choice.type_ == MenuSelectionType.Esc:
|
||||
return None
|
||||
if choice.type_ == MenuSelectionType.Esc:
|
||||
return None
|
||||
|
||||
drive = dict_o_disks[choice.value]
|
||||
return drive
|
||||
drive = dict_o_disks[choice.value]
|
||||
return drive
|
||||
|
||||
raise DiskError('select_disk() requires a non-empty dictionary of disks to select from.')
|
||||
raise DiskError('select_disk() requires a non-empty dictionary of disks to select from.')
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import List, Any, Dict, TYPE_CHECKING
|
||||
import time
|
||||
from typing import List, Any, Dict,Optional, TYPE_CHECKING
|
||||
|
||||
from ..disk import all_blockdevices
|
||||
from ..exceptions import RequirementError
|
||||
|
@ -10,192 +10,281 @@ from ..menu.menu import MenuSelectionType
|
|||
from ..storage import storage
|
||||
|
||||
if TYPE_CHECKING:
|
||||
_: Any
|
||||
_: Any
|
||||
|
||||
|
||||
def select_kernel(preset: List[str] = None) -> List[str]:
|
||||
"""
|
||||
Asks the user to select a kernel for system.
|
||||
"""
|
||||
Asks the user to select a kernel for system.
|
||||
|
||||
:return: The string as a selected kernel
|
||||
:rtype: string
|
||||
"""
|
||||
:return: The string as a selected kernel
|
||||
:rtype: string
|
||||
"""
|
||||
|
||||
kernels = ["linux", "linux-lts", "linux-zen", "linux-hardened"]
|
||||
default_kernel = "linux"
|
||||
kernels = ["linux", "linux-lts", "linux-zen", "linux-hardened"]
|
||||
default_kernel = "linux"
|
||||
|
||||
warning = str(_('Are you sure you want to reset this setting?'))
|
||||
warning = str(_('Are you sure you want to reset this setting?'))
|
||||
|
||||
choice = Menu(
|
||||
_('Choose which kernels to use or leave blank for default "{}"').format(default_kernel),
|
||||
kernels,
|
||||
sort=True,
|
||||
multi=True,
|
||||
preset_values=preset,
|
||||
raise_error_on_interrupt=True,
|
||||
raise_error_warning_msg=warning
|
||||
).run()
|
||||
choice = Menu(
|
||||
_('Choose which kernels to use or leave blank for default "{}"').format(default_kernel),
|
||||
kernels,
|
||||
sort=True,
|
||||
multi=True,
|
||||
preset_values=preset,
|
||||
raise_error_on_interrupt=True,
|
||||
raise_error_warning_msg=warning
|
||||
).run()
|
||||
|
||||
# match choice.type_:
|
||||
# case MenuSelectionType.Esc: return preset
|
||||
# case MenuSelectionType.Ctrl_c: return []
|
||||
# case MenuSelectionType.Selection: return choice.value
|
||||
if choice.type_ == MenuSelectionType.Esc:
|
||||
return preset
|
||||
elif choice.type_ == MenuSelectionType.Ctrl_c:
|
||||
return []
|
||||
elif choice.type_ == MenuSelectionType.Selection:
|
||||
return choice.value
|
||||
# match choice.type_:
|
||||
# case MenuSelectionType.Esc: return preset
|
||||
# case MenuSelectionType.Ctrl_c: return []
|
||||
# case MenuSelectionType.Selection: return choice.value
|
||||
if choice.type_ == MenuSelectionType.Esc:
|
||||
return preset
|
||||
elif choice.type_ == MenuSelectionType.Ctrl_c:
|
||||
return []
|
||||
elif choice.type_ == MenuSelectionType.Selection:
|
||||
return choice.value
|
||||
|
||||
|
||||
def select_harddrives(preset: List[str] = []) -> List[str]:
|
||||
"""
|
||||
Asks the user to select one or multiple hard drives
|
||||
"""
|
||||
Asks the user to select one or multiple hard drives
|
||||
|
||||
:return: List of selected hard drives
|
||||
:rtype: list
|
||||
"""
|
||||
hard_drives = all_blockdevices(partitions=False).values()
|
||||
options = {f'{option}': option for option in hard_drives}
|
||||
:return: List of selected hard drives
|
||||
:rtype: list
|
||||
"""
|
||||
hard_drives = all_blockdevices(partitions=False).values()
|
||||
options = {f'{option}': option for option in hard_drives}
|
||||
|
||||
options_keys = list(options.keys())
|
||||
options_keys = list(options.keys())
|
||||
|
||||
if preset is not None:
|
||||
preset_selection = [str(v) for v in preset]
|
||||
else:
|
||||
preset_selection = []
|
||||
if preset is not None:
|
||||
preset_selection = [str(v) for v in preset]
|
||||
else:
|
||||
preset_selection = []
|
||||
|
||||
title = str(_('Select one or more hard drives to use and configure\n'))
|
||||
title += str(_('Any modifications to the existing setting will reset the disk layout! preset:{}'))
|
||||
title = str(_('Select one or more hard drives to use and configure\n'))
|
||||
title += str(_('Any modifications to the existing setting will reset the disk layout!'))
|
||||
|
||||
warning = str(_('If you reset the harddrive selection this will also reset the current disk layout. Are you sure?'))
|
||||
warning = str(_('If you reset the harddrive selection this will also reset the current disk layout. Are you sure?'))
|
||||
|
||||
selected_harddrive = Menu(
|
||||
title,
|
||||
options_keys,
|
||||
preset_values=preset_selection,
|
||||
multi=True,
|
||||
raise_error_on_interrupt=True,
|
||||
raise_error_warning_msg=warning
|
||||
).run()
|
||||
selected_harddrive = Menu(
|
||||
title,
|
||||
options_keys,
|
||||
preset_values=preset_selection,
|
||||
multi=True,
|
||||
raise_error_on_interrupt=True,
|
||||
raise_error_warning_msg=warning
|
||||
).run()
|
||||
|
||||
# match selected_harddrive.type_:
|
||||
# case MenuSelectionType.Ctrl_c: return []
|
||||
# case MenuSelectionType.Esc: return preset
|
||||
# case MenuSelectionType.Selection: return [options[i] for i in selected_harddrive.value]
|
||||
if selected_harddrive.type_ == MenuSelectionType.Esc:
|
||||
return preset
|
||||
elif selected_harddrive.type_ == MenuSelectionType.Ctrl_c:
|
||||
return []
|
||||
elif selected_harddrive.type_ == MenuSelectionType.Selection:
|
||||
return [options[i] for i in selected_harddrive.value]
|
||||
# match selected_harddrive.type_:
|
||||
# case MenuSelectionType.Ctrl_c: return []
|
||||
# case MenuSelectionType.Esc: return preset
|
||||
# case MenuSelectionType.Selection: return [options[i] for i in selected_harddrive.value]
|
||||
if selected_harddrive.type_ == MenuSelectionType.Esc:
|
||||
return preset
|
||||
elif selected_harddrive.type_ == MenuSelectionType.Ctrl_c:
|
||||
return []
|
||||
elif selected_harddrive.type_ == MenuSelectionType.Selection:
|
||||
return [options[i] for i in selected_harddrive.value]
|
||||
|
||||
|
||||
def select_driver(options: Dict[str, Any] = AVAILABLE_GFX_DRIVERS) -> str:
|
||||
"""
|
||||
Some what convoluted function, whose job is simple.
|
||||
Select a graphics driver from a pre-defined set of popular options.
|
||||
"""
|
||||
Some what convoluted function, whose job is simple.
|
||||
Select a graphics driver from a pre-defined set of popular options.
|
||||
|
||||
(The template xorg is for beginner users, not advanced, and should
|
||||
there for appeal to the general public first and edge cases later)
|
||||
"""
|
||||
(The template xorg is for beginner users, not advanced, and should
|
||||
there for appeal to the general public first and edge cases later)
|
||||
"""
|
||||
|
||||
drivers = sorted(list(options))
|
||||
drivers = sorted(list(options))
|
||||
|
||||
if drivers:
|
||||
arguments = storage.get('arguments', {})
|
||||
title = ''
|
||||
if drivers:
|
||||
arguments = storage.get('arguments', {})
|
||||
title = ''
|
||||
|
||||
if has_amd_graphics():
|
||||
title += str(_(
|
||||
'For the best compatibility with your AMD hardware, you may want to use either the all open-source or AMD / ATI options.'
|
||||
)) + '\n'
|
||||
if has_intel_graphics():
|
||||
title += str(_(
|
||||
'For the best compatibility with your Intel hardware, you may want to use either the all open-source or Intel options.\n'
|
||||
))
|
||||
if has_nvidia_graphics():
|
||||
title += str(_(
|
||||
'For the best compatibility with your Nvidia hardware, you may want to use the Nvidia proprietary driver.\n'
|
||||
))
|
||||
if has_amd_graphics():
|
||||
title += str(_(
|
||||
'For the best compatibility with your AMD hardware, you may want to use either the all open-source or AMD / ATI options.'
|
||||
)) + '\n'
|
||||
if has_intel_graphics():
|
||||
title += str(_(
|
||||
'For the best compatibility with your Intel hardware, you may want to use either the all open-source or Intel options.\n'
|
||||
))
|
||||
if has_nvidia_graphics():
|
||||
title += str(_(
|
||||
'For the best compatibility with your Nvidia hardware, you may want to use the Nvidia proprietary driver.\n'
|
||||
))
|
||||
|
||||
title += str(_('\n\nSelect a graphics driver or leave blank to install all open-source drivers'))
|
||||
choice = Menu(title, drivers).run()
|
||||
title += str(_('\n\nSelect a graphics driver or leave blank to install all open-source drivers'))
|
||||
choice = Menu(title, drivers).run()
|
||||
|
||||
if choice.type_ != MenuSelectionType.Selection:
|
||||
return arguments.get('gfx_driver')
|
||||
if choice.type_ != MenuSelectionType.Selection:
|
||||
return arguments.get('gfx_driver')
|
||||
|
||||
arguments['gfx_driver'] = choice.value
|
||||
return options.get(choice.value)
|
||||
arguments['gfx_driver'] = choice.value
|
||||
return options.get(choice.value)
|
||||
|
||||
raise RequirementError("Selecting drivers require a least one profile to be given as an option.")
|
||||
raise RequirementError("Selecting drivers require a least one profile to be given as an option.")
|
||||
|
||||
|
||||
def ask_for_bootloader(advanced_options: bool = False, preset: str = None) -> str:
|
||||
if preset == 'systemd-bootctl':
|
||||
preset_val = 'systemd-boot' if advanced_options else Menu.no()
|
||||
elif preset == 'grub-install':
|
||||
preset_val = 'grub' if advanced_options else Menu.yes()
|
||||
else:
|
||||
preset_val = preset
|
||||
if preset == 'systemd-bootctl':
|
||||
preset_val = 'systemd-boot' if advanced_options else Menu.no()
|
||||
elif preset == 'grub-install':
|
||||
preset_val = 'grub' if advanced_options else Menu.yes()
|
||||
else:
|
||||
preset_val = preset
|
||||
|
||||
bootloader = "systemd-bootctl" if has_uefi() else "grub-install"
|
||||
bootloader = "systemd-bootctl" if has_uefi() else "grub-install"
|
||||
|
||||
if has_uefi():
|
||||
if not advanced_options:
|
||||
selection = Menu(
|
||||
_('Would you like to use GRUB as a bootloader instead of systemd-boot?'),
|
||||
Menu.yes_no(),
|
||||
preset_values=preset_val,
|
||||
default_option=Menu.no()
|
||||
).run()
|
||||
if has_uefi():
|
||||
if not advanced_options:
|
||||
selection = Menu(
|
||||
_('Would you like to use GRUB as a bootloader instead of systemd-boot?'),
|
||||
Menu.yes_no(),
|
||||
preset_values=preset_val,
|
||||
default_option=Menu.no()
|
||||
).run()
|
||||
|
||||
# match selection.type_:
|
||||
# case MenuSelectionType.Esc: return preset
|
||||
# case MenuSelectionType.Selection: bootloader = 'grub-install' if selection.value == Menu.yes() else bootloader
|
||||
|
||||
if selection.type_ == MenuSelectionType.Esc:
|
||||
return preset
|
||||
elif selection.type_ == MenuSelectionType.Selection:
|
||||
bootloader = 'grub-install' if selection.value == Menu.yes() else bootloader
|
||||
else:
|
||||
# We use the common names for the bootloader as the selection, and map it back to the expected values.
|
||||
choices = ['systemd-boot', 'grub', 'efistub']
|
||||
selection = Menu(_('Choose a bootloader'), choices, preset_values=preset_val).run()
|
||||
# match selection.type_:
|
||||
# case MenuSelectionType.Esc: return preset
|
||||
# case MenuSelectionType.Selection: bootloader = 'grub-install' if selection.value == Menu.yes() else bootloader
|
||||
|
||||
# value = ''
|
||||
# match selection.type_:
|
||||
# case MenuSelectionType.Esc: value = preset_val
|
||||
# case MenuSelectionType.Selection: value = selection.value
|
||||
if selection.type_ == MenuSelectionType.Esc:
|
||||
value = preset_val
|
||||
elif selection.type_ == MenuSelectionType.Selection:
|
||||
value = selection.value
|
||||
if selection.type_ == MenuSelectionType.Esc:
|
||||
return preset
|
||||
elif selection.type_ == MenuSelectionType.Selection:
|
||||
bootloader = 'grub-install' if selection.value == Menu.yes() else bootloader
|
||||
else:
|
||||
# We use the common names for the bootloader as the selection, and map it back to the expected values.
|
||||
choices = ['systemd-boot', 'grub', 'efistub']
|
||||
selection = Menu(_('Choose a bootloader'), choices, preset_values=preset_val).run()
|
||||
|
||||
if value != "":
|
||||
if value == 'systemd-boot':
|
||||
bootloader = 'systemd-bootctl'
|
||||
elif value == 'grub':
|
||||
bootloader = 'grub-install'
|
||||
else:
|
||||
bootloader = value
|
||||
# value = ''
|
||||
# match selection.type_:
|
||||
# case MenuSelectionType.Esc: value = preset_val
|
||||
# case MenuSelectionType.Selection: value = selection.value
|
||||
if selection.type_ == MenuSelectionType.Esc:
|
||||
value = preset_val
|
||||
elif selection.type_ == MenuSelectionType.Selection:
|
||||
value = selection.value
|
||||
|
||||
return bootloader
|
||||
if value != "":
|
||||
if value == 'systemd-boot':
|
||||
bootloader = 'systemd-bootctl'
|
||||
elif value == 'grub':
|
||||
bootloader = 'grub-install'
|
||||
else:
|
||||
bootloader = value
|
||||
|
||||
return bootloader
|
||||
|
||||
|
||||
def ask_for_swap(preset: bool = True) -> bool:
|
||||
if preset:
|
||||
preset_val = Menu.yes()
|
||||
else:
|
||||
preset_val = Menu.no()
|
||||
if preset:
|
||||
preset_val = Menu.yes()
|
||||
else:
|
||||
preset_val = Menu.no()
|
||||
|
||||
prompt = _('Would you like to use swap on zram?')
|
||||
choice = Menu(prompt, Menu.yes_no(), default_option=Menu.yes(), preset_values=preset_val).run()
|
||||
prompt = _('Would you like to use swap on zram?')
|
||||
choice = Menu(prompt, Menu.yes_no(), default_option=Menu.yes(), preset_values=preset_val).run()
|
||||
|
||||
# match choice.type_:
|
||||
# case MenuSelectionType.Esc: return preset
|
||||
# case MenuSelectionType.Selection: return False if choice.value == Menu.no() else True
|
||||
if choice.type_ == MenuSelectionType.Esc:
|
||||
return preset
|
||||
elif choice.type_ == MenuSelectionType.Selection:
|
||||
return False if choice.value == Menu.no() else True
|
||||
# match choice.type_:
|
||||
# case MenuSelectionType.Esc: return preset
|
||||
# case MenuSelectionType.Selection: return False if choice.value == Menu.no() else True
|
||||
if choice.type_ == MenuSelectionType.Esc:
|
||||
return preset
|
||||
elif choice.type_ == MenuSelectionType.Selection:
|
||||
return False if choice.value == Menu.no() else True
|
||||
|
||||
def all_lvmdrives(disk_layouts: Dict[str,Any] = None) -> List[Dict[str,Any]]:
|
||||
lvm_drives_dict = {}
|
||||
# print("device============>>>>",disk_layouts,disk_layouts)
|
||||
for disk in disk_layouts:
|
||||
device = disk_layouts[disk].get('device',None)
|
||||
# print("device============>>>>",disk_layouts,device)
|
||||
if device is None:
|
||||
continue
|
||||
if device['as_lvm']:
|
||||
# ´ÅÅÌÓÐ
|
||||
if lvm_drives_dict.get(device['vg_name'],None) is not None:
|
||||
lvm_drives_dict[device['vg_name']]['vg_size'] += device['vg_size']
|
||||
lvm_drives_dict[device['vg_name']]['pvs'].append(disk)
|
||||
else:
|
||||
lvm_drives_dict[device['vg_name']] = {
|
||||
'vg_name':device['vg_name'],
|
||||
'vg_size':device['vg_size'],
|
||||
'pvs':[disk]
|
||||
}
|
||||
if len(lvs:=device.get('partitions',[])) > 0:
|
||||
for lv in lvs:
|
||||
if lvm_drives_dict[device['vg_name']].get('partitions',None):
|
||||
lvm_drives_dict[device['vg_name']]['partitions'].append(lv)
|
||||
elif device['has_lvm'] and len(partitions := disk_layouts[disk].get('partitions',[])) > 0:
|
||||
# ·ÖÇøÓÐ
|
||||
for index,partition in enumerate(partitions):
|
||||
if (device := partition.get('device',None)) is not None and device.get('as_lvm',False):
|
||||
if lvm_drives_dict.get(device['vg_name'],None) is not None:
|
||||
lvm_drives_dict[device['vg_name']]['vg_size'] += device['vg_size']
|
||||
lvm_drives_dict[device['vg_name']]['pvs'].append(disk+str(index+1))
|
||||
else:
|
||||
lvm_drives_dict[device['vg_name']] = {
|
||||
'vg_name':device['vg_name'],
|
||||
'vg_size':device['vg_size'],
|
||||
'pvs':[disk+str(index+1)]
|
||||
}
|
||||
if (device := partition.get('device',None)) is not None and len(lvs:=device.get('partitions',[])) > 0:
|
||||
print("lvm_drives_dict=====>>>>>>",lvm_drives_dict)
|
||||
if lvm_drives_dict[device['vg_name']].get('partitions',None):
|
||||
lvm_drives_dict[device['vg_name']]['partitions'].extend(lvs)
|
||||
else:
|
||||
lvm_drives_dict[device['vg_name']]['partitions'] = lvs
|
||||
|
||||
return lvm_drives_dict.values()
|
||||
|
||||
def select_lvmdrives(preset: List[str] = [],disk_layouts: List[Dict[str,Any]] = []) -> List[str]:
|
||||
"""
|
||||
Asks the user to select one or multiple lvm drives
|
||||
|
||||
:return: List of selected hard drives
|
||||
:rtype: list
|
||||
"""
|
||||
hard_drives = all_lvmdrives(disk_layouts)
|
||||
# print("lvm_drives=333=======>>>",hard_drives)
|
||||
# hard_drives = all_blockdevices(partitions=False).values()
|
||||
options = {f'{option}': option for option in hard_drives}
|
||||
|
||||
options_keys = list(options.keys())
|
||||
|
||||
if preset is not None:
|
||||
preset_selection = [str(v) for v in preset]
|
||||
else:
|
||||
preset_selection = []
|
||||
|
||||
title = str(_('Select one or more lvm drives to use and configure\n'))
|
||||
title += str(_('Any modifications to the existing setting will reset the disk layout!'))
|
||||
|
||||
warning = str(_('If you reset the harddrive selection this will also reset the current disk layout. Are you sure?'))
|
||||
|
||||
selected_harddrive = Menu(
|
||||
title,
|
||||
options_keys,
|
||||
preset_values=preset_selection,
|
||||
multi=True,
|
||||
raise_error_on_interrupt=True,
|
||||
raise_error_warning_msg=warning
|
||||
).run()
|
||||
|
||||
# match selected_harddrive.type_:
|
||||
# case MenuSelectionType.Ctrl_c: return []
|
||||
# case MenuSelectionType.Esc: return preset
|
||||
# case MenuSelectionType.Selection: return [options[i] for i in selected_harddrive.value]
|
||||
if selected_harddrive.type_ == MenuSelectionType.Esc:
|
||||
return preset
|
||||
elif selected_harddrive.type_ == MenuSelectionType.Ctrl_c:
|
||||
return []
|
||||
elif selected_harddrive.type_ == MenuSelectionType.Selection:
|
||||
return [options[i] for i in selected_harddrive.value]
|
Loading…
Reference in New Issue
Block a user