From 83d222cec6e7febd8b18be8e5b0733661a022c9d Mon Sep 17 00:00:00 2001 From: codefiles <11915375+codefiles@users.noreply.github.com> Date: Wed, 20 Nov 2024 01:55:09 -0500 Subject: [PATCH] Rework partition flag (#2895) --- archinstall/lib/disk/device_model.py | 38 ++++++++++++++++++---- docs/cli_parameters/config/disk_config.rst | 2 +- docs/examples/python.rst | 4 +-- docs/installing/guided.rst | 2 +- examples/config-sample.json | 2 +- 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/archinstall/lib/disk/device_model.py b/archinstall/lib/disk/device_model.py index 9050afbc..9c4d91c0 100644 --- a/archinstall/lib/disk/device_model.py +++ b/archinstall/lib/disk/device_model.py @@ -111,6 +111,11 @@ class DiskLayoutConfiguration: device_partitions: list[PartitionModification] = [] for partition in entry.get('partitions', []): + flags = [ + flag for f in partition.get('flags', []) + if (flag := PartitionFlag.from_string(f)) + ] + device_partition = PartitionModification( status=ModificationStatus(partition['status']), fs_type=FilesystemType(partition['fs_type']) if partition.get('fs_type') else None, @@ -120,7 +125,7 @@ class DiskLayoutConfiguration: mountpoint=Path(partition['mountpoint']) if partition['mountpoint'] else None, dev_path=Path(partition['dev_path']) if partition['dev_path'] else None, type=PartitionType(partition['type']), - flags=[PartitionFlag[f] for f in partition.get('flags', [])], + flags=flags, btrfs_subvols=SubvolumeModification.parse_args(partition.get('btrfs', [])), ) # special 'invisible attr to internally identify the part mod @@ -388,7 +393,7 @@ class _PartitionInfo: btrfs_subvol_infos: list[_BtrfsSubvolumeInfo] = [] ) -> _PartitionInfo: partition_type = PartitionType.get_type_from_code(partition.type) - flags = [f for f in PartitionFlag if partition.getFlag(f.value)] + flags = [f for f in PartitionFlag if partition.getFlag(f.flag_id)] start = Size( partition.geometry.start, @@ -579,11 +584,32 @@ class PartitionType(Enum): return None -class PartitionFlag(Enum): +@dataclass(frozen=True) +class PartitionFlagDataMixin: + flag_id: int + alias: str | None = None + + +class PartitionFlag(PartitionFlagDataMixin, Enum): Boot = parted.PARTITION_BOOT - XBOOTLDR = parted.PARTITION_BLS_BOOT # Note: parted calls this bls_boot + XBOOTLDR = parted.PARTITION_BLS_BOOT, "bls_boot" ESP = parted.PARTITION_ESP + @property + def description(self) -> str: + return self.alias or self.name.lower() + + @classmethod + def from_string(cls, s: str) -> PartitionFlag | None: + s = s.lower() + + for partition_flag in cls: + if s in (partition_flag.name.lower(), partition_flag.alias): + return partition_flag + + debug(f'Partition flag not supported: {s}') + return None + class PartitionGUID(Enum): """ @@ -829,7 +855,7 @@ class PartitionModification: 'fs_type': self.fs_type.value if self.fs_type else None, 'mountpoint': str(self.mountpoint) if self.mountpoint else None, 'mount_options': self.mount_options, - 'flags': [f.name for f in self.flags], + 'flags': [f.description for f in self.flags], 'dev_path': str(self.dev_path) if self.dev_path else None, 'btrfs': [vol.json() for vol in self.btrfs_subvols] } @@ -848,7 +874,7 @@ class PartitionModification: 'FS type': self.fs_type.value if self.fs_type else 'Unknown', 'Mountpoint': self.mountpoint if self.mountpoint else '', 'Mount options': ', '.join(self.mount_options), - 'Flags': ', '.join([f.name for f in self.flags]), + 'Flags': ', '.join([f.description for f in self.flags]), } if self.btrfs_subvols: diff --git a/docs/cli_parameters/config/disk_config.rst b/docs/cli_parameters/config/disk_config.rst index b09d0dc0..fd8e2f9d 100644 --- a/docs/cli_parameters/config/disk_config.rst +++ b/docs/cli_parameters/config/disk_config.rst @@ -102,7 +102,7 @@ FAT32 { "btrfs": [], "flags": [ - "Boot" + "boot" ], "fs_type": "fat32", "length": { diff --git a/docs/examples/python.rst b/docs/examples/python.rst index 7226c825..c0f27a53 100644 --- a/docs/examples/python.rst +++ b/docs/examples/python.rst @@ -69,8 +69,8 @@ After running ``python -m archinstall test_installer`` it should print something start=Size(value=2048, unit=, sector_size=SectorSize(value=512, unit=)), length=Size(value=535822336, unit=, sector_size=SectorSize(value=512, unit=)), flags=[ - , - + , + ], partn=1, partuuid='a26be943-c193-41f4-9930-9341cf5f6b19', diff --git a/docs/installing/guided.rst b/docs/installing/guided.rst index ed0e6cdc..49be3da1 100644 --- a/docs/installing/guided.rst +++ b/docs/installing/guided.rst @@ -70,7 +70,7 @@ The contents of :code:`https://domain.lan/config.json`: { "btrfs": [], "flags": [ - "Boot" + "boot" ], "fs_type": "fat32", "length": { diff --git a/examples/config-sample.json b/examples/config-sample.json index 57c1e1da..6a4f2416 100644 --- a/examples/config-sample.json +++ b/examples/config-sample.json @@ -15,7 +15,7 @@ { "btrfs": [], "flags": [ - "Boot" + "boot" ], "fs_type": "fat32", "size": {