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 ''' -# -# -#
-# -# -#