Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/disk/diskinfo.py
diff options
context:
space:
mode:
authorDaniel Girtler <blackrabbit256@gmail.com>2022-10-04 01:37:57 +1100
committerGitHub <noreply@github.com>2022-10-03 16:37:57 +0200
commit40e4046633d857929b8fd1bfa121b38937add81c (patch)
treea099f43d011eb84fc5ca38ebc41a8170514f5b37 /archinstall/lib/disk/diskinfo.py
parent5959cde5cb43c166d44af49864ab50d5584ecf45 (diff)
Exclude archiso devices from selectable blockdevices (#1481)
* Exclude liveusb from disk selection * Exclude arch iso from being an option * Update * Update * Update * Mypy Co-authored-by: Daniel Girtler <girtler.daniel@gmail.com>
Diffstat (limited to 'archinstall/lib/disk/diskinfo.py')
-rw-r--r--archinstall/lib/disk/diskinfo.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/archinstall/lib/disk/diskinfo.py b/archinstall/lib/disk/diskinfo.py
new file mode 100644
index 00000000..b56ba282
--- /dev/null
+++ b/archinstall/lib/disk/diskinfo.py
@@ -0,0 +1,40 @@
+import dataclasses
+import json
+from dataclasses import dataclass, field
+from typing import Optional, List
+
+from ..general import SysCommand
+from ..exceptions import DiskError
+
+@dataclass
+class LsblkInfo:
+ size: int = 0
+ log_sec: int = 0
+ pttype: Optional[str] = None
+ rota: bool = False
+ tran: Optional[str] = None
+ ptuuid: Optional[str] = None
+ partuuid: Optional[str] = None
+ uuid: Optional[str] = None
+ fstype: Optional[str] = None
+ type: Optional[str] = None
+ mountpoints: List[str] = field(default_factory=list)
+
+
+def get_lsblk_info(dev_path: str) -> LsblkInfo:
+ fields = [f.name for f in dataclasses.fields(LsblkInfo)]
+ lsblk_fields = ','.join([f.upper().replace('_', '-') for f in fields])
+
+ output = SysCommand(f'lsblk --json -b -o+{lsblk_fields} {dev_path}').decode('UTF-8')
+
+ if output:
+ block_devices = json.loads(output)
+ info = block_devices['blockdevices'][0]
+ lsblk_info = LsblkInfo()
+
+ for f in fields:
+ setattr(lsblk_info, f, info[f.replace('_', '-')])
+
+ return lsblk_info
+
+ raise DiskError(f'Failed to read disk "{dev_path}" with lsblk')