"""ev.py COMMENT KEY LITERAL: adds KEY: LITERAL (a dict of animation: events) to rebirth_art.py's ENTITY_EVENTS, after a comment line (run from the repository root; replaces an existing entry of KEY).""" import re, sys comment, key, literal = sys.argv[1:4] p = 'tools/rebirth_art.py'; s = open(p).read() anchor = " 'visage_plasma': {'Idle': ('Start', 1)},\n" assert anchor in s s = re.sub(r" # [^\n]*\n '%s': [^\n]*\n" % re.escape(key), '', s) s = s.replace(anchor, anchor + f" # {comment}\n '{key}': {literal},\n", 1) open(p, 'w').write(s) compile(s, p, 'exec')