Get warnings of options that might not exist in options.yaml
This commit is contained in:
parent
a269db6ab5
commit
8c94351d53
|
@ -18,16 +18,18 @@ import sys
|
|||
import threading
|
||||
import concurrent.futures
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
|
||||
def feedback(text: str):
|
||||
print(text)
|
||||
logging.info(text)
|
||||
input("Press Enter to ignore and probably crash.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(format='%(message)s', level=logging.INFO)
|
||||
try:
|
||||
print(f"{__author__}'s MultiMystery Launcher")
|
||||
logging.info(f"{__author__}'s MultiMystery Launcher")
|
||||
import ModuleUpdate
|
||||
|
||||
ModuleUpdate.update()
|
||||
|
@ -46,7 +48,7 @@ if __name__ == "__main__":
|
|||
output_path = options["general_options"]["output_path"]
|
||||
enemizer_path = multi_mystery_options["enemizer_path"]
|
||||
player_files_path = multi_mystery_options["player_files_path"]
|
||||
target_player_count = multi_mystery_options.get("players", 0)
|
||||
target_player_count = multi_mystery_options["players"]
|
||||
race = multi_mystery_options["race"]
|
||||
create_spoiler = multi_mystery_options["create_spoiler"]
|
||||
zip_roms = multi_mystery_options["zip_roms"]
|
||||
|
@ -57,7 +59,7 @@ if __name__ == "__main__":
|
|||
# zip_password = multi_mystery_options["zip_password"] not at this time
|
||||
player_name = multi_mystery_options["player_name"]
|
||||
meta_file_path = multi_mystery_options["meta_file_path"]
|
||||
weights_file_path = multi_mystery_options.get("weights_file_path", "weights.yaml")
|
||||
weights_file_path = multi_mystery_options["weights_file_path"]
|
||||
teams = multi_mystery_options["teams"]
|
||||
rom_file = options["general_options"]["rom_file"]
|
||||
host = options["server_options"]["host"]
|
||||
|
@ -76,7 +78,7 @@ if __name__ == "__main__":
|
|||
lfile = file.lower()
|
||||
if lfile.endswith(".yaml") and lfile != meta_file_path.lower() and lfile != weights_file_path.lower():
|
||||
player_files.append(file)
|
||||
print(f"Found player's file {file}.")
|
||||
logging.info(f"Found player's file {file}.")
|
||||
|
||||
player_string = ""
|
||||
for i, file in enumerate(player_files, 1):
|
||||
|
@ -98,7 +100,7 @@ if __name__ == "__main__":
|
|||
if target_player_count == 0:
|
||||
feedback(f"No player files found. Please put them in a {player_files_path} folder.")
|
||||
else:
|
||||
print(target_player_count, "Players found.")
|
||||
logging.info(f"{target_player_count} Players found.")
|
||||
|
||||
command = f"{basemysterycommand} --multi {target_player_count} {player_string} " \
|
||||
f"--rom \"{rom_file}\" --enemizercli \"{enemizer_path}\" " \
|
||||
|
@ -117,12 +119,12 @@ if __name__ == "__main__":
|
|||
if os.path.exists(weights_file_path):
|
||||
command += f" --weights {weights_file_path}"
|
||||
|
||||
print(command)
|
||||
logging.info(command)
|
||||
import time
|
||||
|
||||
start = time.perf_counter()
|
||||
text = subprocess.check_output(command, shell=True).decode()
|
||||
print(f"Took {time.perf_counter() - start:.3f} seconds to generate multiworld.")
|
||||
logging.info(f"Took {time.perf_counter() - start:.3f} seconds to generate multiworld.")
|
||||
seedname = ""
|
||||
|
||||
for segment in text.split():
|
||||
|
@ -160,17 +162,17 @@ if __name__ == "__main__":
|
|||
def pack_file(file: str):
|
||||
with ziplock:
|
||||
zf.write(os.path.join(output_path, file), file)
|
||||
print(f"Packed {file} into zipfile {zipname}")
|
||||
logging.info(f"Packed {file} into zipfile {zipname}")
|
||||
|
||||
|
||||
def remove_zipped_file(file: str):
|
||||
os.remove(os.path.join(output_path, file))
|
||||
print(f"Removed {file} which is now present in the zipfile")
|
||||
logging.info(f"Removed {file} which is now present in the zipfile")
|
||||
|
||||
|
||||
zipname = os.path.join(output_path, f"BM_{seedname}.{typical_zip_ending}")
|
||||
|
||||
print(f"Creating zipfile {zipname}")
|
||||
logging.info(f"Creating zipfile {zipname}")
|
||||
ipv4 = (host if host else get_public_ipv4()) + ":" + str(port)
|
||||
|
||||
|
||||
|
|
26
Utils.py
26
Utils.py
|
@ -222,6 +222,23 @@ def get_default_options() -> dict:
|
|||
get_default_options.options = options
|
||||
return get_default_options.options
|
||||
|
||||
def update_options(src: dict, dest: dict, filename: str, keys: list) -> dict:
|
||||
import logging
|
||||
for key, value in src.items():
|
||||
new_keys = keys.copy()
|
||||
new_keys.append(key)
|
||||
if key not in dest:
|
||||
dest[key] = value
|
||||
if filename.endswith("options.yaml"):
|
||||
logging.info(f"Warning: {filename} is missing {'.'.join(new_keys)}")
|
||||
elif isinstance(value, dict):
|
||||
if not isinstance(dest.get(key, None), dict):
|
||||
if filename.endswith("options.yaml"):
|
||||
logging.info(f"Warning: {filename} has {'.'.join(new_keys)}, but it is not a dictionary. overwriting.")
|
||||
dest[key] = value
|
||||
else:
|
||||
dest[key] = update_options(value, dest[key], filename, new_keys)
|
||||
return dest
|
||||
|
||||
def get_options() -> dict:
|
||||
if not hasattr(get_options, "options"):
|
||||
|
@ -233,14 +250,7 @@ def get_options() -> dict:
|
|||
with open(location) as f:
|
||||
options = parse_yaml(f.read())
|
||||
|
||||
default_options = get_default_options()
|
||||
for key, value in options.items():
|
||||
if isinstance(value, dict):
|
||||
for key2, value2 in value.items():
|
||||
default_options[key][key2] = value2
|
||||
else:
|
||||
default_options[key] = value
|
||||
get_options.options = default_options
|
||||
get_options.options = update_options(get_default_options(), options, location, list())
|
||||
break
|
||||
else:
|
||||
raise FileNotFoundError(f"Could not find {locations[1]} to load options.")
|
||||
|
|
Loading…
Reference in New Issue