utils: add get_filesystem_type function

Retrieve filesystem type from a partition using get_filesystem_type.
Encapsulates a subprocess call to blkid.
more_events
Jose M. Guisado 2023-04-25 13:29:05 +02:00
parent 2ddea6d514
commit 22dce48d3e
1 changed files with 12 additions and 0 deletions

View File

@ -165,3 +165,15 @@ def mkfs_fat32(partdev, label=None):
subprocess.run(cmd,
stdout=logfile,
stderr=STDOUT)
def get_filesystem_type(partdev):
"""
Get filesystem type from a partition device path.
Raises RuntimeError when blkid exits with non-zero return code.
"""
cmd = shlex.split(f'blkid -o value -s TYPE {partdev}')
proc = subprocess.run(cmd, stdout=PIPE, encoding='utf-8')
if proc.returncode != 0:
raise RuntimeError(f'Error getting filesystem from {partdev}')
return proc.stdout.strip()