Updated scripts and added new

This commit is contained in:
2023-11-25 20:23:04 +01:00
parent a5153cc997
commit 92df6f6b44
7 changed files with 566 additions and 251 deletions

36
util.py Normal file
View File

@ -0,0 +1,36 @@
import sys
from pathlib import Path
from zipfile import ZipFile
def is_valid_zip(file: Path) -> bool:
"""
Checks if a zip file is a save file from the minimax simulator, e.g. if the contents
are a 'machine.json' and 'signal.json' file.
"""
if not file.suffix == ".zip":
return False
with ZipFile(file) as machine_zip:
zip_content = machine_zip.namelist()
return set(zip_content) == set(("machine.json", "signal.json"))
def select_zip(zips: list[Path]) -> Path:
"""
Prompts the user to select a single zip file from a list, and returns it.
"""
print("Multiple zip files found. Please select one:")
for index, f in enumerate(zips, start=1):
print(f"[{index}] {f.name}")
while True:
try:
selection = input("Enter the number of the zip file to select: ")
selection = int(selection) - 1
if selection <= 0 or selection > len(zips):
print(f"Please select a number between 1 and {len(zips)}.")
else:
return zips[selection]
except ValueError:
print("Please enter a valid integer.")
except KeyboardInterrupt:
sys.exit("Aborted")