papermario/tools/rename.py

29 lines
869 B
Python
Raw Normal View History

2020-11-29 17:52:16 +01:00
#!/usr/bin/python3
import argparse
import os
import re
script_dir = os.path.dirname(os.path.realpath(__file__))
root_dir = script_dir + "/../"
src_dir = root_dir + "src/"
asm_dir = root_dir + "ver/current/asm/"
2020-11-29 17:52:16 +01:00
2021-01-09 10:49:15 +01:00
with open(os.path.join(script_dir, "duplicate_renames.txt")) as f:
2020-11-29 17:52:16 +01:00
renames_text = f.readlines()
for root, dirs, files in os.walk(asm_dir):
for f_name in files:
if f_name.endswith(".s"):
f_path = os.path.join(root, f_name)
with open(f_path) as f:
f_text_orig = f.read()
f_text = f_text_orig
for rename_text in renames_text:
2021-01-09 10:49:15 +01:00
r_from, r_to = rename_text.rstrip().split(",")
2020-11-29 17:52:16 +01:00
f_text = f_text.replace(r_from, r_to)
if f_text != f_text_orig:
with open(f_path, "w", newline="\n") as f:
f.write(f_text)