Skip to content

Commit

Permalink
Use rust parser
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasdoehne committed Jan 5, 2023
1 parent 3a01d3a commit 53e6bdf
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions stellarisdashboard/parsing/save_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import concurrent.futures
import enum
import itertools
import json
import logging
import multiprocessing as mp
import os
Expand Down Expand Up @@ -261,26 +262,21 @@ def parse_save(filename) -> Dict[str, Any]:
:param filename: Path to a .sav file
:return: The gamestate dictionary
"""
gamestate = None
parser = SaveFileParser()
max_attempts = 3
for attempt in range(max_attempts):
try:
gamestate = parser.parse_save(filename)
break
except KeyboardInterrupt:
raise
except zipfile.BadZipFile as e:
remaining = max_attempts - attempt - 1
if not remaining:
raise
delay_seconds = 0.5
logger.info(
f"Encountered BadZipFile error {e}. Next attempt in {delay_seconds} seconds, {remaining} attempts remaining."
)
time.sleep(delay_seconds)
return gamestate
import rust_parser

def fix_dict(d):
x = {}
for k, v in d.items():
try:
x[int(k)] = v
except:
x[k] = v
return x

return json.loads(
rust_parser.parse_save_file(str(filename.absolute())),
object_hook=fix_dict,
)

class TokenType(enum.Enum):
BRACE_OPEN = enum.auto()
Expand Down

0 comments on commit 53e6bdf

Please sign in to comment.