mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-23 07:43:36 +05:00
refactor(klipper): use name "klipper" for single instance setup
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -39,9 +39,7 @@ class InstanceManager:
|
||||
|
||||
def set_current_instance(self, instance: BaseInstance) -> None:
|
||||
self.current_instance = instance
|
||||
self.instance_name = (
|
||||
f"{instance.prefix}-{instance.name}" if instance.name else instance.prefix
|
||||
)
|
||||
self.instance_name = instance.name
|
||||
|
||||
def create_instance(self) -> None:
|
||||
if self.current_instance is not None:
|
||||
@@ -123,13 +121,16 @@ class InstanceManager:
|
||||
|
||||
def _find_instances(self) -> None:
|
||||
prefix = self.instance_type.__name__.lower()
|
||||
pattern = re.compile(f"{prefix}(-[0-9a-zA-Z]+)?.service")
|
||||
single_pattern = re.compile(f"^{prefix}.service$")
|
||||
multi_pattern = re.compile(f"^{prefix}(-[0-9a-zA-Z]+)?.service$")
|
||||
|
||||
excluded = self.instance_type.blacklist()
|
||||
service_list = [
|
||||
os.path.join(SYSTEMD, service)
|
||||
for service in os.listdir(SYSTEMD)
|
||||
if pattern.search(service) and not any(s in service for s in excluded)
|
||||
if multi_pattern.search(service)
|
||||
and not any(s in service for s in excluded)
|
||||
or single_pattern.search(service)
|
||||
]
|
||||
|
||||
instance_list = [
|
||||
@@ -141,10 +142,8 @@ class InstanceManager:
|
||||
|
||||
def _get_instance_name(self, file_path: Path) -> Union[str, None]:
|
||||
full_name = str(file_path).split("/")[-1].split(".")[0]
|
||||
if full_name.isalnum():
|
||||
return None
|
||||
|
||||
return full_name.split("-")[-1]
|
||||
return full_name.split("-")[-1] if "-" in full_name else full_name
|
||||
|
||||
def _sort_instance_list(self, s):
|
||||
if s is None:
|
||||
|
||||
@@ -26,7 +26,7 @@ from kiauh.utils.system_utils import create_directory
|
||||
class Klipper(BaseInstance):
|
||||
@classmethod
|
||||
def blacklist(cls) -> List[str]:
|
||||
return ["None", "mcu"]
|
||||
return ["None", "klipper", "mcu"]
|
||||
|
||||
def __init__(self, name: str):
|
||||
super().__init__(
|
||||
@@ -117,7 +117,7 @@ class Klipper(BaseInstance):
|
||||
Logger.print_ok(f"Env file created: {env_file_target}")
|
||||
|
||||
def get_service_file_name(self, extension=False) -> str:
|
||||
name = self.prefix if self.name is None else self.prefix + "-" + self.name
|
||||
name = "klipper" if self.name == self.prefix else self.prefix + "-" + self.name
|
||||
return name if not extension else f"{name}.service"
|
||||
|
||||
def _get_service_file_path(self):
|
||||
@@ -138,7 +138,7 @@ class Klipper(BaseInstance):
|
||||
Logger.print_ok("Directories successfully deleted.")
|
||||
|
||||
def _get_data_dir_from_name(self, name: str) -> str:
|
||||
if name is None:
|
||||
if name == "klipper":
|
||||
return "printer"
|
||||
elif int(name.isdigit()):
|
||||
return f"printer_{name}"
|
||||
|
||||
@@ -185,10 +185,14 @@ def set_instance_names(instance_list, install_count: int) -> List[Union[str, Non
|
||||
|
||||
# new single instance install
|
||||
if instance_count == 0 and install_count == 1:
|
||||
return [None]
|
||||
return ["klipper"]
|
||||
|
||||
# convert single instance install to multi install
|
||||
elif instance_count == 1 and instance_list[0].name is None and install_count >= 1:
|
||||
elif (
|
||||
instance_count == 1
|
||||
and instance_list[0].name == "klipper"
|
||||
and install_count >= 1
|
||||
):
|
||||
return handle_convert_single_to_multi_instance_names(install_count)
|
||||
|
||||
# new multi instance install
|
||||
|
||||
@@ -68,7 +68,7 @@ def get_string_input(question: str, exclude=Optional[List], default=None) -> str
|
||||
while True:
|
||||
_input = input(format_question(question, default)).strip()
|
||||
|
||||
if _input.isalnum() and _input not in exclude:
|
||||
if _input.isalnum() and _input.lower() not in exclude:
|
||||
return _input
|
||||
|
||||
Logger.print_error(INVALID_CHOICE)
|
||||
|
||||
Reference in New Issue
Block a user