aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-11-23 08:58:03 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-11-23 12:31:55 +0100
commit8ce76143247f99b25e8da5ace81df6882a17db30 (patch)
treeac13bdf78c9c147c2d97a130d48b02a85af955eb
parent6f392052367e851bc4108e7b3578e03b6ec027cf (diff)
Fix snippets_translate on Windows, take 2
Fix another occurrence of opening a file. Amends ed0f55c1d79636040843ae5c5e0d9308e35da65a. Pick-to: 6.4 Change-Id: I7b1fa6068b620acafe51df539ad9379d922277b1 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Adrian Herrmann <adrian.herrmann@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--tools/snippets_translate/main.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/tools/snippets_translate/main.py b/tools/snippets_translate/main.py
index 22fc292fb..3c959dfda 100644
--- a/tools/snippets_translate/main.py
+++ b/tools/snippets_translate/main.py
@@ -286,16 +286,20 @@ def get_snippets(lines: List[str], rel_path: str) -> List[List[str]]:
def get_license_from_file(filename):
lines = []
- with open(filename, "r") as f:
- line = True
- while line:
- line = f.readline().rstrip()
-
- if line.startswith("/*") or line.startswith("**"):
- lines.append(line)
- # End of the comment
- if line.endswith("*/"):
- break
+ try:
+ with open(filename, "r", encoding="utf-8") as f:
+ line = True
+ while line:
+ line = f.readline().rstrip()
+
+ if line.startswith("/*") or line.startswith("**"):
+ lines.append(line)
+ # End of the comment
+ if line.endswith("*/"):
+ break
+ except Exception as e:
+ log.error(f"Error reading {filename}: {e}")
+ raise
if lines:
# We know we have the whole block, so we can
# perform replacements to translate the comment