From 4578af7a6d4f9c6f1bff660dd83c50712faed6ea Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sat, 2 Jan 2021 20:38:11 +0100 Subject: [PATCH] Fix export of logfiles (#1794) --- cps/debug_info.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cps/debug_info.py b/cps/debug_info.py index aae97001..8f0cdeee 100644 --- a/cps/debug_info.py +++ b/cps/debug_info.py @@ -21,7 +21,12 @@ import shutil import glob import zipfile import json -import io +from io import BytesIO +try: + from StringIO import StringIO +except ImportError: + from io import StringIO + import os from flask import send_file @@ -32,11 +37,12 @@ from .about import collect_stats log = logger.create() def assemble_logfiles(file_name): - log_list = glob.glob(file_name + '*') - wfd = io.StringIO() + log_list = sorted(glob.glob(file_name + '*'), reverse=True) + wfd = StringIO() for f in log_list: with open(f, 'r') as fd: shutil.copyfileobj(fd, wfd) + wfd.seek(0) return send_file(wfd, as_attachment=True, 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]: if element in file_list: file_list.remove(element) - memory_zip = io.BytesIO() + memory_zip = BytesIO() with zipfile.ZipFile(memory_zip, 'w', compression=zipfile.ZIP_DEFLATED) as zf: zf.writestr('settings.txt', json.dumps(config.toDict())) zf.writestr('libs.txt', json.dumps(collect_stats()))