From 2f0656ee6ca8283e543d32aecb2d3675ec6b17a1 Mon Sep 17 00:00:00 2001 From: Benedikt Werner <1benediktwerner@gmail.com> Date: Fri, 18 Dec 2020 18:14:22 +0100 Subject: [PATCH] Update create_release.py --- .gitignore | 1 + create_release.py | 74 +++++++++++++++++++---------------------------- 2 files changed, 30 insertions(+), 45 deletions(-) diff --git a/.gitignore b/.gitignore index a82d67b..57e756f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ bin obj .vs PostBuild.bat +releases diff --git a/create_release.py b/create_release.py index 0194b04..3aebf42 100644 --- a/create_release.py +++ b/create_release.py @@ -1,52 +1,36 @@ #!/usr/bin/env python3 -import os, json, zipfile +import os, zipfile, shutil + +mods = [ + "BetterLevelEditor", + "Convinience", + "D1CooperGun", + "DevKillsList", + "ExtendedCheats", + "KingsmanEasterEgg", + "ShowdownModePauseOnDesperadoDiff", +] - -GAME_DIR = "/mnt/g/Steam/steamapps/common/Desperados III/Mods/" RELEASES_DIR = "releases" -SCRIPT_DIR = os.path.dirname(__file__) -RELEASES_DIR = os.path.join(SCRIPT_DIR, RELEASES_DIR) -REPO_FILE = os.path.join(SCRIPT_DIR, "Repository.json") - - -if not os.path.isfile(REPO_FILE): - print("No 'Repository.json' file found") - exit(-1) -elif not os.path.isdir(GAME_DIR): - print(f"No game direcotry found at '{GAME_DIR}'") - exit(-1) - - -with open(REPO_FILE) as f: - repo = json.load(f) - - os.makedirs("releases", exist_ok=True) - -for mod in repo["Releases"]: - name = mod["Id"] - mod_dir = os.path.join(GAME_DIR, name) - - if not os.path.isdir(mod_dir): - print(f"No mod directory found for '{name}' at '{mod_dir}'. Skipping.") - continue - - dll = os.path.join(mod_dir, name + ".dll") - info = os.path.join(SCRIPT_DIR, name, "Info.json") - - if not os.path.isfile(dll): - print(f"No DLL found for '{name}' at '{dll}'. Skipping.") - continue - - if not os.path.isfile(info): - print(f"No 'Info.json' found for '{name}' at '{info}'. Skipping.") - continue - - with zipfile.ZipFile( - os.path.join(RELEASES_DIR, name + ".zip"), "w", zipfile.ZIP_DEFLATED - ) as zipf: - zipf.write(dll, name + ".dll") - zipf.write(info, "Info.json") +for mod in mods: + dll = os.path.join(mod, "bin", "Release" , mod + ".dll") + if mod == "BetterLevelEditor": + files = [] + files.append((dll, mod + ".dll")) + files.append((os.path.join(mod, "spawn_codes.txt"), "spawn_codes.txt")) + + for f, _ in files: + if not os.path.isfile(f): + print(f"{mod}: {f} not found. Skipping") + break + else: + outfile = os.path.join(RELEASES_DIR, mod + ".zip") + with zipfile.ZipFile(outfile, "w", zipfile.ZIP_DEFLATED) as zipf: + for f, n in files: + zipf.write(f, n) + else: + shutil.copy(dll, RELEASES_DIR)