Fix:archives (again...)

This commit is contained in:
Emmanuel Viennet 2022-06-30 09:27:46 +02:00
parent 0fe89b0501
commit 0330544a0b

View File

@ -47,6 +47,7 @@
qui est une description (humaine, format libre) de l'archive.
"""
import chardet
import datetime
import glob
import json
@ -55,7 +56,7 @@ import os
import re
import shutil
import time
import chardet
from typing import Union
import flask
from flask import g, request
@ -232,14 +233,17 @@ class BaseArchiver(object):
os.mkdir(archive_id) # if exists, raises an OSError
finally:
scu.GSL.release()
self.store(archive_id, "_description.txt", description.encode("utf-8"))
self.store(archive_id, "_description.txt", description)
return archive_id
def store(self, archive_id: str, filename: str, data: bytes):
def store(self, archive_id: str, filename: str, data: Union[str, bytes]):
"""Store data in archive, under given filename.
Filename may be modified (sanitized): return used filename
The file is created or replaced.
data may be str or bytes
"""
if isinstance(data, str):
data = data.encode(scu.SCO_ENCODING)
self.initialize()
filename = scu.sanitize_filename(filename)
log("storing %s (%d bytes) in %s" % (filename, len(data), archive_id))
@ -350,13 +354,11 @@ def do_formsemestre_archive(
html_sco_header.sco_footer(),
]
)
data = data.encode(scu.SCO_ENCODING)
PVArchive.store(archive_id, "Tableau_moyennes.html", data)
# Bulletins en JSON
data = gen_formsemestre_recapcomplet_json(formsemestre_id, xml_with_decisions=True)
data_js = json.dumps(data, indent=1, cls=scu.ScoDocJSONEncoder)
data_js = data_js.encode(scu.SCO_ENCODING)
if data:
PVArchive.store(archive_id, "Bulletins.json", data_js)
# Decisions de jury, en XLS
@ -365,7 +367,7 @@ def do_formsemestre_archive(
PVArchive.store(
archive_id,
"Decisions_Jury" + scu.XLSX_SUFFIX,
data.encode(scu.SCO_ENCODING),
data,
)
# Classeur bulletins (PDF)
data, _ = sco_bulletins_pdf.get_formsemestre_bulletins_pdf(