Switch from zip to tar, fix prep
This commit is contained in:
63
prep
Normal file → Executable file
63
prep
Normal file → Executable file
@@ -1,16 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Prepare local mods, zip them, generate config, and commit."""
|
||||
"""Prepare local mods, tar 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")
|
||||
AUTOGEN = os.path.join(BASE, "scripts", "autogen_config.py")
|
||||
LOCALMODS_DIR = os.path.join(BASE, "LocalMods")
|
||||
ZIP_PATH = os.path.join(BASE, "LocalMods.zip")
|
||||
TAR_PATH = os.path.join(BASE, "LocalMods.tar.gz")
|
||||
|
||||
|
||||
def log_ok(msg):
|
||||
@@ -22,65 +21,37 @@ def log_info(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("║ Prep: mods → tar → commit ║")
|
||||
print("╚════════════════════════════════════╝")
|
||||
print()
|
||||
|
||||
# 1. Run prepare_local
|
||||
log_info("Step 1: Copy mods from workshop...")
|
||||
run([sys.executable, PREPARE_LOCAL])
|
||||
log_info("Step 1/4: Copy mods from workshop...")
|
||||
subprocess.run([sys.executable, PREPARE_LOCAL], check=True)
|
||||
log_ok("LocalMods ready")
|
||||
print()
|
||||
|
||||
# 2. Zip LocalMods
|
||||
log_info("Step 2: Zipping LocalMods/...")
|
||||
zip_localmods()
|
||||
log_info("Step 2/4: Taring LocalMods/...")
|
||||
if os.path.exists(TAR_PATH):
|
||||
os.remove(TAR_PATH)
|
||||
subprocess.run(["tar", "-czf", TAR_PATH, "-C", BASE, "LocalMods"], check=True)
|
||||
size = os.path.getsize(TAR_PATH)
|
||||
log_ok(f"Created {TAR_PATH} ({size / 1024:.1f} KB)")
|
||||
print()
|
||||
|
||||
# 3. Run autogen_config
|
||||
log_info("Step 3: Generating config_player.xml...")
|
||||
run([sys.executable, AUTOGEN])
|
||||
log_info("Step 3/4: Generating config_player.xml...")
|
||||
subprocess.run([sys.executable, AUTOGEN], check=True)
|
||||
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_info("Step 4/4: Committing...")
|
||||
subprocess.run(["git", "add", "-A"], cwd=BASE, check=True)
|
||||
subprocess.run(["git", "commit", "-m", msg], cwd=BASE, check=True)
|
||||
log_ok(f"Committed: {msg}")
|
||||
print()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user