From 61bc59f5bfe1eb848bcb5ba891921544fd70c2e2 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Thu, 18 Nov 2021 15:29:59 +0000 Subject: Reworked the last uuid fix, and introduced _safe_uuid which does the same thing but handles the DisKerror. This way we can use it in more places. --- archinstall/lib/disk/partition.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/archinstall/lib/disk/partition.py b/archinstall/lib/disk/partition.py index 39d67873..cfb46015 100644 --- a/archinstall/lib/disk/partition.py +++ b/archinstall/lib/disk/partition.py @@ -64,19 +64,15 @@ class Partition: elif self.target_mountpoint: mount_repr = f", rel_mountpoint={self.target_mountpoint}" - try: - if self._encrypted: - return f'Partition(path={self.path}, size={self.size}, PARTUUID={self.uuid}, parent={self.real_device}, fs={self.filesystem}{mount_repr})' - else: - return f'Partition(path={self.path}, size={self.size}, PARTUUID={self.uuid}, fs={self.filesystem}{mount_repr})' - except DiskError: - # DiskErrors occur when we cannot retrieve the UUID of the partition, usually due to encryption or a slow disk. - return f'Partition(path={self.path}, size={self.size}, PARTUUID=None, fs={self.filesystem}{mount_repr})' + if self._encrypted: + return f'Partition(path={self.path}, size={self.size}, PARTUUID={self._safe_uuid}, parent={self.real_device}, fs={self.filesystem}{mount_repr})' + else: + return f'Partition(path={self.path}, size={self.size}, PARTUUID={self._safe_uuid}, fs={self.filesystem}{mount_repr})' def __dump__(self): return { 'type' : 'primary', - 'PARTUUID' : self.uuid, + 'PARTUUID' : self._safe_uuid, 'wipe' : self.allow_formatting, 'boot' : self.boot, 'ESP' : self.boot, @@ -164,6 +160,13 @@ class Partition: raise DiskError(f"Could not get PARTUUID for {self.path} using 'lsblk -J -o+PARTUUID {self.path}'") + @property + def _safe_uuid(self): + try: + return self.uuid + except DiskError: + return None + @property def encrypted(self): return self._encrypted -- cgit v1.2.3-54-g00ecf From ee2eba6baff4b94a6a0d6ab26aae9c4f084a55c6 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Thu, 18 Nov 2021 15:32:47 +0000 Subject: Reworked _safe_uuid() to be it's own function without timeouts. --- archinstall/lib/disk/partition.py | 1 - 1 file changed, 1 deletion(-) diff --git a/archinstall/lib/disk/partition.py b/archinstall/lib/disk/partition.py index cfb46015..0d72f6ab 100644 --- a/archinstall/lib/disk/partition.py +++ b/archinstall/lib/disk/partition.py @@ -160,7 +160,6 @@ class Partition: raise DiskError(f"Could not get PARTUUID for {self.path} using 'lsblk -J -o+PARTUUID {self.path}'") - @property def _safe_uuid(self): try: return self.uuid -- cgit v1.2.3-54-g00ecf From 96332670c3f58770c7529aa0ef4fc96760172199 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Thu, 18 Nov 2021 15:33:21 +0000 Subject: Added docstring --- archinstall/lib/disk/partition.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/archinstall/lib/disk/partition.py b/archinstall/lib/disk/partition.py index 0d72f6ab..f8378d47 100644 --- a/archinstall/lib/disk/partition.py +++ b/archinstall/lib/disk/partition.py @@ -160,11 +160,20 @@ class Partition: raise DiskError(f"Could not get PARTUUID for {self.path} using 'lsblk -J -o+PARTUUID {self.path}'") - def _safe_uuid(self): - try: - return self.uuid - except DiskError: - return None + @property + def _safe_uuid(self) -> Optional[str]: + """ + A near copy of self.uuid but without any delays. + This function should only be used where uuid is not crucial. + For instance when you want to get a __repr__ of the class. + """ + self.partprobe() + + partuuid_struct = SysCommand(f'lsblk -J -o+PARTUUID {self.path}') + if partuuid_struct.exit_code == 0: + if partition_information := next(iter(json.loads(partuuid_struct.decode('UTF-8'))['blockdevices']), None): + if (partuuid := partition_information.get('partuuid', None)): + return partuuid @property def encrypted(self): -- cgit v1.2.3-54-g00ecf