Fix manual partitioning device wipe status (#3198)
This commit is contained in:
parent
4b07f8a3ae
commit
4a477351e0
|
|
@ -5,12 +5,13 @@ from pathlib import Path
|
||||||
from typing import TYPE_CHECKING, override
|
from typing import TYPE_CHECKING, override
|
||||||
|
|
||||||
from archinstall.lib.models.device_model import (
|
from archinstall.lib.models.device_model import (
|
||||||
BDevice,
|
|
||||||
BtrfsMountOption,
|
BtrfsMountOption,
|
||||||
|
DeviceModification,
|
||||||
FilesystemType,
|
FilesystemType,
|
||||||
ModificationStatus,
|
ModificationStatus,
|
||||||
PartitionFlag,
|
PartitionFlag,
|
||||||
PartitionModification,
|
PartitionModification,
|
||||||
|
PartitionTable,
|
||||||
PartitionType,
|
PartitionType,
|
||||||
SectorSize,
|
SectorSize,
|
||||||
Size,
|
Size,
|
||||||
|
|
@ -18,7 +19,6 @@ from archinstall.lib.models.device_model import (
|
||||||
)
|
)
|
||||||
from archinstall.tui import Alignment, EditMenu, FrameProperties, MenuItem, MenuItemGroup, Orientation, ResultType, SelectMenu
|
from archinstall.tui import Alignment, EditMenu, FrameProperties, MenuItem, MenuItemGroup, Orientation, ResultType, SelectMenu
|
||||||
|
|
||||||
from ..hardware import SysInfo
|
|
||||||
from ..menu import ListManager
|
from ..menu import ListManager
|
||||||
from ..output import FormattedOutput
|
from ..output import FormattedOutput
|
||||||
from ..utils.util import prompt_dir
|
from ..utils.util import prompt_dir
|
||||||
|
|
@ -75,10 +75,17 @@ class DiskSegment:
|
||||||
|
|
||||||
|
|
||||||
class PartitioningList(ListManager):
|
class PartitioningList(ListManager):
|
||||||
def __init__(self, prompt: str, device: BDevice, device_partitions: list[PartitionModification]):
|
def __init__(
|
||||||
|
self,
|
||||||
|
device_mod: DeviceModification,
|
||||||
|
partition_table: PartitionTable
|
||||||
|
) -> None:
|
||||||
|
device = device_mod.device
|
||||||
|
|
||||||
self._device = device
|
self._device = device
|
||||||
|
self._wipe = device_mod.wipe
|
||||||
self._buffer = Size(1, Unit.MiB, device.device_info.sector_size)
|
self._buffer = Size(1, Unit.MiB, device.device_info.sector_size)
|
||||||
self._using_gpt = SysInfo.has_uefi()
|
self._using_gpt = device_mod.using_gpt(partition_table)
|
||||||
|
|
||||||
self._actions = {
|
self._actions = {
|
||||||
'suggest_partition_layout': str(_('Suggest partition layout')),
|
'suggest_partition_layout': str(_('Suggest partition layout')),
|
||||||
|
|
@ -93,14 +100,32 @@ class PartitioningList(ListManager):
|
||||||
'delete_partition': str(_('Delete partition'))
|
'delete_partition': str(_('Delete partition'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
device_partitions = []
|
||||||
|
|
||||||
|
if not device_mod.partitions:
|
||||||
|
# we'll display the existing partitions of the device
|
||||||
|
for partition in device.partition_infos:
|
||||||
|
device_partitions.append(
|
||||||
|
PartitionModification.from_existing_partition(partition)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
device_partitions = device_mod.partitions
|
||||||
|
|
||||||
|
prompt = str(_('Partition management: {}')).format(device.device_info.path) + '\n'
|
||||||
|
prompt += str(_('Total length: {}')).format(device.device_info.total_size.format_size(Unit.MiB))
|
||||||
|
self._info = prompt + '\n'
|
||||||
|
|
||||||
display_actions = list(self._actions.values())
|
display_actions = list(self._actions.values())
|
||||||
super().__init__(
|
super().__init__(
|
||||||
self.as_segments(device_partitions),
|
self.as_segments(device_partitions),
|
||||||
display_actions[:1],
|
display_actions[:1],
|
||||||
display_actions[2:],
|
display_actions[2:],
|
||||||
prompt
|
self._info + self.wipe_str()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def wipe_str(self) -> str:
|
||||||
|
return '{}: {}'.format(str(_('Wipe')), self._wipe)
|
||||||
|
|
||||||
def as_segments(self, device_partitions: list[PartitionModification]) -> list[DiskSegment]:
|
def as_segments(self, device_partitions: list[PartitionModification]) -> list[DiskSegment]:
|
||||||
end = self._device.device_info.total_size
|
end = self._device.device_info.total_size
|
||||||
|
|
||||||
|
|
@ -163,10 +188,10 @@ class PartitioningList(ListManager):
|
||||||
if isinstance(s.segment, PartitionModification)
|
if isinstance(s.segment, PartitionModification)
|
||||||
]
|
]
|
||||||
|
|
||||||
@override
|
def get_device_mod(self) -> DeviceModification:
|
||||||
def run(self) -> list[PartitionModification]:
|
|
||||||
disk_segments = super().run()
|
disk_segments = super().run()
|
||||||
return self.get_part_mods(disk_segments)
|
partitions = self.get_part_mods(disk_segments)
|
||||||
|
return DeviceModification(self._device, self._wipe, partitions)
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def _run_actions_on_entry(self, entry: DiskSegment) -> None:
|
def _run_actions_on_entry(self, entry: DiskSegment) -> None:
|
||||||
|
|
@ -241,9 +266,11 @@ class PartitioningList(ListManager):
|
||||||
match action_key:
|
match action_key:
|
||||||
case 'suggest_partition_layout':
|
case 'suggest_partition_layout':
|
||||||
part_mods = self.get_part_mods(data)
|
part_mods = self.get_part_mods(data)
|
||||||
new_partitions = self._suggest_partition_layout(part_mods)
|
device_mod = self._suggest_partition_layout(part_mods)
|
||||||
if len(new_partitions) > 0:
|
if device_mod and device_mod.partitions:
|
||||||
data = self.as_segments(new_partitions)
|
data = self.as_segments(device_mod.partitions)
|
||||||
|
self._wipe = device_mod.wipe
|
||||||
|
self._prompt = self._info + self.wipe_str()
|
||||||
case 'remove_added_partitions':
|
case 'remove_added_partitions':
|
||||||
if self._reset_confirmation():
|
if self._reset_confirmation():
|
||||||
data = [
|
data = [
|
||||||
|
|
@ -506,43 +533,32 @@ class PartitioningList(ListManager):
|
||||||
|
|
||||||
return result.item() == MenuItem.yes()
|
return result.item() == MenuItem.yes()
|
||||||
|
|
||||||
def _suggest_partition_layout(self, data: list[PartitionModification]) -> list[PartitionModification]:
|
def _suggest_partition_layout(
|
||||||
|
self,
|
||||||
|
data: list[PartitionModification]
|
||||||
|
) -> DeviceModification | None:
|
||||||
# if modifications have been done already, inform the user
|
# if modifications have been done already, inform the user
|
||||||
# that this operation will erase those modifications
|
# that this operation will erase those modifications
|
||||||
if any([not entry.exists() for entry in data]):
|
if any([not entry.exists() for entry in data]):
|
||||||
if not self._reset_confirmation():
|
if not self._reset_confirmation():
|
||||||
return []
|
return None
|
||||||
|
|
||||||
from ..interactions.disk_conf import suggest_single_disk_layout
|
from ..interactions.disk_conf import suggest_single_disk_layout
|
||||||
|
|
||||||
device_modification = suggest_single_disk_layout(self._device)
|
return suggest_single_disk_layout(self._device)
|
||||||
return device_modification.partitions
|
|
||||||
|
|
||||||
|
|
||||||
def manual_partitioning(
|
def manual_partitioning(
|
||||||
device: BDevice,
|
device_mod: DeviceModification,
|
||||||
prompt: str = '',
|
partition_table: PartitionTable
|
||||||
preset: list[PartitionModification] = []
|
) -> DeviceModification | None:
|
||||||
) -> list[PartitionModification]:
|
menu_list = PartitioningList(device_mod, partition_table)
|
||||||
if not prompt:
|
mod = menu_list.get_device_mod()
|
||||||
prompt = str(_('Partition management: {}')).format(device.device_info.path) + '\n'
|
|
||||||
prompt += str(_('Total length: {}')).format(device.device_info.total_size.format_size(Unit.MiB))
|
|
||||||
|
|
||||||
manual_preset = []
|
|
||||||
|
|
||||||
if not preset:
|
|
||||||
# we'll display the existing partitions of the device
|
|
||||||
for partition in device.partition_infos:
|
|
||||||
manual_preset.append(
|
|
||||||
PartitionModification.from_existing_partition(partition)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
manual_preset = preset
|
|
||||||
|
|
||||||
menu_list = PartitioningList(prompt, device, manual_preset)
|
|
||||||
partitions: list[PartitionModification] = menu_list.run()
|
|
||||||
|
|
||||||
if menu_list.is_last_choice_cancel():
|
if menu_list.is_last_choice_cancel():
|
||||||
return preset
|
return device_mod
|
||||||
|
|
||||||
return partitions
|
if mod.partitions:
|
||||||
|
return mod
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
|
||||||
|
|
@ -116,9 +116,8 @@ def _manual_partitioning(
|
||||||
if not mod:
|
if not mod:
|
||||||
mod = DeviceModification(device, wipe=False)
|
mod = DeviceModification(device, wipe=False)
|
||||||
|
|
||||||
if partitions := manual_partitioning(device, preset=mod.partitions):
|
if device_mod := manual_partitioning(mod, device_handler.partition_table):
|
||||||
mod.partitions = partitions
|
modifications.append(device_mod)
|
||||||
modifications.append(mod)
|
|
||||||
|
|
||||||
return modifications
|
return modifications
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue