mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-25 00:33:37 +05:00
feat(extension): implement PrettyGCode for Klipper extension
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
0
kiauh/extensions/pretty_gcode/__init__.py
Normal file
0
kiauh/extensions/pretty_gcode/__init__.py
Normal file
19
kiauh/extensions/pretty_gcode/assets/pgcode.local.conf
Normal file
19
kiauh/extensions/pretty_gcode/assets/pgcode.local.conf
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# PrettyGCode website configuration
|
||||||
|
# copy this file to /etc/nginx/sites-available/pgcode.local.conf
|
||||||
|
# then to enable:
|
||||||
|
# sudo ln -s /etc/nginx/sites-available/pgcode.local.conf /etc/nginx/sites-enabled/pgcode.local.conf
|
||||||
|
# then restart ngninx:
|
||||||
|
# sudo systemctl reload nginx
|
||||||
|
server {
|
||||||
|
listen %PORT%;
|
||||||
|
listen [::]:%PORT%;
|
||||||
|
server_name pgcode.local;
|
||||||
|
|
||||||
|
root %ROOT_DIR%;
|
||||||
|
|
||||||
|
index pgcode.html;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ =404;
|
||||||
|
}
|
||||||
|
}
|
||||||
10
kiauh/extensions/pretty_gcode/metadata.json
Normal file
10
kiauh/extensions/pretty_gcode/metadata.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"metadata": {
|
||||||
|
"index": 5,
|
||||||
|
"module": "pretty_gcode_extension",
|
||||||
|
"maintained_by": "Kragrathea",
|
||||||
|
"display_name": "PrettyGCode for Klipper",
|
||||||
|
"description": "3D G-Code viewer for Klipper",
|
||||||
|
"updates": true
|
||||||
|
}
|
||||||
|
}
|
||||||
104
kiauh/extensions/pretty_gcode/pretty_gcode_extension.py
Normal file
104
kiauh/extensions/pretty_gcode/pretty_gcode_extension.py
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
# ======================================================================= #
|
||||||
|
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||||
|
# #
|
||||||
|
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||||
|
# https://github.com/dw-0/kiauh #
|
||||||
|
# #
|
||||||
|
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||||
|
# ======================================================================= #
|
||||||
|
import shutil
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from extensions.base_extension import BaseExtension
|
||||||
|
from utils import NGINX_SITES_AVAILABLE, NGINX_SITES_ENABLED
|
||||||
|
from utils.common import check_install_dependencies
|
||||||
|
from utils.fs_utils import (
|
||||||
|
create_nginx_cfg,
|
||||||
|
remove_file,
|
||||||
|
)
|
||||||
|
from utils.git_utils import git_clone_wrapper, git_pull_wrapper
|
||||||
|
from utils.input_utils import get_number_input
|
||||||
|
from utils.logger import DialogType, Logger
|
||||||
|
from utils.sys_utils import cmd_sysctl_service, get_ipv4_addr
|
||||||
|
|
||||||
|
MODULE_PATH = Path(__file__).resolve().parent
|
||||||
|
PGC_DIR = Path.home().joinpath("pgcode")
|
||||||
|
PGC_REPO = "https://github.com/Kragrathea/pgcode"
|
||||||
|
PGC_CONF = "pgcode.local.conf"
|
||||||
|
|
||||||
|
|
||||||
|
# noinspection PyMethodMayBeStatic
|
||||||
|
class PrettyGcodeExtension(BaseExtension):
|
||||||
|
def install_extension(self, **kwargs) -> None:
|
||||||
|
Logger.print_status("Installing PrettyGCode for Klipper ...")
|
||||||
|
Logger.print_dialog(
|
||||||
|
DialogType.ATTENTION,
|
||||||
|
[
|
||||||
|
"Make sure you don't select a port which is already in use by "
|
||||||
|
"another application. Your input will not be validated! Choosing a port "
|
||||||
|
"which is already in use by another application may cause issues!",
|
||||||
|
"The default port is 7136.",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
port = get_number_input(
|
||||||
|
"On which port should PrettyGCode run",
|
||||||
|
min_count=0,
|
||||||
|
default=7136,
|
||||||
|
allow_go_back=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
check_install_dependencies(["nginx"])
|
||||||
|
|
||||||
|
try:
|
||||||
|
# remove any existing pgc dir
|
||||||
|
if PGC_DIR.exists():
|
||||||
|
shutil.rmtree(PGC_DIR)
|
||||||
|
|
||||||
|
# clone pgc repo
|
||||||
|
git_clone_wrapper(PGC_REPO, PGC_DIR)
|
||||||
|
|
||||||
|
# copy pgc conf
|
||||||
|
create_nginx_cfg(
|
||||||
|
"PrettyGCode for Klipper",
|
||||||
|
cfg_name=PGC_CONF,
|
||||||
|
template_src=MODULE_PATH.joinpath(f"assets/{PGC_CONF}"),
|
||||||
|
ROOT_DIR=PGC_DIR,
|
||||||
|
PORT=port,
|
||||||
|
)
|
||||||
|
|
||||||
|
cmd_sysctl_service("nginx", "restart")
|
||||||
|
|
||||||
|
log = f"Open PrettyGCode now on: http://{get_ipv4_addr()}:{port}"
|
||||||
|
Logger.print_ok("PrettyGCode installation complete!", start="\n")
|
||||||
|
Logger.print_ok(log, prefix=False, end="\n\n")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
Logger.print_error(
|
||||||
|
f"Error during PrettyGCode for Klipper installation: {e}"
|
||||||
|
)
|
||||||
|
|
||||||
|
def update_extension(self, **kwargs) -> None:
|
||||||
|
Logger.print_status("Updating PrettyGCode for Klipper ...")
|
||||||
|
try:
|
||||||
|
git_pull_wrapper(PGC_REPO, PGC_DIR)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
Logger.print_error(f"Error during PrettyGCode for Klipper update: {e}")
|
||||||
|
|
||||||
|
def remove_extension(self, **kwargs) -> None:
|
||||||
|
try:
|
||||||
|
Logger.print_status("Removing PrettyGCode for Klipper ...")
|
||||||
|
|
||||||
|
# remove pgc dir
|
||||||
|
shutil.rmtree(PGC_DIR)
|
||||||
|
# remove nginx config
|
||||||
|
remove_file(NGINX_SITES_AVAILABLE.joinpath(PGC_CONF), True)
|
||||||
|
remove_file(NGINX_SITES_ENABLED.joinpath(PGC_CONF), True)
|
||||||
|
# restart nginx
|
||||||
|
cmd_sysctl_service("nginx", "restart")
|
||||||
|
|
||||||
|
Logger.print_ok("PrettyGCode for Klipper removed!")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
Logger.print_error(f"Error during PrettyGCode for Klipper removal: {e}")
|
||||||
Reference in New Issue
Block a user