mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-25 16:53:36 +05:00
refactor(KIAUH): big refactor of instance handling
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
|
||||
from abc import abstractmethod, ABC
|
||||
from pathlib import Path
|
||||
from typing import List, Union, Optional, Type, TypeVar
|
||||
from typing import List, Type, TypeVar
|
||||
|
||||
from kiauh.utils.constants import SYSTEMD, CURRENT_USER
|
||||
|
||||
@@ -25,7 +25,7 @@ class BaseInstance(ABC):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
suffix: Optional[str],
|
||||
suffix: str,
|
||||
instance_type: B = B,
|
||||
):
|
||||
self._instance_type = instance_type
|
||||
@@ -52,7 +52,7 @@ class BaseInstance(ABC):
|
||||
return self._suffix
|
||||
|
||||
@suffix.setter
|
||||
def suffix(self, value: Union[str, None]) -> None:
|
||||
def suffix(self, value: str) -> None:
|
||||
self._suffix = value
|
||||
|
||||
@property
|
||||
@@ -144,7 +144,7 @@ class BaseInstance(ABC):
|
||||
|
||||
def get_service_file_name(self, extension: bool = False) -> str:
|
||||
name = f"{self.__class__.__name__.lower()}"
|
||||
if self.suffix is not None:
|
||||
if self.suffix != "":
|
||||
name += f"-{self.suffix}"
|
||||
|
||||
return name if not extension else f"{name}.service"
|
||||
@@ -153,7 +153,7 @@ class BaseInstance(ABC):
|
||||
return SYSTEMD.joinpath(self.get_service_file_name(extension=True))
|
||||
|
||||
def get_data_dir_name_from_suffix(self) -> str:
|
||||
if self._suffix is None:
|
||||
if self._suffix == "":
|
||||
return "printer"
|
||||
elif self._suffix.isdigit():
|
||||
return f"printer_{self._suffix}"
|
||||
|
||||
@@ -207,10 +207,8 @@ class InstanceManager:
|
||||
|
||||
return instance_list
|
||||
|
||||
def _get_instance_suffix(self, file_path: Path) -> Union[str, None]:
|
||||
full_name = file_path.name.split(".")[0]
|
||||
|
||||
return full_name.split("-")[-1] if "-" in full_name else None
|
||||
def _get_instance_suffix(self, file_path: Path) -> str:
|
||||
return file_path.stem.split("-")[-1] if "-" in file_path.stem else ""
|
||||
|
||||
def _sort_instance_list(self, s: Union[int, str, None]):
|
||||
if s is None:
|
||||
|
||||
8
kiauh/core/instance_manager/name_scheme.py
Normal file
8
kiauh/core/instance_manager/name_scheme.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from enum import unique, Enum
|
||||
|
||||
|
||||
@unique
|
||||
class NameScheme(Enum):
|
||||
SINGLE = "SINGLE"
|
||||
INDEX = "INDEX"
|
||||
CUSTOM = "CUSTOM"
|
||||
Reference in New Issue
Block a user