mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-13 10:34:28 +05:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
372bab8847 | ||
|
|
d5062d41de | ||
|
|
e9459bd68e | ||
|
|
ee460663c9 | ||
|
|
6f0e0146ef | ||
|
|
229f317025 | ||
|
|
48c0ae7227 |
@@ -237,7 +237,6 @@ def install_input_shaper_deps() -> None:
|
||||
"If you agree, the following additional system packages will be installed:",
|
||||
"● python3-numpy",
|
||||
"● python3-matplotlib",
|
||||
"● libatlas-base-dev",
|
||||
"● libopenblas-dev",
|
||||
"\n\n",
|
||||
"Also, the following Python package will be installed:",
|
||||
@@ -253,7 +252,6 @@ def install_input_shaper_deps() -> None:
|
||||
apt_deps = (
|
||||
"python3-numpy",
|
||||
"python3-matplotlib",
|
||||
"libatlas-base-dev",
|
||||
"libopenblas-dev",
|
||||
)
|
||||
check_install_dependencies({*apt_deps})
|
||||
|
||||
@@ -11,6 +11,7 @@ from __future__ import annotations
|
||||
import json
|
||||
import re
|
||||
import shutil
|
||||
from json import JSONDecodeError
|
||||
from pathlib import Path
|
||||
from subprocess import PIPE, CalledProcessError, run
|
||||
from typing import List, get_args
|
||||
@@ -151,18 +152,36 @@ def symlink_webui_nginx_log(
|
||||
def get_local_client_version(client: BaseWebClient) -> str | None:
|
||||
relinfo_file = client.client_dir.joinpath("release_info.json")
|
||||
version_file = client.client_dir.joinpath(".version")
|
||||
default = "n/a"
|
||||
|
||||
if not client.client_dir.exists():
|
||||
return None
|
||||
if not relinfo_file.is_file() and not version_file.is_file():
|
||||
return "n/a"
|
||||
return default
|
||||
|
||||
# try to get version from release_info.json first
|
||||
if relinfo_file.is_file():
|
||||
with open(relinfo_file, "r") as f:
|
||||
return str(json.load(f)["version"])
|
||||
else:
|
||||
with open(version_file, "r") as f:
|
||||
return f.readlines()[0]
|
||||
try:
|
||||
if relinfo_file.stat().st_size == 0:
|
||||
raise JSONDecodeError("Empty file", "", 0)
|
||||
with open(relinfo_file, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
raw_version = data.get("version")
|
||||
if raw_version is not None:
|
||||
parsed = str(raw_version).strip()
|
||||
if parsed:
|
||||
return parsed
|
||||
except (JSONDecodeError, OSError):
|
||||
Logger.print_error("Invalid 'release_info.json'")
|
||||
|
||||
# fallback to .version file
|
||||
if version_file.is_file():
|
||||
try:
|
||||
with open(version_file, "r") as f:
|
||||
line = f.readline().strip()
|
||||
return line or default
|
||||
except OSError:
|
||||
Logger.print_error("Unable to read '.version'")
|
||||
|
||||
return default
|
||||
|
||||
|
||||
def get_remote_client_version(client: BaseWebClient) -> str | None:
|
||||
|
||||
@@ -58,7 +58,7 @@ class BackupMenu(BaseMenu):
|
||||
|
||||
def print_menu(self) -> None:
|
||||
line1 = Color.apply(
|
||||
"INFO: Backups are located in '~/kiauh-backups'", Color.YELLOW
|
||||
"INFO: Backups are located in '~/kiauh_backups'", Color.YELLOW
|
||||
)
|
||||
menu = textwrap.dedent(
|
||||
f"""
|
||||
|
||||
@@ -62,16 +62,16 @@ class BackupService:
|
||||
target_name
|
||||
or f"{source_path.stem}_{self.timestamp}{source_path.suffix}"
|
||||
)
|
||||
if target_path is not None:
|
||||
backup_path = self._backup_root.joinpath(target_path, filename)
|
||||
else:
|
||||
backup_path = self._backup_root.joinpath(filename)
|
||||
|
||||
backup_path.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy2(source_path, backup_path)
|
||||
backup_dir = self._backup_root
|
||||
if target_path is not None:
|
||||
backup_dir = self._backup_root.joinpath(target_path)
|
||||
|
||||
backup_dir.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy2(source_path, backup_dir.joinpath(filename))
|
||||
|
||||
Logger.print_ok(
|
||||
f"Successfully backed up '{source_path}' to '{backup_path}'"
|
||||
f"Successfully backed up '{source_path}' to '{backup_dir}'"
|
||||
)
|
||||
return True
|
||||
|
||||
@@ -109,7 +109,16 @@ class BackupService:
|
||||
else:
|
||||
backup_path = self._backup_root.joinpath(backup_dir_name)
|
||||
|
||||
shutil.copytree(source_path, backup_path)
|
||||
if backup_path.exists():
|
||||
Logger.print_info(f"Reusing existing backup directory '{backup_path}'")
|
||||
|
||||
shutil.copytree(
|
||||
source_path,
|
||||
backup_path,
|
||||
dirs_exist_ok=True,
|
||||
symlinks=True,
|
||||
ignore_dangling_symlinks=True,
|
||||
)
|
||||
|
||||
Logger.print_ok(
|
||||
f"Successfully backed up '{source_path}' to '{backup_path}'"
|
||||
|
||||
@@ -16,6 +16,7 @@ class ShellCommand:
|
||||
self.gcode = self.printer.lookup_object("gcode")
|
||||
cmd = config.get("command")
|
||||
cmd = os.path.expanduser(cmd)
|
||||
cmd = os.path.expandvars(cmd)
|
||||
self.command = shlex.split(cmd)
|
||||
self.timeout = config.getfloat("timeout", 2.0, above=0.0)
|
||||
self.verbose = config.getboolean("verbose", True)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
# ======================================================================= #
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
from subprocess import CalledProcessError, run
|
||||
from typing import List, Tuple
|
||||
|
||||
@@ -311,13 +312,19 @@ class SpoolmanExtension(BaseExtension):
|
||||
mrsvc.load_instances()
|
||||
mr_instances = mrsvc.get_all_instances()
|
||||
for instance in mr_instances:
|
||||
asvc_path = instance.data_dir.joinpath("moonraker.asvc")
|
||||
if asvc_path.exists():
|
||||
if "Spoolman" in open(asvc_path).read():
|
||||
Logger.print_info(f"Spoolman already in {asvc_path}. Skipping...")
|
||||
continue
|
||||
asvc_path: Path = instance.data_dir.joinpath("moonraker.asvc")
|
||||
if asvc_path.exists() and asvc_path.is_file():
|
||||
with open(asvc_path, "a+") as f:
|
||||
if "Spoolman" in f.read():
|
||||
Logger.print_info(
|
||||
f"Spoolman already in {asvc_path}. Skipping..."
|
||||
)
|
||||
continue
|
||||
|
||||
content: List[str] = f.readlines()
|
||||
if content and not content[-1].endswith("\n"):
|
||||
f.write("\n")
|
||||
|
||||
with open(asvc_path, "a") as f:
|
||||
f.write("Spoolman\n")
|
||||
|
||||
Logger.print_ok(f"Spoolman added to {asvc_path}!")
|
||||
|
||||
Reference in New Issue
Block a user