1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-05 05:04:43 +00:00

dirty fix for text files with bad char

This commit is contained in:
deadc0de6
2017-03-09 15:11:06 +01:00
parent 8f6b58bcac
commit 6ea90ee1d6
2 changed files with 13 additions and 2 deletions

View File

@@ -43,7 +43,13 @@ class Templategen:
def _handle_text_file(self, src, profile):
l = len(self.base) + 1
template = self.env.get_template(src[l:])
try:
template = self.env.get_template(src[l:])
content = template.render(profile=profile)
except UnicodeDecodeError:
data = self._read_bad_encoded_text(src)
template = self.env.from_string(data)
content = template.render(profile=profile)
content = content.encode('UTF-8')
return content
@@ -54,3 +60,8 @@ class Templategen:
src = os.path.join(self.base, src)
with open(src, 'rb') as f:
return f.read()
def _read_bad_encoded_text(self, path):
with open(path, 'rb') as f:
data = f.read()
return data.decode('utf-8', 'replace')

View File

@@ -18,7 +18,7 @@ def run(cmd, log=False, raw=True):
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if raw:
return p.stdout.readlines()
return ''.join([x.decode("utf-8") for x in p.stdout.readlines()])
return ''.join([x.decode('utf-8', 'replace') for x in p.stdout.readlines()])
def diff(src, dst, log=False, raw=True):