Skip to content

Commit

Permalink
code hygiene
Browse files Browse the repository at this point in the history
(cherry picked from commit d0675a3)
  • Loading branch information
yocalebo authored and bugclerk committed Jun 28, 2024
1 parent 0045fc1 commit 3f667f9
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/middlewared/middlewared/plugins/disk_/disk_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3f667f9

Please sign in to comment.