diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-11-23 08:58:03 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-11-23 15:14:02 +0000 |
commit | c9538c7cccf88e478e65af20610968df8de7d582 (patch) | |
tree | 1783b084e2e7d59a9cd4f373849c16d6759bd1c9 | |
parent | c139e78ad9edccecba241d26221fb622d774258d (diff) |
Fix snippets_translate on Windows, take 2
Fix another occurrence of opening a file.
Amends ed0f55c1d79636040843ae5c5e0d9308e35da65a.
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>
(cherry picked from commit 8ce76143247f99b25e8da5ace81df6882a17db30)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | tools/snippets_translate/main.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/tools/snippets_translate/main.py b/tools/snippets_translate/main.py index 91905f2a1..c8c2f30c3 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 |