Minor fixes

This commit is contained in:
Ivan Kravets
2020-03-06 00:43:57 +02:00
parent 59e1c88726
commit 3ef96cb215
2 changed files with 14 additions and 14 deletions

View File

@ -18,6 +18,7 @@
from __future__ import absolute_import from __future__ import absolute_import
import hashlib import hashlib
import io
import os import os
import re import re
import sys import sys
@ -82,7 +83,7 @@ class LibBuilderFactory(object):
fname, piotool.SRC_BUILD_EXT + piotool.SRC_HEADER_EXT fname, piotool.SRC_BUILD_EXT + piotool.SRC_HEADER_EXT
): ):
continue continue
with open(join(root, fname)) as fp: with io.open(join(root, fname), errors="ignore") as fp:
content = fp.read() content = fp.read()
if not content: if not content:
continue continue

View File

@ -53,7 +53,7 @@ class InoToCPPConverter(object):
self._safe_encoding = None self._safe_encoding = None
def read_safe_contents(self, path): def read_safe_contents(self, path):
last_exc = None error_reported = False
for encoding in ( for encoding in (
"utf-8", "utf-8",
None, None,
@ -66,8 +66,9 @@ class InoToCPPConverter(object):
contents = fp.read() contents = fp.read()
self._safe_encoding = encoding self._safe_encoding = encoding
return contents return contents
except UnicodeDecodeError as e: except UnicodeDecodeError:
last_exc = e if not error_reported:
error_reported = True
click.secho( click.secho(
"Unicode decode error has occurred, please remove invalid " "Unicode decode error has occurred, please remove invalid "
"(non-ASCII or non-UTF8) characters from %s file or convert it to UTF-8" "(non-ASCII or non-UTF8) characters from %s file or convert it to UTF-8"
@ -75,9 +76,7 @@ class InoToCPPConverter(object):
fg="yellow", fg="yellow",
err=True, err=True,
) )
if last_exc: return ""
raise last_exc
return None
def write_safe_contents(self, path, contents): def write_safe_contents(self, path, contents):
with io.open( with io.open(