92 lines
2.6 KiB
Python
92 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Prepare local mods, zip them, generate config, and commit."""
|
|
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
BASE = os.path.dirname(os.path.abspath(__file__))
|
|
SCRIPTS = os.path.join(BASE, "scripts")
|
|
PREPARE_LOCAL = os.path.join(BASE, "prepare_local")
|
|
AUTOGEN = os.path.join(SCRIPTS, "autogen_config.py")
|
|
LOCALMODS_DIR = os.path.join(BASE, "LocalMods")
|
|
ZIP_PATH = os.path.join(BASE, "LocalMods.zip")
|
|
|
|
|
|
def log_ok(msg):
|
|
print(f"\033[92m✓\033[0m {msg}")
|
|
|
|
def log_info(msg):
|
|
print(f"• {msg}")
|
|
|
|
def log_err(msg):
|
|
print(f"\033[91m✗\033[0m {msg}", file=sys.stderr)
|
|
|
|
def run(cmd, cwd=None):
|
|
result = subprocess.run(cmd, cwd=cwd, capture_output=True, text=True)
|
|
if result.returncode != 0:
|
|
print(result.stdout)
|
|
print(result.stderr, file=sys.stderr)
|
|
sys.exit(result.returncode)
|
|
return result.stdout.strip()
|
|
|
|
|
|
def zip_localmods():
|
|
import zipfile
|
|
log_info(f"Zipping {LOCALMODS_DIR} → {ZIP_PATH}")
|
|
|
|
if os.path.exists(ZIP_PATH):
|
|
os.remove(ZIP_PATH)
|
|
|
|
count = 0
|
|
with zipfile.ZipFile(ZIP_PATH, "w", zipfile.ZIP_DEFLATED) as zf:
|
|
for root, dirs, files in os.walk(LOCALMODS_DIR):
|
|
for fn in files:
|
|
full = os.path.join(root, fn)
|
|
arcname = os.path.relpath(full, BASE)
|
|
zf.write(full, arcname)
|
|
count += 1
|
|
|
|
size = os.path.getsize(ZIP_PATH)
|
|
log_ok(f"Zipped {count} files ({size / 1024:.1f} KB)")
|
|
|
|
|
|
def main():
|
|
msg = " ".join(sys.argv[1:]) if len(sys.argv) > 1 else "Update LocalMods"
|
|
|
|
print()
|
|
print("╔════════════════════════════════════╗")
|
|
print("║ Prep: mods → zip → commit ║")
|
|
print("╚════════════════════════════════════╝")
|
|
print()
|
|
|
|
# 1. Run prepare_local
|
|
log_info("Step 1: Copy mods from workshop...")
|
|
run([sys.executable, PREPARE_LOCAL])
|
|
log_ok("LocalMods ready")
|
|
print()
|
|
|
|
# 2. Zip LocalMods
|
|
log_info("Step 2: Zipping LocalMods/...")
|
|
zip_localmods()
|
|
print()
|
|
|
|
# 3. Run autogen_config
|
|
log_info("Step 3: Generating config_player.xml...")
|
|
run([sys.executable, AUTOGEN])
|
|
log_ok("config_player.xml generated")
|
|
print()
|
|
|
|
# 4. Git add and commit (no push)
|
|
log_info("Step 4: Committing...")
|
|
run(["git", "add", "-A"], cwd=BASE)
|
|
run(["git", "commit", "-m", msg], cwd=BASE)
|
|
log_ok(f"Committed: {msg}")
|
|
print()
|
|
|
|
log_ok("Done. Push manually when ready.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|