diff --git a/src/applets/install/__pycache__/routes.cpython-313.pyc b/src/applets/install/__pycache__/routes.cpython-313.pyc index 7be89bb..bf059ee 100644 Binary files a/src/applets/install/__pycache__/routes.cpython-313.pyc and b/src/applets/install/__pycache__/routes.cpython-313.pyc differ diff --git a/src/applets/install/install.html b/src/applets/install/install.html index e1fa811..3184fc4 100644 --- a/src/applets/install/install.html +++ b/src/applets/install/install.html @@ -2,14 +2,48 @@ {% block body %}
-

Installing...


+

+ + Installing... + +

+ +
+
-

Installing system, the rest of the process is automated.

-

+

+ Installing system, the rest of the process is automated. +

+ +

+


+ +
+ + +
+ +
+ + +
+
+ +
-
Initializing...
+
+
Initializing...
+
diff --git a/src/applets/install/routes.py b/src/applets/install/routes.py index e7124b0..b343f2b 100644 --- a/src/applets/install/routes.py +++ b/src/applets/install/routes.py @@ -1,8 +1,20 @@ from applets.install import bp from flask import Flask, request, session, redirect, \ - url_for, render_template, flash, Blueprint + url_for, render_template, flash, Blueprint, jsonify from flask import current_app +import subprocess +import threading + + +status = { + "status": "idle", # idle | running | finished + "output": "", + "exit_code": None, + "lines": [] +} + + @bp.route('/install',methods=['GET', 'POST', 'PUT']) def install_index(): """ @@ -19,14 +31,74 @@ def install_start(): Trigger the installation process """ print("The installation process is starting!... in theory at least") + if status["status"] == "running": + return jsonify({"status": "already running"}), 409 # Conflict + threading.Thread(target=run_script).start() + return jsonify({"status": "started"}) + print("did it finish?") -@bp.route('/install-status',methods=['GET', 'POST', 'PUT']) +def run_script(): + global status + status["status"] = "running" + + process = subprocess.Popen( + ["bash", "/data/jonathan/devel/highvoltage/system-installer/daemon/src/fake-install-shell.sh"], + stdout = subprocess.PIPE, + stderr = subprocess.STDOUT, + text = True) + + lines = [] + for line in iter(process.stdout.readline,''): + #lines.append(line.strip()) + #status["output"] = "\n".join(lines) + status["lines"].append(line.strip()) + + process.wait() + status["status"] = 'finished' + status["exit_code"] = process.returncode + + print(lines) + print("status:", status["status"], "code:", status["exit_code"]) + + +@bp.route('/install/status', methods=['GET', 'POST']) def install_status(): """ Update on the status of the installation process. """ - print("installation en coers") + + # Keep track of the last line posted, so that we can include + # any new lines not provided to the UI yet + last_line = int(request.args.get("last_line", 0)) + new_lines = status["lines"][last_line:] + + if not new_lines and status["status"] == "finished": + return "" # Empty response = HTMX will stop polling + + lines_html = "" + for i, line in enumerate(new_lines, start=last_line + 1): + lines_html += f'
{line}
' + + return { + "output": status['output'], + "status": status['status'], + "lines": lines_html, + "last_line": f'' + } + + +@bp.route('/install/cancel', methods=["POST"]) +def install_cancel(): + """ + Cancel the installation process. + """ + if status["status"] != "running" or not status["process"]: + return Response("No running script", status=400) + process["process"].terminate() + process["status"] = "cancelled" + process["exit_code"] = -1 + return Response("Cancelled", status=200) @bp.route('/settings',methods=['GET', 'POST', 'PUT']) diff --git a/src/applets/main/routes.py b/src/applets/main/routes.py index 5cc9f5a..da1a1cf 100644 --- a/src/applets/main/routes.py +++ b/src/applets/main/routes.py @@ -1,5 +1,10 @@ -from applets.main import bp - +from applets.welcome import bp +from flask import Flask, request, session, redirect, \ + url_for, render_template, flash, Blueprint +# we use this neat little trick to get config data from the main app +from flask import current_app +import gettext +import dmm.lsblk as lsblk @bp.route('/') def index(): @@ -19,3 +24,26 @@ def apihome(): """ return ("0") + +@bp.route('/main/help',methods=['GET', 'POST', 'PUT']) +def main_welcome(): + """ + Manages the main help system. + """ + return render_template('help.html') + + +@bp.route('/main/quit',methods=['GET', 'POST', 'PUT']) +def main_quit(): + """ + Manages the quit dialog. + """ + return render_template('quit.html') + + +@bp.route('/main/menu',methods=['GET', 'POST', 'PUT']) +def main_menu(): + """ + Manages the main menu. + """ + return render_template('menu.html') diff --git a/src/applets/welcome/welcome.html b/src/applets/welcome/welcome.html index 59a095b..a9a6df7 100644 --- a/src/applets/welcome/welcome.html +++ b/src/applets/welcome/welcome.html @@ -11,7 +11,8 @@
- {{ string_dict['language_text'] }} + +{{ string_dict['language_text'] }}