summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2022-04-27 10:03:02 +0200
committerJose M. Guisado <jguisado@soleta.eu>2022-04-27 10:03:02 +0200
commit3da8100a3b3dd2e826e815d7a03dc63cd223e378 (patch)
tree15e008ce162938ad34d2f44c80e9d42f845a9f02
parentad3d3b2d19c412e648ab77dfc4c80b3a0f160656 (diff)
live: get partition number using partno attribute
Removes a workaround enumaration of the partitions of a given libfdisk context. Use Partition class partno attribute. This enables detecting non contiguous partitions, like: /dev/sda /dev/sda1 /dev/sda2 /dev/sda4
-rw-r--r--src/live/ogOperations.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py
index 005cfbd..c3ede91 100644
--- a/src/live/ogOperations.py
+++ b/src/live/ogOperations.py
@@ -46,12 +46,13 @@ class OgLiveOperations:
part_setup['size'] = str(cxt.nsectors * cxt.sector_size // 1024)
part_setup['used_size'] = '0'
- def _refresh_payload_partition(self, cxt, pa, part_setup, num_part, disk):
+ def _refresh_payload_partition(self, cxt, pa, part_setup, disk):
parttype = cxt.partition_to_string(pa, fdisk.FDISK_FIELD_TYPEID)
fstype = cxt.partition_to_string(pa, fdisk.FDISK_FIELD_FSTYPE)
size = cxt.partition_to_string(pa, fdisk.FDISK_FIELD_SIZE)
- source = f'/dev/{disk}{num_part}'
- target = f'/mnt/{disk}{num_part}/'
+ partnum = pa.partno + 1
+ source = f'/dev/{disk}{partnum}'
+ target = f'/mnt/{disk}{partnum}/'
if cxt.label.name == 'gpt':
code = GUID_MAP.get(parttype, 0x0)
else:
@@ -68,7 +69,7 @@ class OgLiveOperations:
part_setup['disk_type'] = ''
- part_setup['partition'] = str(num_part)
+ part_setup['partition'] = str(partnum)
part_setup['filesystem'] = fstype.upper() if fstype else 'EMPTY'
# part_setup['code'] = hex(code).removeprefix('0x')
part_setup['code'] = hex(code)[2:]
@@ -330,9 +331,9 @@ class OgLiveOperations:
self._refresh_payload_disk(cxt, part_setup, num_disk)
parsed['disk_setup'].append(part_setup)
- for num_part, pa in enumerate(cxt.parts, start=1):
+ for pa in cxt.partitions:
part_setup = part_setup.copy()
- self._refresh_payload_partition(cxt, pa, part_setup, num_part, disk)
+ self._refresh_payload_partition(cxt, pa, part_setup, disk)
parsed['partition_setup'].append(part_setup)
generate_menu(parsed['partition_setup'])