Skip to content

Commit

Permalink
Update create_release.py
Browse files Browse the repository at this point in the history
  • Loading branch information
benediktwerner committed Dec 18, 2020
1 parent bdfa2ce commit 2f0656e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 45 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ bin
obj
.vs
PostBuild.bat
releases
74 changes: 29 additions & 45 deletions create_release.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 2f0656e

Please sign in to comment.