"""Writes surfaces_spearfish.py: surfaces_head.py (the Spearfish's sets and atlases) + the Manta's surfaces body (its helper functions and the run: UV layers, screens, bakes, node dressing; models/tender-manta/build/surfaces_manta.py from '# --- UV layers' to the end) with the names changed. Plain python: python build/make_surfaces.py""" import os HERE = os.path.dirname(os.path.abspath(__file__)) src = open(os.path.join(HERE, "..", "..", "tender-manta", "build", "surfaces_manta.py"), encoding="utf-8").read() a = src.index("# ------------------------------------------------------------------ UV layers") body = src[a:] for old, new in [("SM_Manta", "SM_Spearfish"), ('"MANTA | ', '"SPEARFISH | '), ('startswith("MANTA")', 'startswith("SPEARFISH")'), ("T_Manta_", "T_Spearfish_"), ("img[:] = (0.022, 0.011, 0.004)", "img[:] = (0.004, 0.012, 0.020)")]: assert old in body, old body = body.replace(old, new) assert "MANTA" not in body and "SM_Manta" not in body, [l for l in body.splitlines() if "MANTA" in l or "SM_Manta" in l] out = open(os.path.join(HERE, "surfaces_head.py"), encoding="utf-8").read() + body open(os.path.join(HERE, "surfaces_spearfish.py"), "w", encoding="utf-8").write(out) print("written", len(out.splitlines()), "lines")