From 22dce48d3ec27d0db8f6a069744d44454382bcc4 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Tue, 25 Apr 2023 13:29:05 +0200 Subject: utils: add get_filesystem_type function Retrieve filesystem type from a partition using get_filesystem_type. Encapsulates a subprocess call to blkid. --- src/utils/fs.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/utils/fs.py b/src/utils/fs.py index 7b0e1c3..a7058a7 100644 --- a/src/utils/fs.py +++ b/src/utils/fs.py @@ -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() -- cgit v1.2.3-18-g5258