Skip to content

Commit 83d222c

Browse files
authored
Rework partition flag (archlinux#2895)
1 parent 3453816 commit 83d222c

File tree

5 files changed

+37
-11
lines changed

5 files changed

+37
-11
lines changed

archinstall/lib/disk/device_model.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ def parse_arg(cls, disk_config: dict[str, Any]) -> DiskLayoutConfiguration | Non
111111
device_partitions: list[PartitionModification] = []
112112

113113
for partition in entry.get('partitions', []):
114+
flags = [
115+
flag for f in partition.get('flags', [])
116+
if (flag := PartitionFlag.from_string(f))
117+
]
118+
114119
device_partition = PartitionModification(
115120
status=ModificationStatus(partition['status']),
116121
fs_type=FilesystemType(partition['fs_type']) if partition.get('fs_type') else None,
@@ -120,7 +125,7 @@ def parse_arg(cls, disk_config: dict[str, Any]) -> DiskLayoutConfiguration | Non
120125
mountpoint=Path(partition['mountpoint']) if partition['mountpoint'] else None,
121126
dev_path=Path(partition['dev_path']) if partition['dev_path'] else None,
122127
type=PartitionType(partition['type']),
123-
flags=[PartitionFlag[f] for f in partition.get('flags', [])],
128+
flags=flags,
124129
btrfs_subvols=SubvolumeModification.parse_args(partition.get('btrfs', [])),
125130
)
126131
# special 'invisible attr to internally identify the part mod
@@ -388,7 +393,7 @@ def from_partition(
388393
btrfs_subvol_infos: list[_BtrfsSubvolumeInfo] = []
389394
) -> _PartitionInfo:
390395
partition_type = PartitionType.get_type_from_code(partition.type)
391-
flags = [f for f in PartitionFlag if partition.getFlag(f.value)]
396+
flags = [f for f in PartitionFlag if partition.getFlag(f.flag_id)]
392397

393398
start = Size(
394399
partition.geometry.start,
@@ -579,11 +584,32 @@ def get_partition_code(self) -> int | None:
579584
return None
580585

581586

582-
class PartitionFlag(Enum):
587+
@dataclass(frozen=True)
588+
class PartitionFlagDataMixin:
589+
flag_id: int
590+
alias: str | None = None
591+
592+
593+
class PartitionFlag(PartitionFlagDataMixin, Enum):
583594
Boot = parted.PARTITION_BOOT
584-
XBOOTLDR = parted.PARTITION_BLS_BOOT # Note: parted calls this bls_boot
595+
XBOOTLDR = parted.PARTITION_BLS_BOOT, "bls_boot"
585596
ESP = parted.PARTITION_ESP
586597

598+
@property
599+
def description(self) -> str:
600+
return self.alias or self.name.lower()
601+
602+
@classmethod
603+
def from_string(cls, s: str) -> PartitionFlag | None:
604+
s = s.lower()
605+
606+
for partition_flag in cls:
607+
if s in (partition_flag.name.lower(), partition_flag.alias):
608+
return partition_flag
609+
610+
debug(f'Partition flag not supported: {s}')
611+
return None
612+
587613

588614
class PartitionGUID(Enum):
589615
"""
@@ -829,7 +855,7 @@ def json(self) -> dict[str, Any]:
829855
'fs_type': self.fs_type.value if self.fs_type else None,
830856
'mountpoint': str(self.mountpoint) if self.mountpoint else None,
831857
'mount_options': self.mount_options,
832-
'flags': [f.name for f in self.flags],
858+
'flags': [f.description for f in self.flags],
833859
'dev_path': str(self.dev_path) if self.dev_path else None,
834860
'btrfs': [vol.json() for vol in self.btrfs_subvols]
835861
}
@@ -848,7 +874,7 @@ def table_data(self) -> dict[str, Any]:
848874
'FS type': self.fs_type.value if self.fs_type else 'Unknown',
849875
'Mountpoint': self.mountpoint if self.mountpoint else '',
850876
'Mount options': ', '.join(self.mount_options),
851-
'Flags': ', '.join([f.name for f in self.flags]),
877+
'Flags': ', '.join([f.description for f in self.flags]),
852878
}
853879

854880
if self.btrfs_subvols:

docs/cli_parameters/config/disk_config.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ FAT32
102102
{
103103
"btrfs": [],
104104
"flags": [
105-
"Boot"
105+
"boot"
106106
],
107107
"fs_type": "fat32",
108108
"length": {

docs/examples/python.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ After running ``python -m archinstall test_installer`` it should print something
6969
start=Size(value=2048, unit=<Unit.sectors: 'sectors'>, sector_size=SectorSize(value=512, unit=<Unit.B: 1>)),
7070
length=Size(value=535822336, unit=<Unit.B: 1>, sector_size=SectorSize(value=512, unit=<Unit.B: 1>)),
7171
flags=[
72-
<PartitionFlag.Boot: 1>,
73-
<PartitionFlag.ESP: 18>
72+
<PartitionFlag.Boot: flag_id=1, alias=None>,
73+
<PartitionFlag.ESP: flag_id=18, alias=None>
7474
],
7575
partn=1,
7676
partuuid='a26be943-c193-41f4-9930-9341cf5f6b19',

docs/installing/guided.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ The contents of :code:`https://domain.lan/config.json`:
7070
{
7171
"btrfs": [],
7272
"flags": [
73-
"Boot"
73+
"boot"
7474
],
7575
"fs_type": "fat32",
7676
"length": {

examples/config-sample.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
{
1616
"btrfs": [],
1717
"flags": [
18-
"Boot"
18+
"boot"
1919
],
2020
"fs_type": "fat32",
2121
"size": {

0 commit comments

Comments
 (0)