updated parsing
This commit is contained in:
@ -779,38 +779,45 @@ class SystemHealthMonitor:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def _parse_size(self, size_str: str) -> float:
|
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):
|
Parse size string with units to bytes.
|
||||||
logger.debug(f"Invalid size string: {size_str}")
|
|
||||||
return 0.0
|
|
||||||
|
|
||||||
size_str = size_str.strip().upper()
|
: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}")
|
logger.debug(f"Parsing size string: {size_str}")
|
||||||
|
|
||||||
# Match size with optional decimal and unit
|
try:
|
||||||
match = re.match(r'^([\d.]+)\s*([KMGT]B?)?$', size_str)
|
# Skip non-size strings
|
||||||
if match:
|
if not any(unit in size_str.upper() for unit in ['B', 'K', 'M', 'G', 'T']):
|
||||||
value = float(match.group(1))
|
logger.debug(f"No valid size unit found in: {size_str}")
|
||||||
unit = match.group(2)
|
return 0.0
|
||||||
logger.debug(f"Extracted value: {value}, unit: {unit}")
|
|
||||||
|
|
||||||
|
# Define multipliers for units
|
||||||
multipliers = {
|
multipliers = {
|
||||||
|
'B': 1,
|
||||||
'K': 1024,
|
'K': 1024,
|
||||||
'M': 1024**2,
|
'M': 1024**2,
|
||||||
'G': 1024**3,
|
'G': 1024**3,
|
||||||
'T': 1024**4,
|
'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}")
|
# Extract numeric value and unit
|
||||||
return 0.0
|
value = float(size_str[:-1].strip())
|
||||||
|
unit = size_str[-1].upper()
|
||||||
|
|
||||||
|
logger.debug(f"Extracted value: {value}, unit: {unit}")
|
||||||
|
|
||||||
|
# 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):
|
def _is_physical_disk(self, device_path):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user