Added tweak to catching output from lsblk.stderr
This commit is contained in:
parent
241a8a117a
commit
b57ec8e3f0
|
|
@ -214,9 +214,7 @@ def all_disks() -> List[BlockDevice]:
|
|||
|
||||
def get_blockdevice_info(device_path, exclude_iso_dev :bool = True) -> Dict[str, Any]:
|
||||
for retry_attempt in range(storage['DISK_RETRY_ATTEMPTS']):
|
||||
print(f"Attempt {retry_attempt} on {device_path}")
|
||||
partprobe(device_path)
|
||||
print('Partprobe done at least')
|
||||
time.sleep(max(0.1, storage['DISK_TIMEOUTS'] * retry_attempt))
|
||||
|
||||
try:
|
||||
|
|
@ -227,9 +225,7 @@ def get_blockdevice_info(device_path, exclude_iso_dev :bool = True) -> Dict[str,
|
|||
if any([dev in lsblk_info.mountpoints for dev in iso_devs]):
|
||||
continue
|
||||
|
||||
print('Using blkid')
|
||||
information = blkid(f'blkid -p -o export {device_path}')
|
||||
print('Returning')
|
||||
return enrich_blockdevice_information(information)
|
||||
except SysCallError as ex:
|
||||
if ex.exit_code in (512, 2):
|
||||
|
|
@ -253,11 +249,9 @@ def get_blockdevice_info(device_path, exclude_iso_dev :bool = True) -> Dict[str,
|
|||
else:
|
||||
# We could not reliably get any information, perhaps the disk is clean of information?
|
||||
if retry_attempt == storage['DISK_RETRY_ATTEMPTS'] -1:
|
||||
print("Raising ex because:", ex.exit_code)
|
||||
print("Raising exception for blkid because:", ex.exit_code)
|
||||
raise ex
|
||||
|
||||
print(f"Could not find info for {device_path}")
|
||||
|
||||
def all_blockdevices(
|
||||
mappers: bool = False,
|
||||
partitions: bool = False,
|
||||
|
|
@ -282,7 +276,6 @@ def all_blockdevices(
|
|||
continue
|
||||
|
||||
information = get_blockdevice_info(device_path)
|
||||
print(f'Done gathering info for {device_path}')
|
||||
if not information:
|
||||
continue
|
||||
|
||||
|
|
|
|||
|
|
@ -190,8 +190,10 @@ class Partition:
|
|||
output = SysCommand(f"lsblk --json -b -o+LOG-SEC,SIZE,PTTYPE,PARTUUID,UUID,FSTYPE {self.device_path}").decode('UTF-8')
|
||||
except SysCallError as error:
|
||||
# It appears as if lsblk can return exit codes like 8192 to indicate something.
|
||||
# But it does return output so we'll try to catch it.
|
||||
# But it does return output in stderr so we'll try to catch it minus the message/info.
|
||||
output = error.worker.decode('UTF-8')
|
||||
if '{' in output:
|
||||
output = output[output.find('{'):]
|
||||
|
||||
if output:
|
||||
try:
|
||||
|
|
@ -200,7 +202,7 @@ class Partition:
|
|||
except json.decoder.JSONDecodeError:
|
||||
log(f"Could not decode JSON: {output}", fg="red", level=logging.ERROR)
|
||||
|
||||
raise DiskError(f'Failed to partition "{self.device_path}" with lsblk')
|
||||
raise DiskError(f'Failed to get partition information "{self.device_path}" with lsblk')
|
||||
|
||||
def _call_sfdisk(self) -> Dict[str, Any]:
|
||||
output = SysCommand(f"sfdisk --json {self.block_device.path}").decode('UTF-8')
|
||||
|
|
|
|||
Loading…
Reference in New Issue