Updated RAM regex to work with both MiB and GB units (#58)

* Updated RAM regex to work with both MiB and GB units

* Set RAM values to something useful in the event of a parsing error

* Ran python3 -m black .
This commit is contained in:
SamusAranX 2023-06-09 16:27:23 +02:00 committed by GitHub
parent 151844fb3e
commit 7bcf3c28fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -210,15 +210,24 @@ class LogAnalyser:
case "ram": case "ram":
ram_match = re.search( ram_match = re.search(
r"RAM:\s(Total)?\s([^;\n\r]*)\s;\s(Available)?\s(\d+)", r"RAM: Total ([\d.]+) (MiB|GB) ; Available ([\d.]+) (MiB|GB)",
self._log_text, self._log_text,
re.MULTILINE, re.MULTILINE,
) )
if ram_match is not None and ram_match.group(2) is not None: if ram_match is not None:
self._hardware_info[setting] = ram_match.group(2).rstrip() try:
ram_available = ram_match.group(4).rstrip() ram_available = float(ram_match.group(3))
if ram_available.isnumeric(): if ram_match.group(4) == "GB":
ram_available *= 1024
self._hardware_info[
setting
] = f"{ram_match.group(1)} {ram_match.group(2)}"
self._ram_available_mib = int(ram_available) self._ram_available_mib = int(ram_available)
except ValueError:
# ram_match.group(3) couldn't be parsed as a float.
self._hardware_info[setting] = "Error"
self._ram_available_mib = -1
case "os": case "os":
os_match = re.search( os_match = re.search(