]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
list-discoverable-partitions: apply "ruff format"
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 19 Feb 2026 17:10:48 +0000 (02:10 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 17 May 2026 17:44:47 +0000 (02:44 +0900)
tools/list-discoverable-partitions.py

index a19bf1d6e2ee7ad1887f5492b0fa9c5e73e2777f..437be68d727f7221891d495179dde3028546044c 100755 (executable)
@@ -30,16 +30,15 @@ ARCHITECTURES = {
     'TILEGX':      'TILE-Gx',
     'X86':         'x86',
     'X86_64':      'amd64/x86_64',
-}
+}  # fmt: skip
 
 TYPES = {
-    'ROOT' :            'Root Partition',
-    'ROOT_VERITY' :     'Root Verity Partition',
-    'ROOT_VERITY_SIG' : 'Root Verity Signature Partition',
-    'USR' :             '`/usr/` Partition',
-    'USR_VERITY' :      '`/usr/` Verity Partition',
-    'USR_VERITY_SIG' :  '`/usr/` Verity Signature Partition',
-
+    'ROOT':             'Root Partition',
+    'ROOT_VERITY':      'Root Verity Partition',
+    'ROOT_VERITY_SIG':  'Root Verity Signature Partition',
+    'USR':              '`/usr/` Partition',
+    'USR_VERITY':       '`/usr/` Verity Partition',
+    'USR_VERITY_SIG':   '`/usr/` Verity Signature Partition',
     'ESP':              'EFI System Partition',
     'SRV':              'Server Data Partition',
     'VAR':              'Variable Data Partition',
@@ -49,7 +48,7 @@ TYPES = {
     'USER_HOME':        'Per-user Home Partition',
     'LINUX_GENERIC':    'Generic Linux Data Partition',
     'XBOOTLDR':         'Extended Boot Loader Partition',
-}
+}  # fmt: skip
 
 DESCRIPTIONS = {
     'ROOT': (
@@ -57,56 +56,66 @@ DESCRIPTIONS = {
         'On systems with matching architecture, the first partition with this type UUID on the disk '
         'containing the active EFI ESP is automatically mounted to the root directory `/`. '
         'If the partition is encrypted with LUKS or has dm-verity integrity data (see below), the '
-        'device mapper file will be named `/dev/mapper/root`.'),
+        'device mapper file will be named `/dev/mapper/root`.',
+    ),
     'USR': (
         'Any native, optionally in LUKS',
-        'Similar semantics to root partition, but just the `/usr/` partition.'),
+        'Similar semantics to root partition, but just the `/usr/` partition.',
+    ),
     'ROOT_VERITY': (
         'A dm-verity superblock followed by hash data',
         'Contains dm-verity integrity hash data for the matching root partition. If this feature is '
         'used the partition UUID of the root partition should be the first 128 bits of the root hash '
         'of the dm-verity hash data, and the partition UUID of this dm-verity partition should be the '
         'final 128 bits of it, so that the root partition and its Verity partition can be discovered '
-        'easily, simply by specifying the root hash.'),
+        'easily, simply by specifying the root hash.',
+    ),
     'USR_VERITY': (
         'A dm-verity superblock followed by hash data',
-        'Similar semantics to root Verity partition, but just for the `/usr/` partition.'),
+        'Similar semantics to root Verity partition, but just for the `/usr/` partition.',
+    ),
     'ROOT_VERITY_SIG': (
         'A serialized JSON object, see below',
-        'Contains a root hash and a PKCS#7 signature for it, permitting signed dm-verity GPT images.'),
+        'Contains a root hash and a PKCS#7 signature for it, permitting signed dm-verity GPT images.',
+    ),
     'USR_VERITY_SIG': (
         'A serialized JSON object, see below',
-        'Similar semantics to root Verity signature partition, but just for the `/usr/` partition.'),
-
+        'Similar semantics to root Verity signature partition, but just for the `/usr/` partition.',
+    ),
     'ESP': (
         'VFAT',
         'The ESP used for the current boot is automatically mounted to `/efi/` (or `/boot/` as '
         'fallback), unless a different partition is mounted there (possibly via `/etc/fstab`, or '
         'because the Extended Boot Loader Partition — see below — exists) or the directory is '
         'non-empty on the root disk.  This partition type is defined by the '
-        '[UEFI Specification](http://www.uefi.org/specifications).'),
+        '[UEFI Specification](http://www.uefi.org/specifications).',
+    ),
     'XBOOTLDR': (
         'Typically VFAT',
         'The Extended Boot Loader Partition (XBOOTLDR) used for the current boot is automatically '
         'mounted to `/boot/`, unless a different partition is mounted there (possibly via '
         '`/etc/fstab`) or the directory is non-empty on the root disk. This partition type '
         'is defined by the [Boot Loader '
-        'Specification](https://uapi-group.org/specifications/specs/boot_loader_specification).'),
+        'Specification](https://uapi-group.org/specifications/specs/boot_loader_specification).',
+    ),
     'SWAP': (
         'Swap, optionally in LUKS',
         'All swap partitions on the disk containing the root partition are automatically enabled. '
         'If the partition is encrypted with LUKS, the device mapper file will be named '
-        '`/dev/mapper/swap`. This partition type predates the Discoverable Partitions Specification.'),
+        '`/dev/mapper/swap`. This partition type predates the Discoverable Partitions Specification.',
+    ),
     'HOME': (
         'Any native, optionally in LUKS',
         'The first partition with this type UUID on the disk containing the root partition is '
         'automatically mounted to `/home/`. If the partition is encrypted with LUKS, the device '
-        'mapper file will be named `/dev/mapper/home`.'),
+        'mapper file will be named `/dev/mapper/home`.',
+    ),
     'SRV': (
         'Any native, optionally in LUKS',
         'The first partition with this type UUID on the disk containing the root partition is '
         'automatically mounted to `/srv/`. If the partition is encrypted with LUKS, the device '
-        'mapper file will be named `/dev/mapper/srv`.'),
+        'mapper file will be named `/dev/mapper/srv`.',
+    ),
     'VAR': (
         'Any native, optionally in LUKS',
         'The first partition with this type UUID on the disk containing the root partition is '
@@ -118,7 +127,8 @@ DESCRIPTIONS = {
         'listed here) is inherently private to a specific installation and cannot possibly be '
         'shared between multiple OS installations on the same disk, and thus should be bound to '
         'a specific instance of the OS, identified by its machine ID. If the partition is '
-        'encrypted with LUKS, the device mapper file will be named `/dev/mapper/var`.'),
+        'encrypted with LUKS, the device mapper file will be named `/dev/mapper/var`.',
+    ),
     'TMP': (
         'Any native, optionally in LUKS',
         'The first partition with this type UUID on the disk containing the root partition is '
@@ -127,19 +137,23 @@ DESCRIPTIONS = {
         'is indeed `/var/tmp/`, not `/tmp/`. The latter is typically maintained in memory via '
         '`tmpfs` and does not require a partition on disk. In some cases it might be '
         'desirable to make `/tmp/` persistent too, in which case it is recommended to make it '
-        'a symlink or bind mount to `/var/tmp/`, thus not requiring its own partition type UUID.'),
+        'a symlink or bind mount to `/var/tmp/`, thus not requiring its own partition type UUID.',
+    ),
     'USER_HOME': (
         'Any native, optionally in LUKS',
         'A home partition of a user, managed by '
-        '[`systemd-homed`](https://www.freedesktop.org/software/systemd/man/systemd-homed.html).'),
+        '[`systemd-homed`](https://www.freedesktop.org/software/systemd/man/systemd-homed.html).',
+    ),
     'LINUX_GENERIC': (
         'Any native, optionally in LUKS',
         'No automatic mounting takes place for other Linux data partitions. This partition type '
         'should be used for all partitions that carry Linux file systems. The installer needs '
         'to mount them explicitly via entries in `/etc/fstab`. Optionally, these partitions may '
-        'be encrypted with LUKS. This partition type predates the Discoverable Partitions Specification.'),
+        'be encrypted with LUKS. This partition type predates the Discoverable Partitions Specification.',
+    ),
 }
 
+
 def extract(file):
     for line in file:
         # print(line)
@@ -148,7 +162,10 @@ def extract(file):
             continue
 
         name = line.split()[1]
-        if m2 := re.match(r'^(ROOT|USR)_([A-Z0-9]+|X86_64|PPC64_LE|MIPS_LE|MIPS64_LE)(|_VERITY|_VERITY_SIG)\s+SD_ID128_MAKE\((.*)\)', m.group(1)):
+        if m2 := re.match(
+            r'^(ROOT|USR)_([A-Z0-9]+|X86_64|PPC64_LE|MIPS_LE|MIPS64_LE)(|_VERITY|_VERITY_SIG)\s+SD_ID128_MAKE\((.*)\)',
+            m.group(1),
+        ):
             ptype, arch, suffix, u = m2.groups()
             u = uuid.UUID(u.replace(',', ''))
             assert arch in ARCHITECTURES, f'{arch} not in f{ARCHITECTURES}'
@@ -165,6 +182,7 @@ def extract(file):
         else:
             raise ValueError(f'Failed to match: {m.group(1)}')
 
+
 def generate(defines):
     prevtype = None
 
@@ -188,6 +206,7 @@ def generate(defines):
 
         print(f'| _{tdesc}{adesc}_ | `{puuid}` `{name}` | {morea} | {moreb} |')
 
+
 if __name__ == '__main__':
     known = extract(sys.stdin)
     generate(known)