mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-07 12:48:32 +00:00
dirty fix for text files with bad char
This commit is contained in:
@@ -43,7 +43,13 @@ class Templategen:
|
|||||||
|
|
||||||
def _handle_text_file(self, src, profile):
|
def _handle_text_file(self, src, profile):
|
||||||
l = len(self.base) + 1
|
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 = template.render(profile=profile)
|
||||||
content = content.encode('UTF-8')
|
content = content.encode('UTF-8')
|
||||||
return content
|
return content
|
||||||
@@ -54,3 +60,8 @@ class Templategen:
|
|||||||
src = os.path.join(self.base, src)
|
src = os.path.join(self.base, src)
|
||||||
with open(src, 'rb') as f:
|
with open(src, 'rb') as f:
|
||||||
return f.read()
|
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')
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ def run(cmd, log=False, raw=True):
|
|||||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||||
if raw:
|
if raw:
|
||||||
return p.stdout.readlines()
|
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):
|
def diff(src, dst, log=False, raw=True):
|
||||||
|
|||||||
Reference in New Issue
Block a user