Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/disk
diff options
context:
space:
mode:
authorAnton Hvornum <anton@hvornum.se>2022-05-16 09:09:51 +0200
committerGitHub <noreply@github.com>2022-05-16 09:09:51 +0200
commit5eac5df9a8930fbe7410c90a707f0d88e478f1f9 (patch)
tree7e3b5b3770a138788de9a5b1fad8489ae0ecb687 /archinstall/lib/disk
parenta748f3fba04e771a3c18e66efcd2cf48b42c778e (diff)
Adding safe methods for __repr__ to call so that it doesn't break (#1190)
Diffstat (limited to 'archinstall/lib/disk')
-rw-r--r--archinstall/lib/disk/blockdevice.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/archinstall/lib/disk/blockdevice.py b/archinstall/lib/disk/blockdevice.py
index 206c3b7e..188927b1 100644
--- a/archinstall/lib/disk/blockdevice.py
+++ b/archinstall/lib/disk/blockdevice.py
@@ -32,7 +32,7 @@ class BlockDevice:
# I'm placing the encryption password on a BlockDevice level.
def __repr__(self, *args :str, **kwargs :str) -> str:
- return f"BlockDevice({self.device_or_backfile}, size={self.size}GB, free_space={'+'.join(part[2] for part in self.free_space)}, bus_type={self.bus_type})"
+ return f"BlockDevice({self.device_or_backfile}, size={self._safe_size}GB, free_space={self._safe_free_space}, bus_type={self.bus_type})"
def __iter__(self) -> Iterator[Partition]:
for partition in self.partitions:
@@ -168,6 +168,18 @@ class BlockDevice:
return SysCommand(f'blkid -s PTUUID -o value {self.path}').decode('UTF-8')
@property
+ def _safe_size(self) -> float:
+ from .helpers import convert_size_to_gb
+
+ try:
+ output = json.loads(SysCommand(f"lsblk --json -b -o+SIZE {self.path}").decode('UTF-8'))
+ except SysCallError:
+ return -1.0
+
+ for device in output['blockdevices']:
+ return convert_size_to_gb(device['size'])
+
+ @property
def size(self) -> float:
from .helpers import convert_size_to_gb
@@ -191,7 +203,14 @@ class BlockDevice:
return device['rota'] is True
@property
- def free_space(self) -> Tuple[str, str, str]:
+ def _safe_free_space(self) -> Tuple[str, ...]:
+ try:
+ return '+'.join(part[2] for part in self.free_space)
+ except SysCallError:
+ return '?'
+
+ @property
+ def free_space(self) -> Tuple[str, ...]:
# NOTE: parted -s will default to `cancel` on prompt, skipping any partition
# that is "outside" the disk. in /dev/sr0 this is usually the case with Archiso,
# so the free will ignore the ESP partition and just give the "free" space.