Refactor ModificationStatus (#4422)
* Use UPPER_CASE for ModificationStatus member names * Use StrEnum for ModificationStatus * Replace LvmVolumeStatus with ModificationStatus
This commit is contained in:
parent
a52bfc3446
commit
2b27e565ae
|
|
@ -342,7 +342,7 @@ class DeviceHandler:
|
||||||
) -> None:
|
) -> None:
|
||||||
# when we require a delete and the partition to be (re)created
|
# when we require a delete and the partition to be (re)created
|
||||||
# already exists then we have to delete it first
|
# already exists then we have to delete it first
|
||||||
if requires_delete and part_mod.status in [ModificationStatus.Modify, ModificationStatus.Delete]:
|
if requires_delete and part_mod.status in [ModificationStatus.MODIFY, ModificationStatus.DELETE]:
|
||||||
info(f'Delete existing partition: {part_mod.safe_dev_path}')
|
info(f'Delete existing partition: {part_mod.safe_dev_path}')
|
||||||
part_info = self.find_partition(part_mod.safe_dev_path)
|
part_info = self.find_partition(part_mod.safe_dev_path)
|
||||||
|
|
||||||
|
|
@ -351,7 +351,7 @@ class DeviceHandler:
|
||||||
|
|
||||||
disk.deletePartition(part_info.partition)
|
disk.deletePartition(part_info.partition)
|
||||||
|
|
||||||
if part_mod.status == ModificationStatus.Delete:
|
if part_mod.status == ModificationStatus.DELETE:
|
||||||
return
|
return
|
||||||
|
|
||||||
start_sector = part_mod.start.convert(
|
start_sector = part_mod.start.convert(
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ from archinstall.lib.models.device import (
|
||||||
LvmLayoutType,
|
LvmLayoutType,
|
||||||
LvmVolume,
|
LvmVolume,
|
||||||
LvmVolumeGroup,
|
LvmVolumeGroup,
|
||||||
LvmVolumeStatus,
|
|
||||||
ModificationStatus,
|
ModificationStatus,
|
||||||
PartitionFlag,
|
PartitionFlag,
|
||||||
PartitionModification,
|
PartitionModification,
|
||||||
|
|
@ -503,7 +502,7 @@ def _boot_partition(sector_size: SectorSize, using_gpt: bool) -> PartitionModifi
|
||||||
|
|
||||||
# boot partition
|
# boot partition
|
||||||
return PartitionModification(
|
return PartitionModification(
|
||||||
status=ModificationStatus.Create,
|
status=ModificationStatus.CREATE,
|
||||||
type=PartitionType.Primary,
|
type=PartitionType.Primary,
|
||||||
start=start,
|
start=start,
|
||||||
length=size,
|
length=size,
|
||||||
|
|
@ -655,7 +654,7 @@ async def suggest_single_disk_layout(
|
||||||
root_length = available_space - root_start
|
root_length = available_space - root_start
|
||||||
|
|
||||||
root_partition = PartitionModification(
|
root_partition = PartitionModification(
|
||||||
status=ModificationStatus.Create,
|
status=ModificationStatus.CREATE,
|
||||||
type=PartitionType.Primary,
|
type=PartitionType.Primary,
|
||||||
start=root_start,
|
start=root_start,
|
||||||
length=root_length,
|
length=root_length,
|
||||||
|
|
@ -680,7 +679,7 @@ async def suggest_single_disk_layout(
|
||||||
flags.append(PartitionFlag.LINUX_HOME)
|
flags.append(PartitionFlag.LINUX_HOME)
|
||||||
|
|
||||||
home_partition = PartitionModification(
|
home_partition = PartitionModification(
|
||||||
status=ModificationStatus.Create,
|
status=ModificationStatus.CREATE,
|
||||||
type=PartitionType.Primary,
|
type=PartitionType.Primary,
|
||||||
start=home_start,
|
start=home_start,
|
||||||
length=home_length,
|
length=home_length,
|
||||||
|
|
@ -765,7 +764,7 @@ async def suggest_multi_disk_layout(
|
||||||
|
|
||||||
# add root partition to the root device
|
# add root partition to the root device
|
||||||
root_partition = PartitionModification(
|
root_partition = PartitionModification(
|
||||||
status=ModificationStatus.Create,
|
status=ModificationStatus.CREATE,
|
||||||
type=PartitionType.Primary,
|
type=PartitionType.Primary,
|
||||||
start=root_start,
|
start=root_start,
|
||||||
length=root_length,
|
length=root_length,
|
||||||
|
|
@ -787,7 +786,7 @@ async def suggest_multi_disk_layout(
|
||||||
|
|
||||||
# add home partition to home device
|
# add home partition to home device
|
||||||
home_partition = PartitionModification(
|
home_partition = PartitionModification(
|
||||||
status=ModificationStatus.Create,
|
status=ModificationStatus.CREATE,
|
||||||
type=PartitionType.Primary,
|
type=PartitionType.Primary,
|
||||||
start=home_start,
|
start=home_start,
|
||||||
length=home_length,
|
length=home_length,
|
||||||
|
|
@ -851,7 +850,7 @@ async def suggest_lvm_layout(
|
||||||
lvm_vol_group = LvmVolumeGroup(vg_grp_name, pvs=other_part)
|
lvm_vol_group = LvmVolumeGroup(vg_grp_name, pvs=other_part)
|
||||||
|
|
||||||
root_vol = LvmVolume(
|
root_vol = LvmVolume(
|
||||||
status=LvmVolumeStatus.Create,
|
status=ModificationStatus.CREATE,
|
||||||
name='root',
|
name='root',
|
||||||
fs_type=filesystem_type,
|
fs_type=filesystem_type,
|
||||||
length=root_vol_size,
|
length=root_vol_size,
|
||||||
|
|
@ -864,7 +863,7 @@ async def suggest_lvm_layout(
|
||||||
|
|
||||||
if home_volume:
|
if home_volume:
|
||||||
home_vol = LvmVolume(
|
home_vol = LvmVolume(
|
||||||
status=LvmVolumeStatus.Create,
|
status=ModificationStatus.CREATE,
|
||||||
name='home',
|
name='home',
|
||||||
fs_type=filesystem_type,
|
fs_type=filesystem_type,
|
||||||
length=home_vol_size,
|
length=home_vol_size,
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ class DiskSegment:
|
||||||
return self.segment.table_data()
|
return self.segment.table_data()
|
||||||
|
|
||||||
part_mod = PartitionModification(
|
part_mod = PartitionModification(
|
||||||
status=ModificationStatus.Create,
|
status=ModificationStatus.CREATE,
|
||||||
type=PartitionType._Unknown,
|
type=PartitionType._Unknown,
|
||||||
start=self.segment.start,
|
start=self.segment.start,
|
||||||
length=self.segment.length,
|
length=self.segment.length,
|
||||||
|
|
@ -209,7 +209,7 @@ class PartitioningList(ListManager[DiskSegment]):
|
||||||
@override
|
@override
|
||||||
def selected_action_display(self, selection: DiskSegment) -> str:
|
def selected_action_display(self, selection: DiskSegment) -> str:
|
||||||
if isinstance(selection.segment, PartitionModification):
|
if isinstance(selection.segment, PartitionModification):
|
||||||
if selection.segment.status == ModificationStatus.Create:
|
if selection.segment.status == ModificationStatus.CREATE:
|
||||||
return tr('Partition - New')
|
return tr('Partition - New')
|
||||||
elif selection.segment.is_delete() and selection.segment.dev_path:
|
elif selection.segment.is_delete() and selection.segment.dev_path:
|
||||||
title = tr('Partition') + '\n\n'
|
title = tr('Partition') + '\n\n'
|
||||||
|
|
@ -357,7 +357,7 @@ class PartitioningList(ListManager[DiskSegment]):
|
||||||
data: list[DiskSegment],
|
data: list[DiskSegment],
|
||||||
) -> list[DiskSegment]:
|
) -> list[DiskSegment]:
|
||||||
if entry.is_exists_or_modify():
|
if entry.is_exists_or_modify():
|
||||||
entry.status = ModificationStatus.Delete
|
entry.status = ModificationStatus.DELETE
|
||||||
part_mods = self.get_part_mods(data)
|
part_mods = self.get_part_mods(data)
|
||||||
else:
|
else:
|
||||||
part_mods = [d.segment for d in data if isinstance(d.segment, PartitionModification) and d.segment != entry]
|
part_mods = [d.segment for d in data if isinstance(d.segment, PartitionModification) and d.segment != entry]
|
||||||
|
|
@ -391,10 +391,10 @@ class PartitioningList(ListManager[DiskSegment]):
|
||||||
async def _prompt_formatting(self, partition: PartitionModification) -> None:
|
async def _prompt_formatting(self, partition: PartitionModification) -> None:
|
||||||
# an existing partition can toggle between Exist or Modify
|
# an existing partition can toggle between Exist or Modify
|
||||||
if partition.is_modify():
|
if partition.is_modify():
|
||||||
partition.status = ModificationStatus.Exist
|
partition.status = ModificationStatus.EXIST
|
||||||
return
|
return
|
||||||
elif partition.exists():
|
elif partition.exists():
|
||||||
partition.status = ModificationStatus.Modify
|
partition.status = ModificationStatus.MODIFY
|
||||||
|
|
||||||
# If we mark a partition for formatting, but the format is CRYPTO LUKS, there's no point in formatting it really
|
# If we mark a partition for formatting, but the format is CRYPTO LUKS, there's no point in formatting it really
|
||||||
# without asking the user which inner-filesystem they want to use. Since the flag 'encrypted' = True is already set,
|
# without asking the user which inner-filesystem they want to use. Since the flag 'encrypted' = True is already set,
|
||||||
|
|
@ -526,7 +526,7 @@ class PartitioningList(ListManager[DiskSegment]):
|
||||||
mountpoint = await self._prompt_mountpoint()
|
mountpoint = await self._prompt_mountpoint()
|
||||||
|
|
||||||
partition = PartitionModification(
|
partition = PartitionModification(
|
||||||
status=ModificationStatus.Create,
|
status=ModificationStatus.CREATE,
|
||||||
type=PartitionType.Primary,
|
type=PartitionType.Primary,
|
||||||
start=free_space.start,
|
start=free_space.start,
|
||||||
length=length,
|
length=length,
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ from archinstall.lib.models.device import (
|
||||||
LvmLayoutType,
|
LvmLayoutType,
|
||||||
LvmVolume,
|
LvmVolume,
|
||||||
LvmVolumeGroup,
|
LvmVolumeGroup,
|
||||||
LvmVolumeStatus,
|
|
||||||
ModificationStatus,
|
ModificationStatus,
|
||||||
PartitionFlag,
|
PartitionFlag,
|
||||||
PartitionModification,
|
PartitionModification,
|
||||||
|
|
@ -57,7 +56,6 @@ __all__ = [
|
||||||
'LvmLayoutType',
|
'LvmLayoutType',
|
||||||
'LvmVolume',
|
'LvmVolume',
|
||||||
'LvmVolumeGroup',
|
'LvmVolumeGroup',
|
||||||
'LvmVolumeStatus',
|
|
||||||
'MirrorConfiguration',
|
'MirrorConfiguration',
|
||||||
'MirrorRegion',
|
'MirrorRegion',
|
||||||
'ModificationStatus',
|
'ModificationStatus',
|
||||||
|
|
|
||||||
|
|
@ -164,15 +164,15 @@ class DiskLayoutConfiguration:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
first = non_delete_partitions[0]
|
first = non_delete_partitions[0]
|
||||||
if first.status == ModificationStatus.Create and not first.start.is_valid_start():
|
if first.status == ModificationStatus.CREATE and not first.start.is_valid_start():
|
||||||
raise ValueError('First partition must start at no less than 1 MiB')
|
raise ValueError('First partition must start at no less than 1 MiB')
|
||||||
|
|
||||||
for i, current_partition in enumerate(non_delete_partitions[1:], start=1):
|
for i, current_partition in enumerate(non_delete_partitions[1:], start=1):
|
||||||
previous_partition = non_delete_partitions[i - 1]
|
previous_partition = non_delete_partitions[i - 1]
|
||||||
if current_partition.status == ModificationStatus.Create and current_partition.start < previous_partition.end:
|
if current_partition.status == ModificationStatus.CREATE and current_partition.start < previous_partition.end:
|
||||||
raise ValueError('Partitions overlap')
|
raise ValueError('Partitions overlap')
|
||||||
|
|
||||||
create_partitions = [part_mod for part_mod in non_delete_partitions if part_mod.status == ModificationStatus.Create]
|
create_partitions = [part_mod for part_mod in non_delete_partitions if part_mod.status == ModificationStatus.CREATE]
|
||||||
|
|
||||||
if not create_partitions:
|
if not create_partitions:
|
||||||
continue
|
continue
|
||||||
|
|
@ -819,11 +819,11 @@ class FilesystemType(StrEnum):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class ModificationStatus(Enum):
|
class ModificationStatus(StrEnum):
|
||||||
Exist = 'existing'
|
EXIST = 'existing'
|
||||||
Modify = 'modify'
|
MODIFY = auto()
|
||||||
Delete = 'delete'
|
DELETE = auto()
|
||||||
Create = 'create'
|
CREATE = auto()
|
||||||
|
|
||||||
|
|
||||||
class _PartitionModificationSerialization(TypedDict):
|
class _PartitionModificationSerialization(TypedDict):
|
||||||
|
|
@ -868,7 +868,7 @@ class PartitionModification:
|
||||||
if self.is_exists_or_modify() and not self.dev_path:
|
if self.is_exists_or_modify() and not self.dev_path:
|
||||||
raise ValueError('If partition marked as existing a path must be set')
|
raise ValueError('If partition marked as existing a path must be set')
|
||||||
|
|
||||||
if self.fs_type is None and self.status == ModificationStatus.Modify:
|
if self.fs_type is None and self.status == ModificationStatus.MODIFY:
|
||||||
raise ValueError('FS type must not be empty on modifications with status type modify')
|
raise ValueError('FS type must not be empty on modifications with status type modify')
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -911,7 +911,7 @@ class PartitionModification:
|
||||||
subvol_mods = []
|
subvol_mods = []
|
||||||
|
|
||||||
return cls(
|
return cls(
|
||||||
status=ModificationStatus.Exist,
|
status=ModificationStatus.EXIST,
|
||||||
type=partition_info.type,
|
type=partition_info.type,
|
||||||
start=partition_info.start,
|
start=partition_info.start,
|
||||||
length=partition_info.length,
|
length=partition_info.length,
|
||||||
|
|
@ -961,23 +961,23 @@ class PartitionModification:
|
||||||
return self.fs_type == FilesystemType.LINUX_SWAP
|
return self.fs_type == FilesystemType.LINUX_SWAP
|
||||||
|
|
||||||
def is_modify(self) -> bool:
|
def is_modify(self) -> bool:
|
||||||
return self.status == ModificationStatus.Modify
|
return self.status == ModificationStatus.MODIFY
|
||||||
|
|
||||||
def is_delete(self) -> bool:
|
def is_delete(self) -> bool:
|
||||||
return self.status == ModificationStatus.Delete
|
return self.status == ModificationStatus.DELETE
|
||||||
|
|
||||||
def exists(self) -> bool:
|
def exists(self) -> bool:
|
||||||
return self.status == ModificationStatus.Exist
|
return self.status == ModificationStatus.EXIST
|
||||||
|
|
||||||
def is_exists_or_modify(self) -> bool:
|
def is_exists_or_modify(self) -> bool:
|
||||||
return self.status in [
|
return self.status in [
|
||||||
ModificationStatus.Exist,
|
ModificationStatus.EXIST,
|
||||||
ModificationStatus.Delete,
|
ModificationStatus.DELETE,
|
||||||
ModificationStatus.Modify,
|
ModificationStatus.MODIFY,
|
||||||
]
|
]
|
||||||
|
|
||||||
def is_create_or_modify(self) -> bool:
|
def is_create_or_modify(self) -> bool:
|
||||||
return self.status in [ModificationStatus.Create, ModificationStatus.Modify]
|
return self.status in [ModificationStatus.CREATE, ModificationStatus.MODIFY]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def mapper_name(self) -> str | None:
|
def mapper_name(self) -> str | None:
|
||||||
|
|
@ -1088,13 +1088,6 @@ class LvmVolumeGroup:
|
||||||
return lv in self.volumes
|
return lv in self.volumes
|
||||||
|
|
||||||
|
|
||||||
class LvmVolumeStatus(Enum):
|
|
||||||
Exist = 'existing'
|
|
||||||
Modify = 'modify'
|
|
||||||
Delete = 'delete'
|
|
||||||
Create = 'create'
|
|
||||||
|
|
||||||
|
|
||||||
class _LvmVolumeSerialization(TypedDict):
|
class _LvmVolumeSerialization(TypedDict):
|
||||||
obj_id: str
|
obj_id: str
|
||||||
status: str
|
status: str
|
||||||
|
|
@ -1108,7 +1101,7 @@ class _LvmVolumeSerialization(TypedDict):
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class LvmVolume:
|
class LvmVolume:
|
||||||
status: LvmVolumeStatus
|
status: ModificationStatus
|
||||||
name: str
|
name: str
|
||||||
fs_type: FilesystemType
|
fs_type: FilesystemType
|
||||||
length: Size
|
length: Size
|
||||||
|
|
@ -1177,7 +1170,7 @@ class LvmVolume:
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_arg(cls, arg: _LvmVolumeSerialization) -> Self:
|
def parse_arg(cls, arg: _LvmVolumeSerialization) -> Self:
|
||||||
volume = cls(
|
volume = cls(
|
||||||
status=LvmVolumeStatus(arg['status']),
|
status=ModificationStatus(arg['status']),
|
||||||
name=arg['name'],
|
name=arg['name'],
|
||||||
fs_type=FilesystemType(arg['fs_type']),
|
fs_type=FilesystemType(arg['fs_type']),
|
||||||
length=Size.parse_args(arg['length']),
|
length=Size.parse_args(arg['length']),
|
||||||
|
|
@ -1215,13 +1208,13 @@ class LvmVolume:
|
||||||
return part_mod
|
return part_mod
|
||||||
|
|
||||||
def is_modify(self) -> bool:
|
def is_modify(self) -> bool:
|
||||||
return self.status == LvmVolumeStatus.Modify
|
return self.status == ModificationStatus.MODIFY
|
||||||
|
|
||||||
def exists(self) -> bool:
|
def exists(self) -> bool:
|
||||||
return self.status == LvmVolumeStatus.Exist
|
return self.status == ModificationStatus.EXIST
|
||||||
|
|
||||||
def is_exists_or_modify(self) -> bool:
|
def is_exists_or_modify(self) -> bool:
|
||||||
return self.status in [LvmVolumeStatus.Exist, LvmVolumeStatus.Modify]
|
return self.status in [ModificationStatus.EXIST, ModificationStatus.MODIFY]
|
||||||
|
|
||||||
def is_root(self) -> bool:
|
def is_root(self) -> bool:
|
||||||
if self.mountpoint is not None:
|
if self.mountpoint is not None:
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ device_modification = DeviceModification(device, wipe=True)
|
||||||
|
|
||||||
# create a new boot partition
|
# create a new boot partition
|
||||||
boot_partition = PartitionModification(
|
boot_partition = PartitionModification(
|
||||||
status=ModificationStatus.Create,
|
status=ModificationStatus.CREATE,
|
||||||
type=PartitionType.Primary,
|
type=PartitionType.Primary,
|
||||||
start=Size(1, Unit.MiB, device.device_info.sector_size),
|
start=Size(1, Unit.MiB, device.device_info.sector_size),
|
||||||
length=Size(512, Unit.MiB, device.device_info.sector_size),
|
length=Size(512, Unit.MiB, device.device_info.sector_size),
|
||||||
|
|
@ -49,7 +49,7 @@ device_modification.add_partition(boot_partition)
|
||||||
|
|
||||||
# create a root partition
|
# create a root partition
|
||||||
root_partition = PartitionModification(
|
root_partition = PartitionModification(
|
||||||
status=ModificationStatus.Create,
|
status=ModificationStatus.CREATE,
|
||||||
type=PartitionType.Primary,
|
type=PartitionType.Primary,
|
||||||
start=Size(513, Unit.MiB, device.device_info.sector_size),
|
start=Size(513, Unit.MiB, device.device_info.sector_size),
|
||||||
length=Size(20, Unit.GiB, device.device_info.sector_size),
|
length=Size(20, Unit.GiB, device.device_info.sector_size),
|
||||||
|
|
@ -64,7 +64,7 @@ length_home = device.device_info.total_size - start_home
|
||||||
|
|
||||||
# create a new home partition
|
# create a new home partition
|
||||||
home_partition = PartitionModification(
|
home_partition = PartitionModification(
|
||||||
status=ModificationStatus.Create,
|
status=ModificationStatus.CREATE,
|
||||||
type=PartitionType.Primary,
|
type=PartitionType.Primary,
|
||||||
start=start_home,
|
start=start_home,
|
||||||
length=length_home,
|
length=length_home,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue