forked from ScoDoc/ScoDoc
Fix: read non-utf8 archives index
This commit is contained in:
parent
848a168f02
commit
3eda56e89c
@ -47,6 +47,7 @@
|
|||||||
qui est une description (humaine, format libre) de l'archive.
|
qui est une description (humaine, format libre) de l'archive.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
import chardet
|
||||||
import datetime
|
import datetime
|
||||||
import glob
|
import glob
|
||||||
import mimetypes
|
import mimetypes
|
||||||
@ -203,8 +204,16 @@ class BaseArchiver(object):
|
|||||||
def get_archive_description(self, archive_id):
|
def get_archive_description(self, archive_id):
|
||||||
"""Return description of archive"""
|
"""Return description of archive"""
|
||||||
self.initialize()
|
self.initialize()
|
||||||
with open(os.path.join(archive_id, "_description.txt")) as f:
|
filename = os.path.join(archive_id, "_description.txt")
|
||||||
descr = f.read()
|
try:
|
||||||
|
with open(filename) as f:
|
||||||
|
descr = f.read()
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
# some (old) files may have saved under exotic encodings
|
||||||
|
with open(filename, "rb") as f:
|
||||||
|
data = f.read()
|
||||||
|
descr = data.decode(chardet.detect(data)["encoding"])
|
||||||
|
|
||||||
return descr
|
return descr
|
||||||
|
|
||||||
def create_obj_archive(self, oid: int, description: str):
|
def create_obj_archive(self, oid: int, description: str):
|
||||||
|
Loading…
Reference in New Issue
Block a user