updated parsing
This commit is contained in:
@ -779,38 +779,45 @@ class SystemHealthMonitor:
|
||||
return False
|
||||
|
||||
def _parse_size(self, size_str: str) -> float:
|
||||
"""Parse size string with units to bytes"""
|
||||
if not size_str or not isinstance(size_str, str):
|
||||
logger.debug(f"Invalid size string: {size_str}")
|
||||
return 0.0
|
||||
|
||||
size_str = size_str.strip().upper()
|
||||
"""
|
||||
Parse size string with units to bytes.
|
||||
|
||||
:param size_str: String containing size with unit (e.g. '15.7G', '21.8T')
|
||||
:return: Size in bytes as float
|
||||
"""
|
||||
logger.debug(f"Parsing size string: {size_str}")
|
||||
|
||||
try:
|
||||
# Skip non-size strings
|
||||
if not any(unit in size_str.upper() for unit in ['B', 'K', 'M', 'G', 'T']):
|
||||
logger.debug(f"No valid size unit found in: {size_str}")
|
||||
return 0.0
|
||||
|
||||
# Match size with optional decimal and unit
|
||||
match = re.match(r'^([\d.]+)\s*([KMGT]B?)?$', size_str)
|
||||
if match:
|
||||
value = float(match.group(1))
|
||||
unit = match.group(2)
|
||||
# Define multipliers for units
|
||||
multipliers = {
|
||||
'B': 1,
|
||||
'K': 1024,
|
||||
'M': 1024**2,
|
||||
'G': 1024**3,
|
||||
'T': 1024**4
|
||||
}
|
||||
|
||||
# Extract numeric value and unit
|
||||
value = float(size_str[:-1].strip())
|
||||
unit = size_str[-1].upper()
|
||||
|
||||
logger.debug(f"Extracted value: {value}, unit: {unit}")
|
||||
|
||||
multipliers = {
|
||||
'K': 1024,
|
||||
'M': 1024**2,
|
||||
'G': 1024**3,
|
||||
'T': 1024**4,
|
||||
'KB': 1024,
|
||||
'MB': 1024**2,
|
||||
'GB': 1024**3,
|
||||
'TB': 1024**4
|
||||
}
|
||||
byte_value = value * multipliers.get(unit, 1)
|
||||
logger.debug(f"Converted size to bytes: {byte_value}")
|
||||
return byte_value
|
||||
|
||||
logger.debug(f"Failed to parse size string: {size_str}")
|
||||
return 0.0
|
||||
# Convert to bytes
|
||||
bytes_value = value * multipliers.get(unit, 0)
|
||||
logger.debug(f"Converted size to bytes: {bytes_value}")
|
||||
|
||||
return bytes_value
|
||||
|
||||
except (ValueError, AttributeError) as e:
|
||||
logger.debug(f"Failed to parse size string: {size_str}")
|
||||
logger.debug(f"Parse error details: {str(e)}")
|
||||
return 0.0
|
||||
|
||||
def _is_physical_disk(self, device_path):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user