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:
|
||||
# when we require a delete and the partition to be (re)created
|
||||
# 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}')
|
||||
part_info = self.find_partition(part_mod.safe_dev_path)
|
||||
|
||||
|
|
@ -351,7 +351,7 @@ class DeviceHandler:
|
|||
|
||||
disk.deletePartition(part_info.partition)
|
||||
|
||||
if part_mod.status == ModificationStatus.Delete:
|
||||
if part_mod.status == ModificationStatus.DELETE:
|
||||
return
|
||||
|
||||
start_sector = part_mod.start.convert(
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ from archinstall.lib.models.device import (
|
|||
LvmLayoutType,
|
||||
LvmVolume,
|
||||
LvmVolumeGroup,
|
||||
LvmVolumeStatus,
|
||||
ModificationStatus,
|
||||
PartitionFlag,
|
||||
PartitionModification,
|
||||
|
|
@ -503,7 +502,7 @@ def _boot_partition(sector_size: SectorSize, using_gpt: bool) -> PartitionModifi
|
|||
|
||||
# boot partition
|
||||
return PartitionModification(
|
||||
status=ModificationStatus.Create,
|
||||
status=ModificationStatus.CREATE,
|
||||
type=PartitionType.Primary,
|
||||
start=start,
|
||||
length=size,
|
||||
|
|
@ -655,7 +654,7 @@ async def suggest_single_disk_layout(
|
|||
root_length = available_space - root_start
|
||||
|
||||
root_partition = PartitionModification(
|
||||
status=ModificationStatus.Create,
|
||||
status=ModificationStatus.CREATE,
|
||||
type=PartitionType.Primary,
|
||||
start=root_start,
|
||||
length=root_length,
|
||||
|
|
@ -680,7 +679,7 @@ async def suggest_single_disk_layout(
|
|||
flags.append(PartitionFlag.LINUX_HOME)
|
||||
|
||||
home_partition = PartitionModification(
|
||||
status=ModificationStatus.Create,
|
||||
status=ModificationStatus.CREATE,
|
||||
type=PartitionType.Primary,
|
||||
start=home_start,
|
||||
length=home_length,
|
||||
|
|
@ -765,7 +764,7 @@ async def suggest_multi_disk_layout(
|
|||
|
||||
# add root partition to the root device
|
||||
root_partition = PartitionModification(
|
||||
status=ModificationStatus.Create,
|
||||
status=ModificationStatus.CREATE,
|
||||
type=PartitionType.Primary,
|
||||
start=root_start,
|
||||
length=root_length,
|
||||
|
|
@ -787,7 +786,7 @@ async def suggest_multi_disk_layout(
|
|||
|
||||
# add home partition to home device
|
||||
home_partition = PartitionModification(
|
||||
status=ModificationStatus.Create,
|
||||
status=ModificationStatus.CREATE,
|
||||
type=PartitionType.Primary,
|
||||
start=home_start,
|
||||
length=home_length,
|
||||
|
|
@ -851,7 +850,7 @@ async def suggest_lvm_layout(
|
|||
lvm_vol_group = LvmVolumeGroup(vg_grp_name, pvs=other_part)
|
||||
|
||||
root_vol = LvmVolume(
|
||||
status=LvmVolumeStatus.Create,
|
||||
status=ModificationStatus.CREATE,
|
||||
name='root',
|
||||
fs_type=filesystem_type,
|
||||
length=root_vol_size,
|
||||
|
|
@ -864,7 +863,7 @@ async def suggest_lvm_layout(
|
|||
|
||||
if home_volume:
|
||||
home_vol = LvmVolume(
|
||||
status=LvmVolumeStatus.Create,
|
||||
status=ModificationStatus.CREATE,
|
||||
name='home',
|
||||
fs_type=filesystem_type,
|
||||
length=home_vol_size,
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class DiskSegment:
|
|||
return self.segment.table_data()
|
||||
|
||||
part_mod = PartitionModification(
|
||||
status=ModificationStatus.Create,
|
||||
status=ModificationStatus.CREATE,
|
||||
type=PartitionType._Unknown,
|
||||
start=self.segment.start,
|
||||
length=self.segment.length,
|
||||
|
|
@ -209,7 +209,7 @@ class PartitioningList(ListManager[DiskSegment]):
|
|||
@override
|
||||
def selected_action_display(self, selection: DiskSegment) -> str:
|
||||
if isinstance(selection.segment, PartitionModification):
|
||||
if selection.segment.status == ModificationStatus.Create:
|
||||
if selection.segment.status == ModificationStatus.CREATE:
|
||||
return tr('Partition - New')
|
||||
elif selection.segment.is_delete() and selection.segment.dev_path:
|
||||
title = tr('Partition') + '\n\n'
|
||||
|
|
@ -357,7 +357,7 @@ class PartitioningList(ListManager[DiskSegment]):
|
|||
data: list[DiskSegment],
|
||||
) -> list[DiskSegment]:
|
||||
if entry.is_exists_or_modify():
|
||||
entry.status = ModificationStatus.Delete
|
||||
entry.status = ModificationStatus.DELETE
|
||||
part_mods = self.get_part_mods(data)
|
||||
else:
|
||||
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:
|
||||
# an existing partition can toggle between Exist or Modify
|
||||
if partition.is_modify():
|
||||
partition.status = ModificationStatus.Exist
|
||||
partition.status = ModificationStatus.EXIST
|
||||
return
|
||||
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
|
||||
# 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()
|
||||
|
||||
partition = PartitionModification(
|
||||
status=ModificationStatus.Create,
|
||||
status=ModificationStatus.CREATE,
|
||||
type=PartitionType.Primary,
|
||||
start=free_space.start,
|
||||
length=length,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ from archinstall.lib.models.device import (
|
|||
LvmLayoutType,
|
||||
LvmVolume,
|
||||
LvmVolumeGroup,
|
||||
LvmVolumeStatus,
|
||||
ModificationStatus,
|
||||
PartitionFlag,
|
||||
PartitionModification,
|
||||
|
|
@ -57,7 +56,6 @@ __all__ = [
|
|||
'LvmLayoutType',
|
||||
'LvmVolume',
|
||||
'LvmVolumeGroup',
|
||||
'LvmVolumeStatus',
|
||||
'MirrorConfiguration',
|
||||
'MirrorRegion',
|
||||
'ModificationStatus',
|
||||
|
|
|
|||
|
|
@ -164,15 +164,15 @@ class DiskLayoutConfiguration:
|
|||
continue
|
||||
|
||||
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')
|
||||
|
||||
for i, current_partition in enumerate(non_delete_partitions[1:], start=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')
|
||||
|
||||
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:
|
||||
continue
|
||||
|
|
@ -819,11 +819,11 @@ class FilesystemType(StrEnum):
|
|||
return None
|
||||
|
||||
|
||||
class ModificationStatus(Enum):
|
||||
Exist = 'existing'
|
||||
Modify = 'modify'
|
||||
Delete = 'delete'
|
||||
Create = 'create'
|
||||
class ModificationStatus(StrEnum):
|
||||
EXIST = 'existing'
|
||||
MODIFY = auto()
|
||||
DELETE = auto()
|
||||
CREATE = auto()
|
||||
|
||||
|
||||
class _PartitionModificationSerialization(TypedDict):
|
||||
|
|
@ -868,7 +868,7 @@ class PartitionModification:
|
|||
if self.is_exists_or_modify() and not self.dev_path:
|
||||
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')
|
||||
|
||||
@override
|
||||
|
|
@ -911,7 +911,7 @@ class PartitionModification:
|
|||
subvol_mods = []
|
||||
|
||||
return cls(
|
||||
status=ModificationStatus.Exist,
|
||||
status=ModificationStatus.EXIST,
|
||||
type=partition_info.type,
|
||||
start=partition_info.start,
|
||||
length=partition_info.length,
|
||||
|
|
@ -961,23 +961,23 @@ class PartitionModification:
|
|||
return self.fs_type == FilesystemType.LINUX_SWAP
|
||||
|
||||
def is_modify(self) -> bool:
|
||||
return self.status == ModificationStatus.Modify
|
||||
return self.status == ModificationStatus.MODIFY
|
||||
|
||||
def is_delete(self) -> bool:
|
||||
return self.status == ModificationStatus.Delete
|
||||
return self.status == ModificationStatus.DELETE
|
||||
|
||||
def exists(self) -> bool:
|
||||
return self.status == ModificationStatus.Exist
|
||||
return self.status == ModificationStatus.EXIST
|
||||
|
||||
def is_exists_or_modify(self) -> bool:
|
||||
return self.status in [
|
||||
ModificationStatus.Exist,
|
||||
ModificationStatus.Delete,
|
||||
ModificationStatus.Modify,
|
||||
ModificationStatus.EXIST,
|
||||
ModificationStatus.DELETE,
|
||||
ModificationStatus.MODIFY,
|
||||
]
|
||||
|
||||
def is_create_or_modify(self) -> bool:
|
||||
return self.status in [ModificationStatus.Create, ModificationStatus.Modify]
|
||||
return self.status in [ModificationStatus.CREATE, ModificationStatus.MODIFY]
|
||||
|
||||
@property
|
||||
def mapper_name(self) -> str | None:
|
||||
|
|
@ -1088,13 +1088,6 @@ class LvmVolumeGroup:
|
|||
return lv in self.volumes
|
||||
|
||||
|
||||
class LvmVolumeStatus(Enum):
|
||||
Exist = 'existing'
|
||||
Modify = 'modify'
|
||||
Delete = 'delete'
|
||||
Create = 'create'
|
||||
|
||||
|
||||
class _LvmVolumeSerialization(TypedDict):
|
||||
obj_id: str
|
||||
status: str
|
||||
|
|
@ -1108,7 +1101,7 @@ class _LvmVolumeSerialization(TypedDict):
|
|||
|
||||
@dataclass
|
||||
class LvmVolume:
|
||||
status: LvmVolumeStatus
|
||||
status: ModificationStatus
|
||||
name: str
|
||||
fs_type: FilesystemType
|
||||
length: Size
|
||||
|
|
@ -1177,7 +1170,7 @@ class LvmVolume:
|
|||
@classmethod
|
||||
def parse_arg(cls, arg: _LvmVolumeSerialization) -> Self:
|
||||
volume = cls(
|
||||
status=LvmVolumeStatus(arg['status']),
|
||||
status=ModificationStatus(arg['status']),
|
||||
name=arg['name'],
|
||||
fs_type=FilesystemType(arg['fs_type']),
|
||||
length=Size.parse_args(arg['length']),
|
||||
|
|
@ -1215,13 +1208,13 @@ class LvmVolume:
|
|||
return part_mod
|
||||
|
||||
def is_modify(self) -> bool:
|
||||
return self.status == LvmVolumeStatus.Modify
|
||||
return self.status == ModificationStatus.MODIFY
|
||||
|
||||
def exists(self) -> bool:
|
||||
return self.status == LvmVolumeStatus.Exist
|
||||
return self.status == ModificationStatus.EXIST
|
||||
|
||||
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:
|
||||
if self.mountpoint is not None:
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ device_modification = DeviceModification(device, wipe=True)
|
|||
|
||||
# create a new boot partition
|
||||
boot_partition = PartitionModification(
|
||||
status=ModificationStatus.Create,
|
||||
status=ModificationStatus.CREATE,
|
||||
type=PartitionType.Primary,
|
||||
start=Size(1, 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
|
||||
root_partition = PartitionModification(
|
||||
status=ModificationStatus.Create,
|
||||
status=ModificationStatus.CREATE,
|
||||
type=PartitionType.Primary,
|
||||
start=Size(513, Unit.MiB, 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
|
||||
home_partition = PartitionModification(
|
||||
status=ModificationStatus.Create,
|
||||
status=ModificationStatus.CREATE,
|
||||
type=PartitionType.Primary,
|
||||
start=start_home,
|
||||
length=length_home,
|
||||
|
|
|
|||
Loading…
Reference in New Issue