forked from ScoDoc/DocScoDoc
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.
|
||||
|
||||
"""
|
||||
import chardet
|
||||
import datetime
|
||||
import glob
|
||||
import mimetypes
|
||||
@ -203,8 +204,16 @@ class BaseArchiver(object):
|
||||
def get_archive_description(self, archive_id):
|
||||
"""Return description of archive"""
|
||||
self.initialize()
|
||||
with open(os.path.join(archive_id, "_description.txt")) as f:
|
||||
filename = os.path.join(archive_id, "_description.txt")
|
||||
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
|
||||
|
||||
def create_obj_archive(self, oid: int, description: str):
|
||||
|
Loading…
Reference in New Issue
Block a user