Refactor PartitionType (#4432)
* Use UPPER_CASE for PartitionType * Use StrEnum for PartitionType
This commit is contained in:
parent
8b3be842ca
commit
7ea171369a
|
|
@ -503,7 +503,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,
|
||||||
mountpoint=Path('/boot'),
|
mountpoint=Path('/boot'),
|
||||||
|
|
@ -655,7 +655,7 @@ async def suggest_single_disk_layout(
|
||||||
|
|
||||||
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,
|
||||||
mountpoint=Path('/') if not using_subvolumes else None,
|
mountpoint=Path('/') if not using_subvolumes else None,
|
||||||
|
|
@ -680,7 +680,7 @@ async def suggest_single_disk_layout(
|
||||||
|
|
||||||
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,
|
||||||
mountpoint=Path('/home'),
|
mountpoint=Path('/home'),
|
||||||
|
|
@ -765,7 +765,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,
|
||||||
mountpoint=Path('/'),
|
mountpoint=Path('/'),
|
||||||
|
|
@ -787,7 +787,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,
|
||||||
mountpoint=Path('/home'),
|
mountpoint=Path('/home'),
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ class DiskSegment:
|
||||||
|
|
||||||
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,
|
||||||
)
|
)
|
||||||
|
|
@ -527,7 +527,7 @@ class PartitioningList(ListManager[DiskSegment]):
|
||||||
|
|
||||||
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,
|
||||||
fs_type=fs_type,
|
fs_type=fs_type,
|
||||||
|
|
|
||||||
|
|
@ -720,23 +720,23 @@ class BDevice:
|
||||||
return hash(self.disk.device.path)
|
return hash(self.disk.device.path)
|
||||||
|
|
||||||
|
|
||||||
class PartitionType(Enum):
|
class PartitionType(StrEnum):
|
||||||
Boot = 'boot'
|
BOOT = auto()
|
||||||
Primary = 'primary'
|
PRIMARY = auto()
|
||||||
_Unknown = 'unknown'
|
_UNKNOWN = 'unknown'
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_type_from_code(cls, code: int) -> Self:
|
def get_type_from_code(cls, code: int) -> Self:
|
||||||
if code == parted.PARTITION_NORMAL:
|
if code == parted.PARTITION_NORMAL:
|
||||||
return cls.Primary
|
return cls.PRIMARY
|
||||||
else:
|
else:
|
||||||
debug(f'Partition code not supported: {code}')
|
debug(f'Partition code not supported: {code}')
|
||||||
return cls._Unknown
|
return cls._UNKNOWN
|
||||||
|
|
||||||
def get_partition_code(self) -> int | None:
|
def get_partition_code(self) -> int | None:
|
||||||
if self == PartitionType.Primary:
|
if self == PartitionType.PRIMARY:
|
||||||
return parted.PARTITION_NORMAL
|
return parted.PARTITION_NORMAL
|
||||||
elif self == PartitionType.Boot:
|
elif self == PartitionType.BOOT:
|
||||||
return parted.PARTITION_BOOT
|
return parted.PARTITION_BOOT
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ After running ``python -m archinstall test_installer`` it should print something
|
||||||
_PartitionInfo(
|
_PartitionInfo(
|
||||||
partition=<parted.partition.Partition object at 0x7fbe166c4a90>,
|
partition=<parted.partition.Partition object at 0x7fbe166c4a90>,
|
||||||
name='primary',
|
name='primary',
|
||||||
type=<PartitionType.Primary: 'primary'>,
|
type=<PartitionType.PRIMARY: 'primary'>,
|
||||||
fs_type=<FilesystemType.FAT32: 'fat32'>,
|
fs_type=<FilesystemType.FAT32: 'fat32'>,
|
||||||
path='/dev/nvme0n1p1',
|
path='/dev/nvme0n1p1',
|
||||||
start=Size(value=2048, unit=<Unit.sectors: 'sectors'>, sector_size=SectorSize(value=512, unit=<Unit.B: 1>)),
|
start=Size(value=2048, unit=<Unit.sectors: 'sectors'>, sector_size=SectorSize(value=512, unit=<Unit.B: 1>)),
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,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),
|
||||||
mountpoint=Path('/boot'),
|
mountpoint=Path('/boot'),
|
||||||
|
|
@ -50,7 +50,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),
|
||||||
mountpoint=None,
|
mountpoint=None,
|
||||||
|
|
@ -65,7 +65,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,
|
||||||
mountpoint=Path('/home'),
|
mountpoint=Path('/home'),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue