dump fichier en erreur pour debug

This commit is contained in:
Emmanuel Viennet 2021-09-28 07:22:23 +02:00
parent 550a7888bf
commit f5529ec4a6
1 changed files with 13 additions and 8 deletions

View File

@ -567,23 +567,27 @@ def excel_bytes_to_list(bytes_content):
filelike = io.BytesIO(bytes_content) filelike = io.BytesIO(bytes_content)
return _excel_to_list(filelike) return _excel_to_list(filelike)
except: except:
raise ScoValueError(""" raise ScoValueError(
"""
scolars_import_excel_file: un contenu xlsx semble corrompu! scolars_import_excel_file: un contenu xlsx semble corrompu!
peut-être avez vous fourni un fichier au mauvais format (txt, xls, ..) peut-être avez vous fourni un fichier au mauvais format (txt, xls, ..)
""") """
)
def excel_file_to_list(filename): def excel_file_to_list(filename):
try: try:
return _excel_to_list(filename) return _excel_to_list(filename)
except: except:
raise ScoValueError(""" raise ScoValueError(
scolars_import_excel_file: un contenu xlsx semble corrompu! """scolars_import_excel_file: un contenu xlsx
peut-être avez vous fourni un fichier au mauvais format (txt, xls, ..) semble corrompu !
""") Peut-être avez-vous fourni un fichier au mauvais format (txt, xls, ...)
"""
)
def _excel_to_list(filelike): # we may need 'encoding' argument ? def _excel_to_list(filelike):
"""returns list of list """returns list of list
convert_to_string is a conversion function applied to all non-string values (ie numbers) convert_to_string is a conversion function applied to all non-string values (ie numbers)
""" """
@ -591,7 +595,8 @@ def _excel_to_list(filelike): # we may need 'encoding' argument ?
wb = load_workbook(filename=filelike, read_only=True, data_only=True) wb = load_workbook(filename=filelike, read_only=True, data_only=True)
except: except:
log("Excel_to_list: failure to import document") log("Excel_to_list: failure to import document")
open("/tmp/last_scodoc_import_failure" + scu.XLSX_SUFFIX, "wb").write(filelike) with open("/tmp/last_scodoc_import_failure" + scu.XLSX_SUFFIX, "wb") as f:
f.write(filelike)
raise ScoValueError( raise ScoValueError(
"Fichier illisible: assurez-vous qu'il s'agit bien d'un document Excel !" "Fichier illisible: assurez-vous qu'il s'agit bien d'un document Excel !"
) )