2024-08-28 22:20:36 +02:00
|
|
|
import os
|
|
|
|
|
|
|
|
import questionary
|
|
|
|
|
2024-08-29 13:13:49 +02:00
|
|
|
from core.vars import loaded_services
|
2024-08-28 22:20:36 +02:00
|
|
|
from ui import choices
|
2024-08-29 12:26:37 +02:00
|
|
|
from ui.choices import update_choices
|
2024-08-28 22:20:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
def clear_terminal():
|
|
|
|
os.system('cls' if os.name == 'nt' else 'clear')
|
|
|
|
|
|
|
|
|
|
|
|
def handle_services(action, service):
|
|
|
|
clear_terminal()
|
|
|
|
|
|
|
|
if service == "back":
|
|
|
|
return
|
|
|
|
|
|
|
|
service = loaded_services[service]
|
|
|
|
if action == "start":
|
2024-08-29 13:13:49 +02:00
|
|
|
questionary.print(f"Starting {service.name}...")
|
2024-08-28 22:20:36 +02:00
|
|
|
service.start()
|
|
|
|
elif action == "stop":
|
2024-08-29 13:13:49 +02:00
|
|
|
questionary.print(f"Stopping {service.name}...")
|
2024-08-28 22:20:36 +02:00
|
|
|
service.stop()
|
2024-08-29 12:26:37 +02:00
|
|
|
elif action == "install":
|
2024-08-28 22:20:36 +02:00
|
|
|
confirmation = choices.are_you_sure.ask()
|
|
|
|
if confirmation:
|
2024-08-29 13:13:49 +02:00
|
|
|
questionary.print(f"Installing {service.name}...")
|
2024-08-29 12:26:37 +02:00
|
|
|
service.install()
|
2024-08-28 22:20:36 +02:00
|
|
|
elif action == "uninstall":
|
|
|
|
confirmation = choices.are_you_sure.ask()
|
|
|
|
if confirmation:
|
2024-08-29 12:50:18 +02:00
|
|
|
type_confirmation = questionary.text(f"Please type {service.id} to confirm uninstallation (or type cancel):")
|
|
|
|
|
|
|
|
value = type_confirmation.ask()
|
|
|
|
|
|
|
|
if value == "cancel":
|
2024-08-29 13:13:49 +02:00
|
|
|
questionary.print("Canceled", style="fg:ansired bold")
|
2024-08-29 12:50:18 +02:00
|
|
|
elif value != service.id:
|
2024-08-29 13:13:49 +02:00
|
|
|
questionary.print("Invalid input, please try again", style="fg:ansired bold")
|
2024-08-29 12:50:18 +02:00
|
|
|
elif value == service.id:
|
2024-08-28 22:20:36 +02:00
|
|
|
service.uninstall()
|
|
|
|
|
|
|
|
choices.any_key.ask()
|
|
|
|
|
|
|
|
|
|
|
|
def run_interactive_cmd_ui():
|
|
|
|
while True:
|
|
|
|
clear_terminal()
|
2024-08-29 12:26:37 +02:00
|
|
|
update_choices()
|
2024-08-28 22:20:36 +02:00
|
|
|
choice = choices.start.ask()
|
|
|
|
|
|
|
|
if choice == "Start service":
|
|
|
|
service = choices.start_service.ask()
|
|
|
|
handle_services("start", service)
|
|
|
|
|
|
|
|
elif choice == "Stop service":
|
|
|
|
service = choices.stop_service.ask()
|
|
|
|
handle_services("stop", service)
|
|
|
|
|
|
|
|
elif choice == "Install/update service":
|
|
|
|
service = choices.install_service.ask()
|
2024-08-29 12:26:37 +02:00
|
|
|
handle_services("install", service)
|
2024-08-28 22:20:36 +02:00
|
|
|
|
|
|
|
elif choice == "Uninstall service":
|
|
|
|
service = choices.uninstall_service.ask()
|
|
|
|
handle_services("uninstall", service)
|
|
|
|
|
2024-08-29 12:03:37 +02:00
|
|
|
elif choice == "exit":
|
2024-08-28 22:20:36 +02:00
|
|
|
print("Exiting...")
|
|
|
|
exit(0)
|