summaryrefslogtreecommitdiffstats
path: root/src/utils/fs.py
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2023-04-25 13:29:05 +0200
committerJose M. Guisado <jguisado@soleta.eu>2023-04-25 13:33:45 +0200
commit22dce48d3ec27d0db8f6a069744d44454382bcc4 (patch)
tree4e63f3e59f3a87d197d26253b4e5ae3a71dc8633 /src/utils/fs.py
parent2ddea6d5143c9a1bc7e207735ac9b5b249f6470f (diff)
utils: add get_filesystem_type function
Retrieve filesystem type from a partition using get_filesystem_type. Encapsulates a subprocess call to blkid.
Diffstat (limited to 'src/utils/fs.py')
-rw-r--r--src/utils/fs.py12
1 files changed, 12 insertions, 0 deletions
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()