Refactor PartitionType (#4432)

* Use UPPER_CASE for PartitionType

* Use StrEnum for PartitionType
This commit is contained in:
codefiles 2026-04-16 00:05:08 -04:00 committed by GitHub
parent 8b3be842ca
commit 7ea171369a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 19 additions and 19 deletions

View File

@ -503,7 +503,7 @@ def _boot_partition(sector_size: SectorSize, using_gpt: bool) -> PartitionModifi
# boot partition
return PartitionModification(
status=ModificationStatus.CREATE,
type=PartitionType.Primary,
type=PartitionType.PRIMARY,
start=start,
length=size,
mountpoint=Path('/boot'),
@ -655,7 +655,7 @@ async def suggest_single_disk_layout(
root_partition = PartitionModification(
status=ModificationStatus.CREATE,
type=PartitionType.Primary,
type=PartitionType.PRIMARY,
start=root_start,
length=root_length,
mountpoint=Path('/') if not using_subvolumes else None,
@ -680,7 +680,7 @@ async def suggest_single_disk_layout(
home_partition = PartitionModification(
status=ModificationStatus.CREATE,
type=PartitionType.Primary,
type=PartitionType.PRIMARY,
start=home_start,
length=home_length,
mountpoint=Path('/home'),
@ -765,7 +765,7 @@ async def suggest_multi_disk_layout(
# add root partition to the root device
root_partition = PartitionModification(
status=ModificationStatus.CREATE,
type=PartitionType.Primary,
type=PartitionType.PRIMARY,
start=root_start,
length=root_length,
mountpoint=Path('/'),
@ -787,7 +787,7 @@ async def suggest_multi_disk_layout(
# add home partition to home device
home_partition = PartitionModification(
status=ModificationStatus.CREATE,
type=PartitionType.Primary,
type=PartitionType.PRIMARY,
start=home_start,
length=home_length,
mountpoint=Path('/home'),

View File

@ -58,7 +58,7 @@ class DiskSegment:
part_mod = PartitionModification(
status=ModificationStatus.CREATE,
type=PartitionType._Unknown,
type=PartitionType._UNKNOWN,
start=self.segment.start,
length=self.segment.length,
)
@ -527,7 +527,7 @@ class PartitioningList(ListManager[DiskSegment]):
partition = PartitionModification(
status=ModificationStatus.CREATE,
type=PartitionType.Primary,
type=PartitionType.PRIMARY,
start=free_space.start,
length=length,
fs_type=fs_type,

View File

@ -720,23 +720,23 @@ class BDevice:
return hash(self.disk.device.path)
class PartitionType(Enum):
Boot = 'boot'
Primary = 'primary'
_Unknown = 'unknown'
class PartitionType(StrEnum):
BOOT = auto()
PRIMARY = auto()
_UNKNOWN = 'unknown'
@classmethod
def get_type_from_code(cls, code: int) -> Self:
if code == parted.PARTITION_NORMAL:
return cls.Primary
return cls.PRIMARY
else:
debug(f'Partition code not supported: {code}')
return cls._Unknown
return cls._UNKNOWN
def get_partition_code(self) -> int | None:
if self == PartitionType.Primary:
if self == PartitionType.PRIMARY:
return parted.PARTITION_NORMAL
elif self == PartitionType.Boot:
elif self == PartitionType.BOOT:
return parted.PARTITION_BOOT
return None

View File

@ -64,7 +64,7 @@ After running ``python -m archinstall test_installer`` it should print something
_PartitionInfo(
partition=<parted.partition.Partition object at 0x7fbe166c4a90>,
name='primary',
type=<PartitionType.Primary: 'primary'>,
type=<PartitionType.PRIMARY: 'primary'>,
fs_type=<FilesystemType.FAT32: 'fat32'>,
path='/dev/nvme0n1p1',
start=Size(value=2048, unit=<Unit.sectors: 'sectors'>, sector_size=SectorSize(value=512, unit=<Unit.B: 1>)),

View File

@ -38,7 +38,7 @@ device_modification = DeviceModification(device, wipe=True)
# create a new boot partition
boot_partition = PartitionModification(
status=ModificationStatus.CREATE,
type=PartitionType.Primary,
type=PartitionType.PRIMARY,
start=Size(1, Unit.MiB, device.device_info.sector_size),
length=Size(512, Unit.MiB, device.device_info.sector_size),
mountpoint=Path('/boot'),
@ -50,7 +50,7 @@ device_modification.add_partition(boot_partition)
# create a root partition
root_partition = PartitionModification(
status=ModificationStatus.CREATE,
type=PartitionType.Primary,
type=PartitionType.PRIMARY,
start=Size(513, Unit.MiB, device.device_info.sector_size),
length=Size(20, Unit.GiB, device.device_info.sector_size),
mountpoint=None,
@ -65,7 +65,7 @@ length_home = device.device_info.total_size - start_home
# create a new home partition
home_partition = PartitionModification(
status=ModificationStatus.CREATE,
type=PartitionType.Primary,
type=PartitionType.PRIMARY,
start=start_home,
length=length_home,
mountpoint=Path('/home'),