mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-05 19:08:12 +00:00
rename_symbols: only write new file if contents have changed
Also don't stop for other exceptions, just print them and keep going
This commit is contained in:
@@ -78,11 +78,15 @@ def create_substring_regex_from_replacements(replacements):
|
|||||||
def replace_symbols_in_file(file, regex, replacements):
|
def replace_symbols_in_file(file, regex, replacements):
|
||||||
try:
|
try:
|
||||||
with file.open("r", encoding="UTF-8", newline="") as rfp:
|
with file.open("r", encoding="UTF-8", newline="") as rfp:
|
||||||
contents = regex.sub(lambda mo: replacements[mo.string[mo.start():mo.end()]], rfp.read())
|
original = rfp.read()
|
||||||
with file.open("w", encoding="UTF-8", newline="") as wfp:
|
contents = regex.sub(lambda mo: replacements[mo.string[mo.start():mo.end()]], original)
|
||||||
wfp.write(contents)
|
if contents != original:
|
||||||
|
with file.open("w", encoding="UTF-8", newline="") as wfp:
|
||||||
|
wfp.write(contents)
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
print("%s is not text, skipping" % file)
|
print("%s is not text, skipping" % file)
|
||||||
|
except Exception as err:
|
||||||
|
print("%s" % err)
|
||||||
|
|
||||||
|
|
||||||
def replace_symbols_in_dir(path, regex, replacements):
|
def replace_symbols_in_dir(path, regex, replacements):
|
||||||
|
Reference in New Issue
Block a user