11from __future__ import annotations
22
3- import json
43import math
54import uuid
65from dataclasses import dataclass , field
1413
1514from ..exceptions import DiskError , SysCallError
1615from ..general import SysCommand
17- from ..output import debug , error
16+ from ..output import debug
1817from ..storage import storage
1918
2019if TYPE_CHECKING :
@@ -1402,7 +1401,7 @@ def _fetch_lsblk_info(
14021401 dev_path : Path | str | None = None ,
14031402 reverse : bool = False ,
14041403 full_dev_path : bool = False
1405- ) -> list [ LsblkInfo ] :
1404+ ) -> LsblkOutput :
14061405 cmd = ['lsblk' , '--json' , '--bytes' , '--output' , ',' .join (LsblkInfo .fields ())]
14071406
14081407 if reverse :
@@ -1427,27 +1426,28 @@ def _fetch_lsblk_info(
14271426
14281427 raise err
14291428
1430- try :
1431- data = json .loads (worker .output (remove_cr = False ))
1432- except json .decoder .JSONDecodeError as err :
1433- error (f"Could not decode lsblk JSON:\n { worker .output ().decode ().rstrip ()} " )
1434- raise err
1435-
1436- return LsblkOutput (** data ).blockdevices
1429+ output = worker .output (remove_cr = False )
1430+ return LsblkOutput .parse_raw (output )
14371431
14381432
14391433def get_lsblk_info (
14401434 dev_path : Path | str ,
14411435 reverse : bool = False ,
14421436 full_dev_path : bool = False
14431437) -> LsblkInfo :
1444- if infos := _fetch_lsblk_info (dev_path , reverse = reverse , full_dev_path = full_dev_path ):
1445- return infos [0 ]
1438+ infos = _fetch_lsblk_info (dev_path , reverse = reverse , full_dev_path = full_dev_path )
1439+
1440+ if infos .blockdevices :
1441+ return infos .blockdevices [0 ]
14461442
14471443 raise DiskError (f'lsblk failed to retrieve information for "{ dev_path } "' )
14481444
14491445
14501446def get_all_lsblk_info () -> list [LsblkInfo ]:
1447+ return _fetch_lsblk_info ().blockdevices
1448+
1449+
1450+ def get_lsblk_output () -> LsblkOutput :
14511451 return _fetch_lsblk_info ()
14521452
14531453
0 commit comments