Fix utf-8 convertion
This commit is contained in:
@@ -387,11 +387,6 @@ class WOFileUtils():
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def writeConversion(self, file):
|
|
||||||
with codecs.open('tmp' + '/' + file, 'w', 'utf-8') as targetFile:
|
|
||||||
for line in file:
|
|
||||||
targetFile.write(line)
|
|
||||||
|
|
||||||
def convertFileBestGuess(self, filename, filepath):
|
def convertFileBestGuess(self, filename, filepath):
|
||||||
"""Convert file to utf-8"""
|
"""Convert file to utf-8"""
|
||||||
sourceFormats = ['ascii', 'iso-8859-1']
|
sourceFormats = ['ascii', 'iso-8859-1']
|
||||||
@@ -399,8 +394,11 @@ class WOFileUtils():
|
|||||||
try:
|
try:
|
||||||
os.chdir(filepath)
|
os.chdir(filepath)
|
||||||
with codecs.open(filename, 'rU', format) as sourceFile:
|
with codecs.open(filename, 'rU', format) as sourceFile:
|
||||||
self.writeConversion(sourceFile)
|
with codecs.open(
|
||||||
return
|
'tmp' + '/' + sourceFile, 'w', 'utf-8') as targetFile:
|
||||||
|
for line in sourceFile:
|
||||||
|
targetFile.write(line)
|
||||||
|
return
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
pass
|
pass
|
||||||
if os.path.exists("/tmp/{0}".format(filename)):
|
if os.path.exists("/tmp/{0}".format(filename)):
|
||||||
|
|||||||
Reference in New Issue
Block a user