re-add yasi-applets

This commit is contained in:
Jonathan Carter
2025-08-23 22:33:58 +02:00
parent 69d6ba277d
commit 652bbba9c0
62 changed files with 1852 additions and 0 deletions

View File

@@ -0,0 +1,114 @@
from yasi_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
import dmm.timezone as timezone
# Set up Gettext
def set_language(LANG):
"""
Sets language for this applet
"""
translations = gettext.translation("welcome", './applets/welcome/locales',
fallback=True, languages=[LANG])
translations.install()
_ = translations.gettext
@bp.route('/welcome',methods=['GET', 'POST', 'PUT'])
def welcome_index():
"""
The page you'd get if you access the root of
this app in a browser.
"""
set_language(current_app.config['CONFIG']['settings']['language'])
if request.method == 'POST':
if "lang" in request.form.keys():
current_app.config['CONFIG']['settings']['language'] = request.form["lang"]
LANG = current_app.config['CONFIG']['settings']['language']
set_language(LANG)
FORMLANG = request.form["lang"]
if "keyboard" in request.form.keys():
print(request.form["keyboard"])
if "timezone" in request.form.keys():
print(request.form["timezone"])
global lang
lang = current_app.config['CONFIG']['settings']['language']
blkid = lsblk.list_scsi_devices()
string_dict = build_stringlist()
build_menu()
build_summary()
menu = current_app.config['CONFIG']['settings']['menu_order'].split(" ")
next_step_url = menu[menu.index("welcome")+1]
previous_step_url = menu[menu.index("welcome")-1]
print("index is: " , menu.index("welcome"))
if menu.index("welcome") == 0:
previous_step_url = False
else:
previous_step_url = menu[menu.index("users")-1]
print("next is: " + next_step_url)
print("previous is: " , previous_step_url)
power_button = '<button class="button is-dark"> <i class="fa fa-check" aria-hidden="true"></i> &nbsp; Power: AC </button>'
internet_button = '&nbsp; <button class="button is-dark"> <i class="fa fa-check" aria-hidden="true"></i> &nbsp; Internet </button>'
bottom_menu = power_button + internet_button
return render_template('welcome.html',
string_dict=string_dict, selected_lang=lang,
menu=current_app.config['CONFIG']['settings']['menu'],
menu_order=current_app.config['CONFIG']['settings']['menu_order'].split(),
timezones=timezone.list_timezones()[1].split("\n"),
previous_step=previous_step_url,
next_step=next_step_url,
bottom_menu=bottom_menu)
def build_stringlist():
"""
Return all the strings that is used in this applet."
"""
string_dict = {}
string_dict['menu_item'] = _("Welcome")
string_dict['welcome_text'] = _("Welcome! This setup program will install Debian on to your system.")
string_dict['confirm_text'] = _("Please confirm the following details:")
string_dict['language_text'] = _("Language:")
string_dict['keylayout_text'] = _("Keyboard Layout:")
string_dict['timezone_text'] = _("Time Zone:")
string_dict['basicsettings_text'] = _("Basic Settings:")
lang_dict = {}
lang_dict['af'] = _("Afrikaans")
lang_dict['en'] = _("English (International)")
lang_dict['en-us'] = _("English (United States)")
lang_dict['en-uk'] = _("English (United Kingdom)")
lang_dict['en-za'] = _("English (South Africa)")
string_dict['lang_list'] = lang_dict
return string_dict
def build_menu():
"""
Define menu items and paths.
"""
current_app.config['CONFIG']['settings']['menu']['welcome'] = (build_stringlist()['menu_item'], "/welcome", 10)
def build_summary():
"""
Write up a summary of what this module will do.
"""
html = ("<b><big>Basic settings</big></b><p> Language: " + lang + "</p>")
if not 'Summary' in current_app.config['CONFIG']:
current_app.config['CONFIG']['Summary'] = {}
current_app.config['CONFIG']['Summary']['welcome'] = {}
current_app.config['CONFIG']['Summary']['welcome']['heading'] = "Basic Settings"
print(current_app.config['CONFIG']['Summary']['welcome'])
text = "Language: " + str(current_app.config['CONFIG']['settings']['language'])
current_app.config['CONFIG']['Summary']['welcome']['text'] = text
return(html)
set_language(current_app.config['CONFIG']['settings']['language'])
build_menu