2020-11-15 13:19:25 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
|
|
|
|
# Copyright (C) 2012-2019 cervinko, idalin, SiphonSquirrel, ouzklcn, akushsky,
|
|
|
|
# OzzieIsaacs, bodybybuddha, jkrehm, matthazinski, janeczku
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import shutil
|
|
|
|
import glob
|
|
|
|
import zipfile
|
|
|
|
import json
|
2021-01-02 19:38:11 +00:00
|
|
|
from io import BytesIO
|
2022-06-08 18:25:35 +00:00
|
|
|
from flask_babel.speaklater import LazyString
|
2021-01-02 19:38:11 +00:00
|
|
|
|
2020-11-15 13:19:25 +00:00
|
|
|
import os
|
|
|
|
|
2021-06-05 16:41:42 +00:00
|
|
|
from flask import send_file, __version__
|
2020-11-15 13:19:25 +00:00
|
|
|
|
|
|
|
from . import logger, config
|
|
|
|
from .about import collect_stats
|
|
|
|
|
|
|
|
log = logger.create()
|
|
|
|
|
2022-06-08 18:25:35 +00:00
|
|
|
class lazyEncoder(json.JSONEncoder):
|
|
|
|
def default(self, obj):
|
|
|
|
if isinstance(obj, LazyString):
|
|
|
|
return str(obj)
|
|
|
|
# Let the base class default method raise the TypeError
|
|
|
|
return json.JSONEncoder.default(self, obj)
|
2022-05-21 20:52:59 +00:00
|
|
|
|
2020-11-15 13:19:25 +00:00
|
|
|
def assemble_logfiles(file_name):
|
2021-01-02 19:38:11 +00:00
|
|
|
log_list = sorted(glob.glob(file_name + '*'), reverse=True)
|
2021-07-12 15:33:35 +00:00
|
|
|
wfd = BytesIO()
|
2020-11-15 13:19:25 +00:00
|
|
|
for f in log_list:
|
2021-07-12 15:33:35 +00:00
|
|
|
with open(f, 'rb') as fd:
|
2020-11-15 13:19:25 +00:00
|
|
|
shutil.copyfileobj(fd, wfd)
|
2021-01-02 19:38:11 +00:00
|
|
|
wfd.seek(0)
|
2021-06-05 16:41:42 +00:00
|
|
|
if int(__version__.split('.')[0]) < 2:
|
|
|
|
return send_file(wfd,
|
|
|
|
as_attachment=True,
|
|
|
|
attachment_filename=os.path.basename(file_name))
|
|
|
|
else:
|
|
|
|
return send_file(wfd,
|
|
|
|
as_attachment=True,
|
|
|
|
download_name=os.path.basename(file_name))
|
|
|
|
|
2020-11-15 13:19:25 +00:00
|
|
|
|
|
|
|
def send_debug():
|
|
|
|
file_list = glob.glob(logger.get_logfile(config.config_logfile) + '*')
|
|
|
|
file_list.extend(glob.glob(logger.get_accesslogfile(config.config_access_logfile) + '*'))
|
2020-12-12 09:02:11 +00:00
|
|
|
for element in [logger.LOG_TO_STDOUT, logger.LOG_TO_STDERR]:
|
|
|
|
if element in file_list:
|
|
|
|
file_list.remove(element)
|
2021-01-02 19:38:11 +00:00
|
|
|
memory_zip = BytesIO()
|
2020-11-15 13:19:25 +00:00
|
|
|
with zipfile.ZipFile(memory_zip, 'w', compression=zipfile.ZIP_DEFLATED) as zf:
|
2022-07-02 15:45:24 +00:00
|
|
|
zf.writestr('settings.txt', json.dumps(config.to_dict(), sort_keys=True, indent=2))
|
2022-06-08 18:25:35 +00:00
|
|
|
zf.writestr('libs.txt', json.dumps(collect_stats(), sort_keys=True, indent=2, cls=lazyEncoder))
|
2020-11-15 13:19:25 +00:00
|
|
|
for fp in file_list:
|
|
|
|
zf.write(fp, os.path.basename(fp))
|
|
|
|
memory_zip.seek(0)
|
2021-06-05 16:41:42 +00:00
|
|
|
if int(__version__.split('.')[0]) < 2:
|
|
|
|
return send_file(memory_zip,
|
|
|
|
as_attachment=True,
|
|
|
|
attachment_filename="Calibre-Web-debug-pack.zip")
|
|
|
|
else:
|
|
|
|
return send_file(memory_zip,
|
|
|
|
as_attachment=True,
|
|
|
|
download_name="Calibre-Web-debug-pack.zip")
|