23 lines
1.1 KiB
Python
23 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Run anim_cap.lua captures in parallel. usage: anim_run.py NAME POWER [KEY=VAL ...] | --batch FILE
|
|
Outputs to re/runs/anim/<NAME>/."""
|
|
import os, subprocess, sys, concurrent.futures as cf
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
DEF = {'TBG_LIB': f'{ROOT}/re/lua/battle_lib.lua', 'TBG_LOAD': f'{ROOT}/re/runs/battle_mid/state.mss'}
|
|
|
|
def run(spec):
|
|
name, power, *kv = spec
|
|
out = f'{ROOT}/re/runs/anim/{name}'
|
|
os.makedirs(out, exist_ok=True)
|
|
env = dict(os.environ, **DEF, TBG_OUT=out, TBG_POWER=power)
|
|
for x in kv:
|
|
k, v = x.split('=', 1); env[k] = v
|
|
r = subprocess.run([f'{ROOT}/re/mesen.sh', f'{ROOT}/re/lua/anim_cap.lua'], env=env, capture_output=True, text=True, timeout=1800)
|
|
return name, r.returncode
|
|
|
|
if __name__ == '__main__':
|
|
specs = [l.split() for l in open(sys.argv[2]) if l.strip() and not l.startswith('#')] if sys.argv[1] == '--batch' else [sys.argv[1:]]
|
|
with cf.ThreadPoolExecutor(int(os.environ.get('JOBS', '8'))) as ex:
|
|
for name, rc in ex.map(run, specs):
|
|
print(name, rc, flush=True)
|