diff --git a/root/app/calibre-web/cps/cwa_functions.py b/root/app/calibre-web/cps/cwa_functions.py index 020c99d..43a91f6 100644 --- a/root/app/calibre-web/cps/cwa_functions.py +++ b/root/app/calibre-web/cps/cwa_functions.py @@ -11,6 +11,9 @@ import os.path from time import sleep +import json +from threading import Thread + import sys sys.path.insert(1, '/app/calibre-web-automated/scripts/') from cwa_db import CWA_DB @@ -233,100 +236,38 @@ def cwa_flash_status(): return redirect(url_for('admin.admin')) -def flask_logger(): +def convert_library_start(): subprocess.Popen(['python3', '/app/calibre-web-automated/scripts/convert_library.py']) - if os.path.isfile("/config/convert-library.log") == False: - with open('/config/convert-library.log', 'w') as create_new_log: - pass - with open("/config/convert-library.log", 'r') as log_info: - while True: - data = log_info.read() - yield data.encode() - sleep(1) - if "FIN" in data: - break - -@convert_library.route("/cwa-library-convert", methods=["GET", "POST"]) -@login_required_if_no_ano -@admin_required -def cwa_library_convert(): - return Response(flask_logger(), mimetype="text/plain", content_type="text/event-stream") -# @convert_library.route("/convert-progress", methods=["GET"]) +@convert_library.route('/cwa-library-convert', methods=['GET']) +def start_conversion(): + t1 = Thread(target=convert_library_start) + t1.start() + return render_title_template('cwa_convert_library.html', title=_("Calibre-Web Automated - Convert Library"), page="cwa-library-convert") + +@convert_library.route('/convert-library-status', methods=['GET']) +def getStatus(): + with open("/config/convert-library.log", 'r') as f: + status = f.read() + statusList = {'status':status} + return json.dumps(statusList) + + +# def flask_logger(): +# subprocess.Popen(['python3', '/app/calibre-web-automated/scripts/convert_library.py']) +# if os.path.isfile("/config/convert-library.log") == False: +# with open('/config/convert-library.log', 'w') as create_new_log: +# pass +# with open("/config/convert-library.log", 'r') as log_info: +# while True: +# data = log_info.read() +# yield data.encode() +# sleep(1) +# if "FIN" in data: +# break + +# @convert_library.route("/cwa-library-convert", methods=["GET", "POST"]) # @login_required_if_no_ano # @admin_required -# def convert_progress(): -# # return render_title_template("cwa_convert_library.html", title=_("CWA Convert Library"), page="cwa-library-convert") -# def convert_progress(): -# return ''' -# -# -# -# -# -# Log Viewer -# -# -# -#

Log Viewer

-#
-# -# -# -# ''' \ No newline at end of file +# def cwa_library_convert(): +# return Response(flask_logger(), mimetype="text/plain", content_type="text/event-stream") \ No newline at end of file diff --git a/root/app/calibre-web/cps/templates/cwa_convert_library.html b/root/app/calibre-web/cps/templates/cwa_convert_library.html index 100020d..6d8007b 100644 --- a/root/app/calibre-web/cps/templates/cwa_convert_library.html +++ b/root/app/calibre-web/cps/templates/cwa_convert_library.html @@ -1,15 +1,5 @@ {% extends "layout.html" %} -{% block script %} - $(document).ready(function(){ - var output = document.getElementById('output'); - var xhr = new XMLHttpRequest(); - xhr.open('GET', '{{ url_for('convert_library.cwa_library_convert') }}', true); - xhr.send(); - setInterval(function() { - output.textContent = xhr.responseText; - }, 500); - }); -{% endblock %} + {% block body %}

{{title}}

@@ -17,9 +7,39 @@

{{title}}

CWA Library Convertor


-

+          

Loading...

{% endblock %} + +{% block js %} + +{% endblock %} diff --git a/scripts/convert_library.py b/scripts/convert_library.py index e12fb5c..d35aef3 100644 --- a/scripts/convert_library.py +++ b/scripts/convert_library.py @@ -15,7 +15,11 @@ logger = logging.getLogger(__name__) -logging.basicConfig(filename='/config/convert-library.log', level=logging.INFO, filemode='w') +LOG_FORMAT = '%(message)s' +logging.basicConfig(filename='/config/convert-library.log', + level=logging.INFO, + filemode='w', + format=LOG_FORMAT) def print_and_log(string) -> None: logging.info(string)