From 8ce76143247f99b25e8da5ace81df6882a17db30 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 23 Nov 2022 08:58:03 +0100 Subject: 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 Reviewed-by: Adrian Herrmann Reviewed-by: Christian Tismer --- tools/snippets_translate/main.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'tools/snippets_translate/main.py') 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 -- cgit v1.2.3