mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-13 18:44:29 +05:00
fix(spoolman): ensure proper file handling when adding Spoolman entry
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
from pathlib import Path
|
||||||
from subprocess import CalledProcessError, run
|
from subprocess import CalledProcessError, run
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
|
|
||||||
@@ -311,13 +312,19 @@ class SpoolmanExtension(BaseExtension):
|
|||||||
mrsvc.load_instances()
|
mrsvc.load_instances()
|
||||||
mr_instances = mrsvc.get_all_instances()
|
mr_instances = mrsvc.get_all_instances()
|
||||||
for instance in mr_instances:
|
for instance in mr_instances:
|
||||||
asvc_path = instance.data_dir.joinpath("moonraker.asvc")
|
asvc_path: Path = instance.data_dir.joinpath("moonraker.asvc")
|
||||||
if asvc_path.exists():
|
if asvc_path.exists() and asvc_path.is_file():
|
||||||
if "Spoolman" in open(asvc_path).read():
|
with open(asvc_path, "a+") as f:
|
||||||
Logger.print_info(f"Spoolman already in {asvc_path}. Skipping...")
|
if "Spoolman" in f.read():
|
||||||
continue
|
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")
|
f.write("Spoolman\n")
|
||||||
|
|
||||||
Logger.print_ok(f"Spoolman added to {asvc_path}!")
|
Logger.print_ok(f"Spoolman added to {asvc_path}!")
|
||||||
|
|||||||
Reference in New Issue
Block a user