aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-11-21 17:27:39 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-11-22 08:31:23 +0100
commited0f55c1d79636040843ae5c5e0d9308e35da65a (patch)
tree896b1e6e5e3d6946db9d706652c749df1e643dd4
parent04af2a4c48ea567f85e15b71c6c01fd244b5e063 (diff)
Fix snippets_translate on Windows
Force UTF-8 encoding. As a drive-by, use Pathlib methods. Complements 81d81baf0ef6c42ebdb6a2b2293d09031ce6dd5c. Pick-to: 6.4 Change-Id: Iccdb33429a030ec76dc55699b07210cd533ba7c2 Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--tools/snippets_translate/main.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/tools/snippets_translate/main.py b/tools/snippets_translate/main.py
index 0ee0b49ee..22fc292fb 100644
--- a/tools/snippets_translate/main.py
+++ b/tools/snippets_translate/main.py
@@ -311,10 +311,15 @@ def get_license_from_file(filename):
def translate_file(file_path, final_path, qt_path, debug, write):
- with open(str(file_path)) as f:
- lines = f.read().splitlines()
- rel_path = file_path.relative_to(qt_path)
- snippets = get_snippets(lines, rel_path)
+ snippets = []
+ try:
+ with file_path.open("r", encoding="utf-8") as f:
+ lines = f.read().splitlines()
+ rel_path = file_path.relative_to(qt_path)
+ snippets = get_snippets(lines, rel_path)
+ except Exception as e:
+ log.error(f"Error reading {file_path}: {e}")
+ raise
if snippets:
# TODO: Get license header first
license_header = get_license_from_file(str(file_path))
@@ -363,7 +368,7 @@ def translate_file(file_path, final_path, qt_path, debug, write):
log.info(f"Creating directories for {target_file.parent}")
target_file.parent.mkdir(parents=True, exist_ok=True)
- with target_file.open("w") as out_f:
+ with target_file.open("w", encoding="utf-8") as out_f:
out_f.write(license_header)
out_f.write("\n\n")