feat(KIAUH): show commit in UpdateMenu

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2023-12-28 13:38:24 +01:00
parent f3b0e45e39
commit dfbce3b489
6 changed files with 182 additions and 73 deletions

View File

@@ -21,7 +21,14 @@ from kiauh.core.menus.update_menu import UpdateMenu
from kiauh.modules.klipper.klipper_utils import get_klipper_status
from kiauh.modules.mainsail.mainsail_utils import get_mainsail_status
from kiauh.modules.moonraker.moonraker_utils import get_moonraker_status
from kiauh.utils.constants import COLOR_MAGENTA, COLOR_CYAN, RESET_FORMAT, COLOR_RED
from kiauh.utils.constants import (
COLOR_MAGENTA,
COLOR_CYAN,
RESET_FORMAT,
COLOR_RED,
COLOR_GREEN,
COLOR_YELLOW,
)
class MainMenu(BaseMenu):
@@ -39,18 +46,18 @@ class MainMenu(BaseMenu):
},
footer_type=QUIT_FOOTER,
)
self.kl_status = None
self.kl_repo = None
self.mr_status = None
self.mr_repo = None
self.ms_status = None
self.fl_status = None
self.ks_status = None
self.mb_status = None
self.cn_status = None
self.tg_status = None
self.ob_status = None
self.oe_status = None
self.kl_status = ""
self.kl_repo = ""
self.mr_status = ""
self.mr_repo = ""
self.ms_status = ""
self.fl_status = ""
self.ks_status = ""
self.mb_status = ""
self.cn_status = ""
self.tg_status = ""
self.ob_status = ""
self.oe_status = ""
self.init_status()
def init_status(self) -> None:
@@ -60,14 +67,30 @@ class MainMenu(BaseMenu):
def fetch_status(self) -> None:
# klipper
self.kl_status = get_klipper_status().get("status")
self.kl_repo = get_klipper_status().get("repo")
klipper_status = get_klipper_status()
kl_status = klipper_status.get("status")
kl_code = klipper_status.get("status_code")
kl_instances = f" {klipper_status.get('instances')}" if kl_code == 1 else ""
self.kl_status = self.format_status_by_code(kl_code, kl_status, kl_instances)
self.kl_repo = f"{COLOR_CYAN}{klipper_status.get('repo')}{RESET_FORMAT}"
# moonraker
self.mr_status = get_moonraker_status().get("status")
self.mr_repo = get_moonraker_status().get("repo")
moonraker_status = get_moonraker_status()
mr_status = moonraker_status.get("status")
mr_code = moonraker_status.get("status_code")
mr_instances = f" {moonraker_status.get('instances')}" if mr_code == 1 else ""
self.mr_status = self.format_status_by_code(mr_code, mr_status, mr_instances)
self.mr_repo = f"{COLOR_CYAN}{moonraker_status.get('repo')}{RESET_FORMAT}"
# mainsail
self.ms_status = get_mainsail_status()
def format_status_by_code(self, code: int, status: str, count: str) -> str:
if code == 1:
return f"{COLOR_GREEN}{status}{count}{RESET_FORMAT}"
elif code == 2:
return f"{COLOR_RED}{status}{count}{RESET_FORMAT}"
return f"{COLOR_YELLOW}{status}{count}{RESET_FORMAT}"
def print_menu(self):
self.fetch_status()

View File

@@ -14,7 +14,11 @@ import textwrap
from kiauh.core.menus import BACK_FOOTER
from kiauh.core.menus.base_menu import BaseMenu
from kiauh.modules.klipper.klipper_setup import update_klipper
from kiauh.utils.constants import COLOR_GREEN, RESET_FORMAT
from kiauh.modules.klipper.klipper_utils import (
get_klipper_status,
)
from kiauh.modules.moonraker.moonraker_utils import get_moonraker_status
from kiauh.utils.constants import COLOR_GREEN, RESET_FORMAT, COLOR_YELLOW, COLOR_WHITE
# noinspection PyMethodMayBeStatic
@@ -39,8 +43,14 @@ class UpdateMenu(BaseMenu):
},
footer_type=BACK_FOOTER,
)
self.kl_local = f"{COLOR_WHITE}{RESET_FORMAT}"
self.kl_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
self.mr_local = f"{COLOR_WHITE}{RESET_FORMAT}"
self.mr_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
def print_menu(self):
self.fetch_update_status()
header = " [ Update Menu ] "
color = COLOR_GREEN
count = 62 - len(color) - len(RESET_FORMAT)
@@ -49,28 +59,28 @@ class UpdateMenu(BaseMenu):
/=======================================================\\
| {color}{header:~^{count}}{RESET_FORMAT} |
|-------------------------------------------------------|
| 0) [Update all] | | |
| | Current: | Latest: |
| Klipper & API: |--------------|--------------|
| 1) [Klipper] | | |
| 2) [Moonraker] | | |
| | | |
| Klipper Webinterface: |--------------|--------------|
| 3) [Mainsail] | | |
| 4) [Fluidd] | | |
| | | |
| Touchscreen GUI: |--------------|--------------|
| 5) [KlipperScreen] | | |
| | | |
| Other: |--------------|--------------|
| 6) [PrettyGCode] | | |
| 7) [Telegram Bot] | | |
| 8) [Obico for Klipper] | | |
| 9) [OctoEverywhere] | | |
| 10) [Mobileraker] | | |
| 11) [Crowsnest] | | |
| |-----------------------------|
| 12) [System] | | |
| 0) Update all | | |
| | Current: | Latest: |
| Klipper & API: |---------------|---------------|
| 1) Klipper | {self.kl_local:<22} | {self.kl_remote:<22} |
| 2) Moonraker | {self.mr_local:<22} | {self.mr_remote:<22} |
| | | |
| Klipper Webinterface: |---------------|---------------|
| 3) Mainsail | | |
| 4) Fluidd | | |
| | | |
| Touchscreen GUI: |---------------|---------------|
| 5) KlipperScreen | | |
| | | |
| Other: |---------------|---------------|
| 6) PrettyGCode | | |
| 7) Telegram Bot | | |
| 8) Obico for Klipper | | |
| 9) OctoEverywhere | | |
| 10) Mobileraker | | |
| 11) Crowsnest | | |
| |-------------------------------|
| 12) System | |
"""
)[1:]
print(menu, end="")
@@ -113,3 +123,23 @@ class UpdateMenu(BaseMenu):
def upgrade_system_packages(self):
print("upgrade_system_packages")
def fetch_update_status(self):
# klipper
kl_status = get_klipper_status()
self.kl_local = kl_status.get("local")
self.kl_remote = kl_status.get("remote")
if self.kl_local == self.kl_remote:
self.kl_local = f"{COLOR_GREEN}{self.kl_local}{RESET_FORMAT}"
else:
self.kl_local = f"{COLOR_YELLOW}{self.kl_local}{RESET_FORMAT}"
self.kl_remote = f"{COLOR_GREEN}{self.kl_remote}{RESET_FORMAT}"
# moonraker
mr_status = get_moonraker_status()
self.mr_local = mr_status.get("local")
self.mr_remote = mr_status.get("remote")
if self.mr_local == self.mr_remote:
self.mr_local = f"{COLOR_GREEN}{self.mr_local}{RESET_FORMAT}"
else:
self.mr_local = f"{COLOR_YELLOW}{self.mr_local}{RESET_FORMAT}"
self.mr_remote = f"{COLOR_GREEN}{self.mr_remote}{RESET_FORMAT}"