From 3f667f9fb4719f7fc1c8b680eb1e0fb74c0c4651 Mon Sep 17 00:00:00 2001 From: caleb Date: Thu, 27 Jun 2024 11:54:51 -0400 Subject: [PATCH] code hygiene (cherry picked from commit d0675a3989d3a671412aefbe0159a0d88412bce3) --- .../middlewared/plugins/disk_/disk_info.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/middlewared/middlewared/plugins/disk_/disk_info.py b/src/middlewared/middlewared/plugins/disk_/disk_info.py index e92e578f372b7..ee8e2fd042307 100644 --- a/src/middlewared/middlewared/plugins/disk_/disk_info.py +++ b/src/middlewared/middlewared/plugins/disk_/disk_info.py @@ -25,21 +25,15 @@ def get_dev_size(self, device): def list_partitions(self, disk): parts = [] try: - block_device = pyudev.Devices.from_name(pyudev.Context(), 'block', disk) + bd = pyudev.Devices.from_name(pyudev.Context(), 'block', disk) except pyudev.DeviceNotFoundByNameError: return parts - if not block_device.children: + if not bd.children: return parts - for p in filter( - lambda p: all( - p.get(k) for k in ( - 'ID_PART_ENTRY_TYPE', 'ID_PART_ENTRY_UUID', 'ID_PART_ENTRY_NUMBER', 'ID_PART_ENTRY_SIZE' - ) - ), - block_device.children - ): + req_keys = ('ID_PART_' + i for i in ('TYPE', 'UUID', 'NUMBER', 'SIZE')) + for p in filter(lambda p: all(p.get(k) for k in req_keys), bd.children): part_name = self.get_partition_for_disk(disk, p['ID_PART_ENTRY_NUMBER']) start_sector = int(p['ID_PART_ENTRY_OFFSET']) end_sector = int(p['ID_PART_ENTRY_OFFSET']) + int(p['ID_PART_ENTRY_SIZE']) - 1