Core: "Build APWorlds" cleanup (#5507)
* allow filtered build, subprocess * component description * correct name * move back to running directly
This commit is contained in:
@@ -244,17 +244,32 @@ icon_paths = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if not is_frozen():
|
if not is_frozen():
|
||||||
def _build_apworlds():
|
def _build_apworlds(*launch_args: str):
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
from worlds import AutoWorldRegister
|
from worlds import AutoWorldRegister
|
||||||
from worlds.Files import APWorldContainer
|
from worlds.Files import APWorldContainer
|
||||||
|
from Launcher import open_folder
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
parser = argparse.ArgumentParser("Build script for APWorlds")
|
||||||
|
parser.add_argument("worlds", type=str, default=(), nargs="*", help="Names of APWorlds to build.")
|
||||||
|
args = parser.parse_args(launch_args)
|
||||||
|
|
||||||
|
if args.worlds:
|
||||||
|
games = [(game, AutoWorldRegister.world_types.get(game, None)) for game in args.worlds]
|
||||||
|
else:
|
||||||
|
games = [(worldname, worldtype) for worldname, worldtype in AutoWorldRegister.world_types.items()
|
||||||
|
if not worldtype.zip_path]
|
||||||
|
|
||||||
apworlds_folder = os.path.join("build", "apworlds")
|
apworlds_folder = os.path.join("build", "apworlds")
|
||||||
os.makedirs(apworlds_folder, exist_ok=True)
|
os.makedirs(apworlds_folder, exist_ok=True)
|
||||||
for worldname, worldtype in AutoWorldRegister.world_types.items():
|
for worldname, worldtype in games:
|
||||||
|
if not worldtype:
|
||||||
|
logging.error(f"Requested APWorld \"{worldname}\" does not exist.")
|
||||||
|
continue
|
||||||
file_name = os.path.split(os.path.dirname(worldtype.__file__))[1]
|
file_name = os.path.split(os.path.dirname(worldtype.__file__))[1]
|
||||||
world_directory = os.path.join("worlds", file_name)
|
world_directory = os.path.join("worlds", file_name)
|
||||||
if os.path.isfile(os.path.join(world_directory, "archipelago.json")):
|
if os.path.isfile(os.path.join(world_directory, "archipelago.json")):
|
||||||
@@ -269,12 +284,15 @@ if not is_frozen():
|
|||||||
apworld.manifest_path = f"{file_name}/archipelago.json"
|
apworld.manifest_path = f"{file_name}/archipelago.json"
|
||||||
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED,
|
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED,
|
||||||
compresslevel=9) as zf:
|
compresslevel=9) as zf:
|
||||||
for path in pathlib.Path(world_directory).rglob("*.*"):
|
for path in pathlib.Path(world_directory).rglob("*"):
|
||||||
relative_path = os.path.join(*path.parts[path.parts.index("worlds") + 1:])
|
relative_path = os.path.join(*path.parts[path.parts.index("worlds") + 1:])
|
||||||
if "__MACOSX" in relative_path or ".DS_STORE" in relative_path or "__pycache__" in relative_path:
|
if "__MACOSX" in relative_path or ".DS_STORE" in relative_path or "__pycache__" in relative_path:
|
||||||
continue
|
continue
|
||||||
if not relative_path.endswith("archipelago.json"):
|
if not relative_path.endswith("archipelago.json"):
|
||||||
zf.write(path, relative_path)
|
zf.write(path, relative_path)
|
||||||
zf.writestr(apworld.manifest_path, json.dumps(manifest))
|
zf.writestr(apworld.manifest_path, json.dumps(manifest))
|
||||||
|
open_folder(apworlds_folder)
|
||||||
|
|
||||||
components.append(Component('Build apworlds', func=_build_apworlds, cli=True,))
|
|
||||||
|
components.append(Component('Build APWorlds', func=_build_apworlds, cli=True,
|
||||||
|
description="Build APWorlds from loose-file world folders."))
|
||||||
|
|||||||
Reference in New Issue
Block a user