mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-24 00:03:42 +05:00
Compare commits
3 Commits
ac0478b062
...
0dfe7672b8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0dfe7672b8 | ||
|
|
b3df3e7b5c | ||
|
|
01afe1fe77 |
@@ -13,7 +13,7 @@ from typing import List
|
||||
|
||||
from core.instance_manager.base_instance import BaseInstance
|
||||
from core.menus.base_menu import print_back_footer
|
||||
from utils.constants import COLOR_GREEN, RESET_FORMAT, COLOR_YELLOW, COLOR_CYAN
|
||||
from utils.constants import COLOR_CYAN, COLOR_GREEN, COLOR_YELLOW, RESET_FORMAT
|
||||
|
||||
|
||||
@unique
|
||||
|
||||
@@ -9,10 +9,6 @@
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from components.webui_client.client_utils import (
|
||||
get_existing_clients,
|
||||
)
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
from components.klipper import (
|
||||
EXIT_KLIPPER_SETUP,
|
||||
KLIPPER_DIR,
|
||||
@@ -22,28 +18,32 @@ from components.klipper import (
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.klipper.klipper_dialogs import print_update_warn_dialog
|
||||
from components.klipper.klipper_utils import (
|
||||
handle_disruptive_system_packages,
|
||||
check_user_groups,
|
||||
handle_to_multi_instance_conversion,
|
||||
create_example_printer_cfg,
|
||||
add_to_existing,
|
||||
get_install_count,
|
||||
init_name_scheme,
|
||||
check_is_single_to_multi_conversion,
|
||||
update_name_scheme,
|
||||
handle_instance_naming,
|
||||
backup_klipper_dir,
|
||||
check_is_single_to_multi_conversion,
|
||||
check_user_groups,
|
||||
create_example_printer_cfg,
|
||||
get_install_count,
|
||||
handle_disruptive_system_packages,
|
||||
handle_instance_naming,
|
||||
handle_to_multi_instance_conversion,
|
||||
init_name_scheme,
|
||||
update_name_scheme,
|
||||
)
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from components.webui_client.client_utils import (
|
||||
get_existing_clients,
|
||||
)
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
from utils.common import check_install_dependencies
|
||||
from utils.git_utils import git_clone_wrapper, git_pull_wrapper
|
||||
from utils.input_utils import get_confirm
|
||||
from utils.logger import Logger
|
||||
from utils.sys_utils import (
|
||||
parse_packages_from_file,
|
||||
create_python_venv,
|
||||
install_python_requirements,
|
||||
parse_packages_from_file,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
# ======================================================================= #
|
||||
|
||||
import textwrap
|
||||
from typing import Type, Optional
|
||||
from typing import Optional, Type
|
||||
|
||||
from components.klipper import klipper_remove
|
||||
from core.menus import FooterType, Option
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.constants import RESET_FORMAT, COLOR_RED, COLOR_CYAN
|
||||
from utils.constants import COLOR_CYAN, COLOR_RED, RESET_FORMAT
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
|
||||
@@ -7,15 +7,15 @@
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
|
||||
from subprocess import CalledProcessError, check_output, Popen, PIPE, STDOUT, run
|
||||
from subprocess import PIPE, STDOUT, CalledProcessError, Popen, check_output, run
|
||||
from typing import List
|
||||
|
||||
from components.klipper import KLIPPER_DIR
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.klipper_firmware import SD_FLASH_SCRIPT
|
||||
from components.klipper_firmware.flash_options import (
|
||||
FlashOptions,
|
||||
FlashMethod,
|
||||
FlashOptions,
|
||||
)
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from utils.logger import Logger
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
from dataclasses import field
|
||||
from enum import Enum
|
||||
from typing import Union, List
|
||||
from typing import List, Union
|
||||
|
||||
|
||||
class FlashMethod(Enum):
|
||||
|
||||
@@ -8,22 +8,22 @@
|
||||
# ======================================================================= #
|
||||
|
||||
import textwrap
|
||||
from typing import Type, Optional
|
||||
from typing import Optional, Type
|
||||
|
||||
from components.klipper import KLIPPER_DIR
|
||||
from components.klipper_firmware.firmware_utils import (
|
||||
run_make,
|
||||
run_make_clean,
|
||||
run_make_menuconfig,
|
||||
run_make,
|
||||
)
|
||||
from core.menus import Option
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.constants import COLOR_CYAN, RESET_FORMAT, COLOR_GREEN, COLOR_RED
|
||||
from utils.constants import COLOR_CYAN, COLOR_GREEN, COLOR_RED, RESET_FORMAT
|
||||
from utils.logger import Logger
|
||||
from utils.sys_utils import (
|
||||
check_package_install,
|
||||
update_system_package_lists,
|
||||
install_system_packages,
|
||||
update_system_package_lists,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import textwrap
|
||||
from typing import Optional, Type
|
||||
|
||||
from components.klipper_firmware.flash_options import FlashOptions, FlashMethod
|
||||
from components.klipper_firmware.flash_options import FlashMethod, FlashOptions
|
||||
from core.menus import FooterType, Option
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.constants import COLOR_RED, RESET_FORMAT
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
import textwrap
|
||||
from typing import Type, Optional
|
||||
from typing import Optional, Type
|
||||
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.constants import COLOR_CYAN, RESET_FORMAT, COLOR_YELLOW
|
||||
from utils.constants import COLOR_CYAN, COLOR_YELLOW, RESET_FORMAT
|
||||
|
||||
|
||||
# noinspection DuplicatedCode
|
||||
|
||||
@@ -9,35 +9,34 @@
|
||||
|
||||
import textwrap
|
||||
import time
|
||||
from typing import Type, Optional
|
||||
from typing import Optional, Type
|
||||
|
||||
from components.klipper_firmware.flash_options import (
|
||||
FlashOptions,
|
||||
FlashMethod,
|
||||
FlashCommand,
|
||||
ConnectionType,
|
||||
)
|
||||
from components.klipper_firmware.firmware_utils import (
|
||||
find_usb_device_by_id,
|
||||
find_firmware_file,
|
||||
find_uart_device,
|
||||
find_usb_device_by_id,
|
||||
find_usb_dfu_device,
|
||||
get_sd_flash_board_list,
|
||||
start_flash_process,
|
||||
find_firmware_file,
|
||||
)
|
||||
from components.klipper_firmware.flash_options import (
|
||||
ConnectionType,
|
||||
FlashCommand,
|
||||
FlashMethod,
|
||||
FlashOptions,
|
||||
)
|
||||
from components.klipper_firmware.menus.klipper_flash_error_menu import (
|
||||
KlipperNoBoardTypesErrorMenu,
|
||||
KlipperNoFirmwareErrorMenu,
|
||||
)
|
||||
from components.klipper_firmware.menus.klipper_flash_help_menu import (
|
||||
KlipperMcuConnectionHelpMenu,
|
||||
KlipperFlashCommandHelpMenu,
|
||||
KlipperFlashMethodHelpMenu,
|
||||
KlipperMcuConnectionHelpMenu,
|
||||
)
|
||||
from core.menus import FooterType, Option
|
||||
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.constants import COLOR_CYAN, RESET_FORMAT, COLOR_YELLOW, COLOR_RED
|
||||
from utils.constants import COLOR_CYAN, COLOR_RED, COLOR_YELLOW, RESET_FORMAT
|
||||
from utils.input_utils import get_number_input
|
||||
from utils.logger import Logger
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
# ======================================================================= #
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Dict, Union, Literal
|
||||
from typing import Dict, Literal, Union
|
||||
|
||||
FileKey = Literal["filepath", "display_name"]
|
||||
LogFile = Dict[FileKey, Union[str, Path]]
|
||||
|
||||
@@ -8,13 +8,12 @@
|
||||
# ======================================================================= #
|
||||
|
||||
import textwrap
|
||||
from typing import Type, Optional
|
||||
from typing import Optional, Type
|
||||
|
||||
from components.log_uploads.log_upload_utils import get_logfile_list
|
||||
from components.log_uploads.log_upload_utils import upload_logfile
|
||||
from components.log_uploads.log_upload_utils import get_logfile_list, upload_logfile
|
||||
from core.menus import Option
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.constants import RESET_FORMAT, COLOR_YELLOW
|
||||
from utils.constants import COLOR_YELLOW, RESET_FORMAT
|
||||
|
||||
|
||||
# noinspection PyMethodMayBeStatic
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
# ======================================================================= #
|
||||
|
||||
import textwrap
|
||||
from typing import Type, Optional
|
||||
from typing import Optional, Type
|
||||
|
||||
from components.moonraker import moonraker_remove
|
||||
from core.menus import Option
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.constants import RESET_FORMAT, COLOR_RED, COLOR_CYAN
|
||||
from utils.constants import COLOR_CYAN, COLOR_RED, RESET_FORMAT
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
|
||||
@@ -11,7 +11,7 @@ import subprocess
|
||||
from pathlib import Path
|
||||
from typing import List, Union
|
||||
|
||||
from components.moonraker import MOONRAKER_DIR, MOONRAKER_ENV_DIR, MODULE_PATH
|
||||
from components.moonraker import MODULE_PATH, MOONRAKER_DIR, MOONRAKER_ENV_DIR
|
||||
from core.config_manager.config_manager import ConfigManager
|
||||
from core.instance_manager.base_instance import BaseInstance
|
||||
from utils.constants import SYSTEMD
|
||||
|
||||
@@ -13,7 +13,7 @@ from typing import List
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from core.menus.base_menu import print_back_footer
|
||||
from utils.constants import COLOR_GREEN, RESET_FORMAT, COLOR_YELLOW, COLOR_CYAN
|
||||
from utils.constants import COLOR_CYAN, COLOR_GREEN, COLOR_YELLOW, RESET_FORMAT
|
||||
|
||||
|
||||
def print_moonraker_overview(
|
||||
|
||||
@@ -10,30 +10,30 @@ import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from components.webui_client.client_utils import (
|
||||
enable_mainsail_remotemode,
|
||||
get_existing_clients,
|
||||
)
|
||||
from components.webui_client.mainsail_data import MainsailData
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.moonraker import (
|
||||
EXIT_MOONRAKER_SETUP,
|
||||
MOONRAKER_DIR,
|
||||
MOONRAKER_ENV_DIR,
|
||||
MOONRAKER_REQUIREMENTS_TXT,
|
||||
POLKIT_LEGACY_FILE,
|
||||
POLKIT_FILE,
|
||||
POLKIT_USR_FILE,
|
||||
POLKIT_LEGACY_FILE,
|
||||
POLKIT_SCRIPT,
|
||||
POLKIT_USR_FILE,
|
||||
)
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from components.moonraker.moonraker_dialogs import print_moonraker_overview
|
||||
from components.moonraker.moonraker_utils import (
|
||||
create_example_moonraker_conf,
|
||||
backup_moonraker_dir,
|
||||
create_example_moonraker_conf,
|
||||
)
|
||||
from components.webui_client.client_utils import (
|
||||
enable_mainsail_remotemode,
|
||||
get_existing_clients,
|
||||
)
|
||||
from components.webui_client.mainsail_data import MainsailData
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
from utils.common import check_install_dependencies
|
||||
from utils.fs_utils import check_file_exist
|
||||
from utils.git_utils import git_clone_wrapper, git_pull_wrapper
|
||||
@@ -43,10 +43,10 @@ from utils.input_utils import (
|
||||
)
|
||||
from utils.logger import Logger
|
||||
from utils.sys_utils import (
|
||||
parse_packages_from_file,
|
||||
check_python_version,
|
||||
create_python_venv,
|
||||
install_python_requirements,
|
||||
check_python_version,
|
||||
parse_packages_from_file,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
# ======================================================================= #
|
||||
# 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 #
|
||||
# ======================================================================= #
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
MODULE_PATH = Path(__file__).resolve().parent
|
||||
|
||||
@@ -12,10 +12,9 @@ import subprocess
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
from components.webui_client.base_data import BaseWebClient, BaseWebClientConfig
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from components.webui_client.base_data import BaseWebClient, BaseWebClientConfig
|
||||
from components.webui_client.client_dialogs import (
|
||||
print_client_already_installed_dialog,
|
||||
)
|
||||
@@ -23,8 +22,8 @@ from components.webui_client.client_utils import (
|
||||
backup_client_config_data,
|
||||
config_for_other_client_exist,
|
||||
)
|
||||
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
from utils.common import backup_printer_config_dir
|
||||
from utils.config_utils import add_config_section, add_config_section_at_top
|
||||
from utils.fs_utils import create_symlink
|
||||
|
||||
@@ -12,7 +12,7 @@ from typing import List
|
||||
|
||||
from components.webui_client.base_data import BaseWebClient
|
||||
from core.menus.base_menu import print_back_footer
|
||||
from utils.constants import RESET_FORMAT, COLOR_YELLOW, COLOR_CYAN
|
||||
from utils.constants import COLOR_CYAN, COLOR_YELLOW, RESET_FORMAT
|
||||
|
||||
|
||||
def print_moonraker_not_found_dialog():
|
||||
|
||||
@@ -21,7 +21,6 @@ from components.webui_client.client_config.client_config_remove import (
|
||||
run_client_config_removal,
|
||||
)
|
||||
from components.webui_client.client_utils import backup_mainsail_config_json
|
||||
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from utils.config_utils import remove_config_section
|
||||
from utils.fs_utils import (
|
||||
|
||||
@@ -11,51 +11,47 @@ from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
from components.klipper.klipper import Klipper
|
||||
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from components.webui_client import MODULE_PATH
|
||||
from components.webui_client.base_data import (
|
||||
WebClientType,
|
||||
BaseWebClient,
|
||||
BaseWebClientConfig,
|
||||
WebClientType,
|
||||
)
|
||||
from components.webui_client.client_config.client_config_setup import (
|
||||
install_client_config,
|
||||
)
|
||||
from components.webui_client.client_dialogs import (
|
||||
print_moonraker_not_found_dialog,
|
||||
print_client_port_select_dialog,
|
||||
print_install_client_config_dialog,
|
||||
print_moonraker_not_found_dialog,
|
||||
)
|
||||
from components.webui_client.client_utils import (
|
||||
backup_mainsail_config_json,
|
||||
restore_mainsail_config_json,
|
||||
enable_mainsail_remotemode,
|
||||
symlink_webui_nginx_log,
|
||||
config_for_other_client_exist,
|
||||
enable_mainsail_remotemode,
|
||||
restore_mainsail_config_json,
|
||||
symlink_webui_nginx_log,
|
||||
)
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
from utils import NGINX_SITES_AVAILABLE, NGINX_SITES_ENABLED
|
||||
from utils.common import check_install_dependencies
|
||||
from utils.config_utils import add_config_section
|
||||
from utils.fs_utils import (
|
||||
unzip,
|
||||
copy_upstream_nginx_cfg,
|
||||
copy_common_vars_nginx_cfg,
|
||||
copy_upstream_nginx_cfg,
|
||||
create_nginx_cfg,
|
||||
create_symlink,
|
||||
remove_file,
|
||||
read_ports_from_nginx_configs,
|
||||
is_valid_port,
|
||||
get_next_free_port,
|
||||
is_valid_port,
|
||||
read_ports_from_nginx_configs,
|
||||
unzip,
|
||||
)
|
||||
from utils.input_utils import get_confirm, get_number_input
|
||||
from utils.logger import Logger
|
||||
from utils.sys_utils import (
|
||||
download_file,
|
||||
set_nginx_permissions,
|
||||
get_ipv4_addr,
|
||||
cmd_sysctl_service,
|
||||
download_file,
|
||||
get_ipv4_addr,
|
||||
)
|
||||
|
||||
|
||||
@@ -142,7 +138,15 @@ def install_client(client: BaseWebClient) -> None:
|
||||
|
||||
copy_upstream_nginx_cfg()
|
||||
copy_common_vars_nginx_cfg()
|
||||
create_client_nginx_cfg(client, port)
|
||||
create_nginx_cfg(
|
||||
display_name=client.display_name,
|
||||
cfg_name=client.name,
|
||||
template_src=MODULE_PATH.joinpath("assets/nginx_cfg"),
|
||||
PORT=port,
|
||||
ROOT_DIR=client.client_dir,
|
||||
NAME=client.name,
|
||||
)
|
||||
|
||||
if kl_instances:
|
||||
symlink_webui_nginx_log(kl_instances)
|
||||
cmd_sysctl_service("nginx", "restart")
|
||||
@@ -191,20 +195,3 @@ def update_client(client: BaseWebClient) -> None:
|
||||
|
||||
if client.client == WebClientType.MAINSAIL:
|
||||
restore_mainsail_config_json()
|
||||
|
||||
|
||||
def create_client_nginx_cfg(client: BaseWebClient, port: int) -> None:
|
||||
display_name = client.display_name
|
||||
root_dir = client.client_dir
|
||||
source = NGINX_SITES_AVAILABLE.joinpath(client.name)
|
||||
target = NGINX_SITES_ENABLED.joinpath(client.name)
|
||||
try:
|
||||
Logger.print_status(f"Creating NGINX config for {display_name} ...")
|
||||
remove_file(Path("/etc/nginx/sites-enabled/default"), True)
|
||||
create_nginx_cfg(client.name, port, root_dir)
|
||||
create_symlink(source, target, True)
|
||||
set_nginx_permissions()
|
||||
Logger.print_ok(f"NGINX config for {display_name} successfully created.")
|
||||
except Exception:
|
||||
Logger.print_error(f"Creating NGINX config for {display_name} failed!")
|
||||
raise
|
||||
|
||||
@@ -13,10 +13,10 @@ from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from components.webui_client.base_data import (
|
||||
BaseWebClient,
|
||||
BaseWebClientConfig,
|
||||
WebClientConfigType,
|
||||
WebClientType,
|
||||
BaseWebClient,
|
||||
)
|
||||
from components.webui_client.client_utils import get_download_url
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
|
||||
@@ -13,10 +13,10 @@ from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from components.webui_client.base_data import (
|
||||
BaseWebClient,
|
||||
BaseWebClientConfig,
|
||||
WebClientConfigType,
|
||||
WebClientType,
|
||||
BaseWebClient,
|
||||
)
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
# ======================================================================= #
|
||||
|
||||
import textwrap
|
||||
from typing import Type, Optional
|
||||
from typing import Optional, Type
|
||||
|
||||
from components.webui_client import client_remove
|
||||
from components.webui_client.base_data import BaseWebClient, WebClientType
|
||||
from core.menus import Option
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.constants import RESET_FORMAT, COLOR_RED, COLOR_CYAN
|
||||
from utils.constants import COLOR_CYAN, COLOR_RED, RESET_FORMAT
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
|
||||
@@ -8,11 +8,12 @@
|
||||
# ======================================================================= #
|
||||
|
||||
from __future__ import annotations
|
||||
from abc import abstractmethod, ABC
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from pathlib import Path
|
||||
from typing import List, Optional
|
||||
|
||||
from utils.constants import SYSTEMD, CURRENT_USER
|
||||
from utils.constants import CURRENT_USER, SYSTEMD
|
||||
|
||||
|
||||
class BaseInstance(ABC):
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
import re
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from typing import List, Optional, Union, TypeVar
|
||||
from typing import List, Optional, TypeVar, Union
|
||||
|
||||
from core.instance_manager.base_instance import BaseInstance
|
||||
from utils.constants import SYSTEMD
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from enum import unique, Enum
|
||||
from enum import Enum, unique
|
||||
|
||||
|
||||
@unique
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
from typing import Callable, Any, Union
|
||||
from typing import Any, Callable, Union
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
# ======================================================================= #
|
||||
|
||||
import textwrap
|
||||
from typing import Type, Optional
|
||||
from typing import Optional, Type
|
||||
|
||||
from components.klipper import KLIPPER_DIR
|
||||
from components.klipper.klipper import Klipper
|
||||
|
||||
@@ -8,24 +8,24 @@
|
||||
# ======================================================================= #
|
||||
|
||||
import textwrap
|
||||
from typing import Type, Optional
|
||||
from typing import Optional, Type
|
||||
|
||||
from components.klipper.klipper_utils import backup_klipper_dir
|
||||
from components.klipperscreen.klipperscreen import backup_klipperscreen_dir
|
||||
from components.moonraker.moonraker_utils import (
|
||||
backup_moonraker_dir,
|
||||
backup_moonraker_db_dir,
|
||||
backup_moonraker_dir,
|
||||
)
|
||||
from components.webui_client.client_utils import (
|
||||
backup_client_data,
|
||||
backup_client_config_data,
|
||||
backup_client_data,
|
||||
)
|
||||
from components.webui_client.fluidd_data import FluiddData
|
||||
from components.webui_client.mainsail_data import MainsailData
|
||||
from core.menus import Option
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.common import backup_printer_config_dir
|
||||
from utils.constants import COLOR_CYAN, RESET_FORMAT, COLOR_YELLOW
|
||||
from utils.constants import COLOR_CYAN, COLOR_YELLOW, RESET_FORMAT
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
|
||||
@@ -14,14 +14,14 @@ import sys
|
||||
import textwrap
|
||||
import traceback
|
||||
from abc import abstractmethod
|
||||
from typing import Type, Dict, Optional
|
||||
from typing import Dict, Optional, Type
|
||||
|
||||
from core.menus import FooterType, Option
|
||||
from utils.constants import (
|
||||
COLOR_GREEN,
|
||||
COLOR_YELLOW,
|
||||
COLOR_RED,
|
||||
COLOR_CYAN,
|
||||
COLOR_GREEN,
|
||||
COLOR_RED,
|
||||
COLOR_YELLOW,
|
||||
RESET_FORMAT,
|
||||
)
|
||||
from utils.logger import Logger
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
# ======================================================================= #
|
||||
|
||||
import textwrap
|
||||
from typing import Type, Optional
|
||||
from typing import Optional, Type
|
||||
|
||||
from components.crowsnest.crowsnest import install_crowsnest
|
||||
from components.klipper import klipper_setup
|
||||
@@ -20,7 +20,6 @@ from components.webui_client.client_config import client_config_setup
|
||||
from components.webui_client.fluidd_data import FluiddData
|
||||
from components.webui_client.mainsail_data import MainsailData
|
||||
from core.menus import Option
|
||||
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.constants import COLOR_GREEN, RESET_FORMAT
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
# ======================================================================= #
|
||||
|
||||
import textwrap
|
||||
from typing import Type, Optional
|
||||
from typing import Optional, Type
|
||||
|
||||
from components.crowsnest.crowsnest import remove_crowsnest
|
||||
from components.klipper.menus.klipper_remove_menu import KlipperRemoveMenu
|
||||
|
||||
@@ -7,16 +7,17 @@
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
|
||||
import textwrap
|
||||
import configparser
|
||||
import textwrap
|
||||
from typing import Dict, Union
|
||||
|
||||
from core.config_manager.config_manager import CustomConfigParser
|
||||
from kiauh import PROJECT_ROOT
|
||||
from utils.constants import RESET_FORMAT, COLOR_RED
|
||||
from utils.constants import COLOR_RED, RESET_FORMAT
|
||||
from utils.logger import Logger
|
||||
from utils.sys_utils import kill
|
||||
|
||||
from kiauh import PROJECT_ROOT
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
# noinspection PyMethodMayBeStatic
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
|
||||
from abc import abstractmethod, ABC
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Dict
|
||||
|
||||
|
||||
|
||||
@@ -12,13 +12,13 @@ import inspect
|
||||
import json
|
||||
import textwrap
|
||||
from pathlib import Path
|
||||
from typing import Type, Dict, Optional
|
||||
from typing import Dict, Optional, Type
|
||||
|
||||
from core.menus import Option
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from extensions import EXTENSION_ROOT
|
||||
from extensions.base_extension import BaseExtension
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.constants import RESET_FORMAT, COLOR_CYAN, COLOR_YELLOW
|
||||
from utils.constants import COLOR_CYAN, COLOR_YELLOW, RESET_FORMAT
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
|
||||
@@ -13,14 +13,14 @@ from typing import List
|
||||
|
||||
from components.klipper.klipper import Klipper
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from extensions.base_extension import BaseExtension
|
||||
from core.config_manager.config_manager import ConfigManager
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from extensions.base_extension import BaseExtension
|
||||
from extensions.gcode_shell_cmd import (
|
||||
EXTENSION_TARGET_PATH,
|
||||
EXTENSION_SRC,
|
||||
KLIPPER_DIR,
|
||||
EXAMPLE_CFG_SRC,
|
||||
EXTENSION_SRC,
|
||||
EXTENSION_TARGET_PATH,
|
||||
KLIPPER_DIR,
|
||||
KLIPPER_EXTRAS,
|
||||
)
|
||||
from utils.fs_utils import check_file_exist
|
||||
|
||||
@@ -15,12 +15,11 @@ import subprocess
|
||||
|
||||
from extensions.base_extension import BaseExtension
|
||||
from extensions.klipper_backup import (
|
||||
KLIPPERBACKUP_REPO_URL,
|
||||
KLIPPERBACKUP_DIR,
|
||||
KLIPPERBACKUP_CONFIG_DIR,
|
||||
KLIPPERBACKUP_DIR,
|
||||
KLIPPERBACKUP_REPO_URL,
|
||||
MOONRAKER_CONF,
|
||||
)
|
||||
|
||||
from utils.fs_utils import check_file_exist
|
||||
from utils.input_utils import get_confirm
|
||||
from utils.logger import Logger
|
||||
|
||||
@@ -11,20 +11,19 @@ import csv
|
||||
import shutil
|
||||
import textwrap
|
||||
import urllib.request
|
||||
from typing import List, Union, Optional, Type
|
||||
from typing import TypedDict
|
||||
from typing import List, Optional, Type, TypedDict, Union
|
||||
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.klipper.klipper_dialogs import (
|
||||
print_instance_overview,
|
||||
DisplayType,
|
||||
print_instance_overview,
|
||||
)
|
||||
from core.menus import Option
|
||||
from extensions.base_extension import BaseExtension
|
||||
from core.instance_manager.base_instance import BaseInstance
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.menus import Option
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.constants import COLOR_YELLOW, COLOR_CYAN, RESET_FORMAT
|
||||
from extensions.base_extension import BaseExtension
|
||||
from utils.constants import COLOR_CYAN, COLOR_YELLOW, RESET_FORMAT
|
||||
from utils.git_utils import git_clone_wrapper
|
||||
from utils.input_utils import get_selection_input
|
||||
from utils.logger import Logger
|
||||
|
||||
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}")
|
||||
@@ -8,7 +8,7 @@
|
||||
# ======================================================================= #
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from typing import List, TypeVar, Tuple, Optional
|
||||
from typing import List, Optional, Tuple, TypeVar
|
||||
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
|
||||
@@ -12,16 +12,15 @@
|
||||
import re
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from zipfile import ZipFile
|
||||
from subprocess import run, check_output, CalledProcessError, PIPE, DEVNULL
|
||||
|
||||
from subprocess import DEVNULL, PIPE, CalledProcessError, check_output, run
|
||||
from typing import List
|
||||
from zipfile import ZipFile
|
||||
|
||||
from components.klipper.klipper import Klipper
|
||||
from utils import (
|
||||
NGINX_SITES_AVAILABLE,
|
||||
MODULE_PATH,
|
||||
NGINX_CONFD,
|
||||
NGINX_SITES_AVAILABLE,
|
||||
NGINX_SITES_ENABLED,
|
||||
)
|
||||
from utils.decorators import deprecated
|
||||
@@ -123,21 +122,23 @@ def copy_common_vars_nginx_cfg() -> None:
|
||||
raise
|
||||
|
||||
|
||||
def create_nginx_cfg(name: str, port: int, root_dir: Path) -> None:
|
||||
def generate_nginx_cfg_from_template(name: str, template_src: Path, **kwargs) -> None:
|
||||
"""
|
||||
Creates an NGINX config from a template file and replaces all placeholders
|
||||
Creates an NGINX config from a template file and
|
||||
replaces all placeholders passed as kwargs. A placeholder must be defined
|
||||
in the template file as %{placeholder}%.
|
||||
:param name: name of the config to create
|
||||
:param port: listen port
|
||||
:param root_dir: directory of the static files
|
||||
:param template_src: the path to the template file
|
||||
:return: None
|
||||
"""
|
||||
tmp = Path.home().joinpath(f"{name}.tmp")
|
||||
shutil.copy(MODULE_PATH.joinpath("assets/nginx_cfg"), tmp)
|
||||
shutil.copy(template_src, tmp)
|
||||
with open(tmp, "r+") as f:
|
||||
content = f.read()
|
||||
content = content.replace("%NAME%", name)
|
||||
content = content.replace("%PORT%", str(port))
|
||||
content = content.replace("%ROOT_DIR%", str(root_dir))
|
||||
|
||||
for key, value in kwargs.items():
|
||||
content = content.replace(f"%{key}%", str(value))
|
||||
|
||||
f.seek(0)
|
||||
f.write(content)
|
||||
f.truncate()
|
||||
@@ -152,6 +153,30 @@ def create_nginx_cfg(name: str, port: int, root_dir: Path) -> None:
|
||||
raise
|
||||
|
||||
|
||||
def create_nginx_cfg(
|
||||
display_name: str,
|
||||
cfg_name: str,
|
||||
template_src: Path,
|
||||
**kwargs,
|
||||
) -> None:
|
||||
from utils.sys_utils import set_nginx_permissions
|
||||
|
||||
try:
|
||||
Logger.print_status(f"Creating NGINX config for {display_name} ...")
|
||||
|
||||
source = NGINX_SITES_AVAILABLE.joinpath(cfg_name)
|
||||
target = NGINX_SITES_ENABLED.joinpath(cfg_name)
|
||||
remove_file(Path("/etc/nginx/sites-enabled/default"), True)
|
||||
generate_nginx_cfg_from_template(cfg_name, template_src=template_src, **kwargs)
|
||||
create_symlink(source, target, True)
|
||||
set_nginx_permissions()
|
||||
|
||||
Logger.print_ok(f"NGINX config for {display_name} successfully created.")
|
||||
except Exception:
|
||||
Logger.print_error(f"Creating NGINX config for {display_name} failed!")
|
||||
raise
|
||||
|
||||
|
||||
def read_ports_from_nginx_configs() -> List[int]:
|
||||
"""
|
||||
Helper function to iterate over all NGINX configs and read all ports defined for listen
|
||||
|
||||
@@ -11,13 +11,13 @@ from enum import Enum
|
||||
from typing import List
|
||||
|
||||
from utils.constants import (
|
||||
COLOR_WHITE,
|
||||
COLOR_GREEN,
|
||||
COLOR_YELLOW,
|
||||
COLOR_RED,
|
||||
COLOR_MAGENTA,
|
||||
RESET_FORMAT,
|
||||
COLOR_CYAN,
|
||||
COLOR_GREEN,
|
||||
COLOR_MAGENTA,
|
||||
COLOR_RED,
|
||||
COLOR_WHITE,
|
||||
COLOR_YELLOW,
|
||||
RESET_FORMAT,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -8,24 +8,22 @@
|
||||
# ======================================================================= #
|
||||
|
||||
import os
|
||||
import select
|
||||
import shutil
|
||||
import socket
|
||||
from subprocess import Popen, PIPE, CalledProcessError, run, DEVNULL
|
||||
import sys
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
import venv
|
||||
from pathlib import Path
|
||||
from subprocess import DEVNULL, PIPE, CalledProcessError, Popen, run
|
||||
from typing import List, Literal
|
||||
|
||||
import select
|
||||
|
||||
from utils.fs_utils import check_file_exist
|
||||
from utils.input_utils import get_confirm
|
||||
from utils.logger import Logger
|
||||
|
||||
|
||||
SysCtlServiceAction = Literal[
|
||||
"start",
|
||||
"stop",
|
||||
|
||||
Reference in New Issue
Block a user