37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
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")
|