Fix export of logfiles (#1794)

This commit is contained in:
Ozzieisaacs 2021-01-02 20:38:11 +01:00
parent 9e1cdd8f57
commit 4578af7a6d

View File

@ -21,7 +21,12 @@ import shutil
import glob import glob
import zipfile import zipfile
import json import json
import io from io import BytesIO
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
import os import os
from flask import send_file from flask import send_file
@ -32,11 +37,12 @@ from .about import collect_stats
log = logger.create() log = logger.create()
def assemble_logfiles(file_name): def assemble_logfiles(file_name):
log_list = glob.glob(file_name + '*') log_list = sorted(glob.glob(file_name + '*'), reverse=True)
wfd = io.StringIO() wfd = StringIO()
for f in log_list: for f in log_list:
with open(f, 'r') as fd: with open(f, 'r') as fd:
shutil.copyfileobj(fd, wfd) shutil.copyfileobj(fd, wfd)
wfd.seek(0)
return send_file(wfd, return send_file(wfd,
as_attachment=True, as_attachment=True,
attachment_filename=os.path.basename(file_name)) attachment_filename=os.path.basename(file_name))
@ -47,7 +53,7 @@ def send_debug():
for element in [logger.LOG_TO_STDOUT, logger.LOG_TO_STDERR]: for element in [logger.LOG_TO_STDOUT, logger.LOG_TO_STDERR]:
if element in file_list: if element in file_list:
file_list.remove(element) file_list.remove(element)
memory_zip = io.BytesIO() memory_zip = BytesIO()
with zipfile.ZipFile(memory_zip, 'w', compression=zipfile.ZIP_DEFLATED) as zf: with zipfile.ZipFile(memory_zip, 'w', compression=zipfile.ZIP_DEFLATED) as zf:
zf.writestr('settings.txt', json.dumps(config.toDict())) zf.writestr('settings.txt', json.dumps(config.toDict()))
zf.writestr('libs.txt', json.dumps(collect_stats())) zf.writestr('libs.txt', json.dumps(collect_stats()))