Skip to content

Commit

Permalink
Updated RAM regex to work with both MiB and GB units (#58)
Browse files Browse the repository at this point in the history
* 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 .
  • Loading branch information
SamusAranX committed Jun 9, 2023
1 parent 151844f commit 7bcf3c2
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions robocop_ng/helpers/ryujinx_log_analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,24 @@ def __get_hardware_info(self):

case "ram":
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,
re.MULTILINE,
)
if ram_match is not None and ram_match.group(2) is not None:
self._hardware_info[setting] = ram_match.group(2).rstrip()
ram_available = ram_match.group(4).rstrip()
if ram_available.isnumeric():
if ram_match is not None:
try:
ram_available = float(ram_match.group(3))
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)
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":
os_match = re.search(
Expand Down

0 comments on commit 7bcf3c2

Please sign in to comment.