Compare commits

..

3 Commits

Author SHA1 Message Date
dw-0
c28d5c28b9 refactor(KIAUH): use pythons own venv module to create a venv
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-12-29 19:39:45 +01:00
dw-0
cda6d31a7c fix(RepoManager): check if git dir exists
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-12-29 18:57:53 +01:00
dw-0
9a657daffd feat(KIAUH): show Mainsail in UpdateMenu
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-12-28 18:05:43 +01:00
6 changed files with 53 additions and 15 deletions

View File

@@ -17,6 +17,11 @@ from kiauh.modules.klipper.klipper_setup import update_klipper
from kiauh.modules.klipper.klipper_utils import ( from kiauh.modules.klipper.klipper_utils import (
get_klipper_status, get_klipper_status,
) )
from kiauh.modules.mainsail.mainsail_setup import update_mainsail
from kiauh.modules.mainsail.mainsail_utils import (
get_mainsail_local_version,
get_mainsail_remote_version,
)
from kiauh.modules.moonraker.moonraker_setup import update_moonraker from kiauh.modules.moonraker.moonraker_setup import update_moonraker
from kiauh.modules.moonraker.moonraker_utils import get_moonraker_status from kiauh.modules.moonraker.moonraker_utils import get_moonraker_status
from kiauh.utils.constants import COLOR_GREEN, RESET_FORMAT, COLOR_YELLOW, COLOR_WHITE from kiauh.utils.constants import COLOR_GREEN, RESET_FORMAT, COLOR_YELLOW, COLOR_WHITE
@@ -48,6 +53,8 @@ class UpdateMenu(BaseMenu):
self.kl_remote = f"{COLOR_WHITE}{RESET_FORMAT}" self.kl_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
self.mr_local = f"{COLOR_WHITE}{RESET_FORMAT}" self.mr_local = f"{COLOR_WHITE}{RESET_FORMAT}"
self.mr_remote = f"{COLOR_WHITE}{RESET_FORMAT}" self.mr_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
self.ms_local = f"{COLOR_WHITE}{RESET_FORMAT}"
self.ms_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
def print_menu(self): def print_menu(self):
self.fetch_update_status() self.fetch_update_status()
@@ -67,7 +74,7 @@ class UpdateMenu(BaseMenu):
| 2) Moonraker | {self.mr_local:<22} | {self.mr_remote:<22} | | 2) Moonraker | {self.mr_local:<22} | {self.mr_remote:<22} |
| | | | | | | |
| Klipper Webinterface: |---------------|---------------| | Klipper Webinterface: |---------------|---------------|
| 3) Mainsail | | | | 3) Mainsail | {self.ms_local:<22} | {self.ms_remote:<22} |
| 4) Fluidd | | | | 4) Fluidd | | |
| | | | | | | |
| Touchscreen GUI: |---------------|---------------| | Touchscreen GUI: |---------------|---------------|
@@ -96,7 +103,7 @@ class UpdateMenu(BaseMenu):
update_moonraker() update_moonraker()
def update_mainsail(self): def update_mainsail(self):
print("update_mainsail") update_mainsail()
def update_fluidd(self): def update_fluidd(self):
print("update_fluidd") print("update_fluidd")
@@ -144,3 +151,11 @@ class UpdateMenu(BaseMenu):
else: else:
self.mr_local = f"{COLOR_YELLOW}{self.mr_local}{RESET_FORMAT}" self.mr_local = f"{COLOR_YELLOW}{self.mr_local}{RESET_FORMAT}"
self.mr_remote = f"{COLOR_GREEN}{self.mr_remote}{RESET_FORMAT}" self.mr_remote = f"{COLOR_GREEN}{self.mr_remote}{RESET_FORMAT}"
# mainsail
self.ms_local = get_mainsail_local_version()
self.ms_remote = get_mainsail_remote_version()
if self.ms_local == self.ms_remote:
self.ms_local = f"{COLOR_GREEN}{self.ms_local}{RESET_FORMAT}"
else:
self.ms_local = f"{COLOR_YELLOW}{self.ms_local}{RESET_FORMAT}"
self.ms_remote = f"{COLOR_GREEN}{self.ms_remote}{RESET_FORMAT}"

View File

@@ -69,6 +69,9 @@ class RepoManager:
:param repo: repository to extract the values from :param repo: repository to extract the values from
:return: String in form of "<orga>/<name>" :return: String in form of "<orga>/<name>"
""" """
if not repo.exists() and not repo.joinpath(".git").exists():
return "-"
try: try:
cmd = ["git", "-C", repo, "config", "--get", "remote.origin.url"] cmd = ["git", "-C", repo, "config", "--get", "remote.origin.url"]
result = subprocess.check_output(cmd, stderr=subprocess.DEVNULL) result = subprocess.check_output(cmd, stderr=subprocess.DEVNULL)
@@ -78,7 +81,7 @@ class RepoManager:
@staticmethod @staticmethod
def get_local_commit(repo: Path) -> str: def get_local_commit(repo: Path) -> str:
if not repo.exists() and repo.joinpath(".git").exists(): if not repo.exists() and not repo.joinpath(".git").exists():
return "-" return "-"
try: try:
@@ -89,7 +92,7 @@ class RepoManager:
@staticmethod @staticmethod
def get_remote_commit(repo: Path) -> str: def get_remote_commit(repo: Path) -> str:
if not repo.exists() and repo.joinpath(".git").exists(): if not repo.exists() and not repo.joinpath(".git").exists():
return "-" return "-"
try: try:

View File

@@ -114,10 +114,9 @@ def setup_klipper_prerequesites() -> None:
repo_manager.clone_repo() repo_manager.clone_repo()
# install klipper dependencies and create python virtualenv # install klipper dependencies and create python virtualenv
install_klipper_packages(Path(KLIPPER_DIR)) install_klipper_packages(KLIPPER_DIR)
create_python_venv(Path(KLIPPER_ENV_DIR)) create_python_venv(KLIPPER_ENV_DIR)
klipper_py_req = Path(KLIPPER_REQUIREMENTS_TXT) install_python_requirements(KLIPPER_ENV_DIR, KLIPPER_REQUIREMENTS_TXT)
install_python_requirements(Path(KLIPPER_ENV_DIR), klipper_py_req)
def install_klipper_packages(klipper_dir: Path) -> None: def install_klipper_packages(klipper_dir: Path) -> None:

View File

@@ -162,6 +162,13 @@ def download_mainsail() -> None:
raise raise
def update_mainsail() -> None:
Logger.print_status("Updating Mainsail ...")
backup_config_json(is_temp=True)
download_mainsail()
restore_config_json()
def download_mainsail_cfg() -> None: def download_mainsail_cfg() -> None:
try: try:
Logger.print_status("Downloading mainsail-config ...") Logger.print_status("Downloading mainsail-config ...")

View File

@@ -11,6 +11,7 @@
import json import json
import shutil import shutil
import requests
from pathlib import Path from pathlib import Path
from typing import List from typing import List
@@ -80,3 +81,19 @@ def symlink_webui_nginx_log(klipper_instances: List[Klipper]) -> None:
desti_error = instance.log_dir.joinpath("mainsail-error.log") desti_error = instance.log_dir.joinpath("mainsail-error.log")
if not desti_error.exists(): if not desti_error.exists():
desti_error.symlink_to(error_log) desti_error.symlink_to(error_log)
def get_mainsail_local_version() -> str:
relinfo_file = MAINSAIL_DIR.joinpath("release_info.json")
if not relinfo_file.is_file():
return "-"
with open(relinfo_file, "r") as f:
return json.load(f)["version"]
def get_mainsail_remote_version() -> str:
url = "https://api.github.com/repos/mainsail-crew/mainsail/tags"
response = requests.get(url)
data = json.loads(response.text)
return data[0]["name"]

View File

@@ -17,6 +17,7 @@ import sys
import time import time
import urllib.error import urllib.error
import urllib.request import urllib.request
import venv
from pathlib import Path from pathlib import Path
from typing import List, Literal from typing import List, Literal
@@ -68,14 +69,10 @@ def create_python_venv(target: Path) -> None:
Logger.print_status("Set up Python virtual environment ...") Logger.print_status("Set up Python virtual environment ...")
if not target.exists(): if not target.exists():
try: try:
command = ["python3", "-m", "venv", f"{target}"] venv.create(target, with_pip=True)
result = subprocess.run(command, stderr=subprocess.PIPE, text=True)
if result.returncode != 0 or result.stderr:
Logger.print_error(f"{result.stderr}", prefix=False)
Logger.print_error("Setup of virtualenv failed!")
return
Logger.print_ok("Setup of virtualenv successfull!") Logger.print_ok("Setup of virtualenv successfull!")
except OSError as e:
Logger.print_error(f"Error setting up virtualenv:\n{e}")
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
Logger.print_error(f"Error setting up virtualenv:\n{e.output.decode()}") Logger.print_error(f"Error setting up virtualenv:\n{e.output.decode()}")
else: else: