From 8ea5146a2e98ce425b880d30fc56898e39cbb967 Mon Sep 17 00:00:00 2001 From: jonpas Date: Tue, 17 Dec 2019 20:17:22 +0100 Subject: [PATCH] Support zh-TW version update in make.py (UTF-8 encoding in file replace) --- tools/make.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/make.py b/tools/make.py index 9ffead03ba..f9f5706fc2 100644 --- a/tools/make.py +++ b/tools/make.py @@ -51,7 +51,7 @@ import traceback import time import timeit import re -import fileinput +from tempfile import mkstemp if sys.platform == "win32": import winreg @@ -582,9 +582,15 @@ def get_project_version(version_increments=[]): def replace_file(filePath, oldSubstring, newSubstring): - for line in fileinput.input(filePath, inplace=True): - # Use stdout directly, print() adds newlines automatically - sys.stdout.write(line.replace(oldSubstring,newSubstring)) + fh, absPath = mkstemp() + with open(absPath, "w", encoding="utf-8") as newFile: + with open(filePath, encoding="utf-8") as oldFile: + for line in oldFile: + newFile.write(line.replace(oldSubstring, newSubstring)) + + newFile.close() + os.remove(filePath) + shutil.move(absPath, filePath) def set_version_in_files(): @@ -603,7 +609,7 @@ def set_version_in_files(): try: # Save the file contents to a variable if the file exists if os.path.isfile(filePath): - f = open(filePath, "r+") + f = open(filePath, "r+", encoding="utf-8") fileText = f.read() f.close()