mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-24 00:03:42 +05:00
chore: fix lint issues
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
import textwrap
|
import textwrap
|
||||||
from enum import Enum, unique
|
from enum import Enum, unique
|
||||||
from typing import List, Union, Literal
|
from typing import List
|
||||||
|
|
||||||
from core.instance_manager.base_instance import BaseInstance
|
from core.instance_manager.base_instance import BaseInstance
|
||||||
from core.menus.base_menu import print_back_footer
|
from core.menus.base_menu import print_back_footer
|
||||||
|
|||||||
@@ -50,5 +50,5 @@ def upload_logfile(logfile: LogFile) -> None:
|
|||||||
Logger.print_ok("Upload successful! Access it via the following link:")
|
Logger.print_ok("Upload successful! Access it via the following link:")
|
||||||
Logger.print_ok(f">>>> {link}", False)
|
Logger.print_ok(f">>>> {link}", False)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Logger.print_error(f"Uploading logfile failed!")
|
Logger.print_error("Uploading logfile failed!")
|
||||||
Logger.print_error(str(e))
|
Logger.print_error(str(e))
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Literal, TypedDict, Set
|
from typing import Literal, TypedDict
|
||||||
|
|
||||||
from core.backup_manager import BACKUP_ROOT_DIR
|
from core.backup_manager import BACKUP_ROOT_DIR
|
||||||
|
|
||||||
|
|||||||
@@ -16,34 +16,34 @@ from core.instance_manager.base_instance import BaseInstance
|
|||||||
from utils.constants import SYSTEMD
|
from utils.constants import SYSTEMD
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
|
|
||||||
I = TypeVar(name="I", bound=BaseInstance, covariant=True)
|
T = TypeVar(name="T", bound=BaseInstance, covariant=True)
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyMethodMayBeStatic
|
# noinspection PyMethodMayBeStatic
|
||||||
class InstanceManager:
|
class InstanceManager:
|
||||||
def __init__(self, instance_type: I) -> None:
|
def __init__(self, instance_type: T) -> None:
|
||||||
self._instance_type = instance_type
|
self._instance_type = instance_type
|
||||||
self._current_instance: Optional[I] = None
|
self._current_instance: Optional[T] = None
|
||||||
self._instance_suffix: Optional[str] = None
|
self._instance_suffix: Optional[str] = None
|
||||||
self._instance_service: Optional[str] = None
|
self._instance_service: Optional[str] = None
|
||||||
self._instance_service_full: Optional[str] = None
|
self._instance_service_full: Optional[str] = None
|
||||||
self._instance_service_path: Optional[str] = None
|
self._instance_service_path: Optional[str] = None
|
||||||
self._instances: List[I] = []
|
self._instances: List[T] = []
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def instance_type(self) -> I:
|
def instance_type(self) -> T:
|
||||||
return self._instance_type
|
return self._instance_type
|
||||||
|
|
||||||
@instance_type.setter
|
@instance_type.setter
|
||||||
def instance_type(self, value: I):
|
def instance_type(self, value: T):
|
||||||
self._instance_type = value
|
self._instance_type = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_instance(self) -> I:
|
def current_instance(self) -> T:
|
||||||
return self._current_instance
|
return self._current_instance
|
||||||
|
|
||||||
@current_instance.setter
|
@current_instance.setter
|
||||||
def current_instance(self, value: I) -> None:
|
def current_instance(self, value: T) -> None:
|
||||||
self._current_instance = value
|
self._current_instance = value
|
||||||
self.instance_suffix = value.suffix
|
self.instance_suffix = value.suffix
|
||||||
self.instance_service = value.get_service_file_name()
|
self.instance_service = value.get_service_file_name()
|
||||||
@@ -78,11 +78,11 @@ class InstanceManager:
|
|||||||
self._instance_service_path = value
|
self._instance_service_path = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def instances(self) -> List[I]:
|
def instances(self) -> List[T]:
|
||||||
return self.find_instances()
|
return self.find_instances()
|
||||||
|
|
||||||
@instances.setter
|
@instances.setter
|
||||||
def instances(self, value: List[I]):
|
def instances(self, value: List[T]):
|
||||||
self._instances = value
|
self._instances = value
|
||||||
|
|
||||||
def create_instance(self) -> None:
|
def create_instance(self) -> None:
|
||||||
@@ -182,7 +182,7 @@ class InstanceManager:
|
|||||||
Logger.print_error(f"{e}")
|
Logger.print_error(f"{e}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def find_instances(self) -> List[I]:
|
def find_instances(self) -> List[T]:
|
||||||
name = self.instance_type.__name__.lower()
|
name = self.instance_type.__name__.lower()
|
||||||
pattern = re.compile(f"^{name}(-[0-9a-zA-Z]+)?.service$")
|
pattern = re.compile(f"^{name}(-[0-9a-zA-Z]+)?.service$")
|
||||||
excluded = self.instance_type.blacklist()
|
excluded = self.instance_type.blacklist()
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import os
|
|
||||||
|
|
||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
|
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||||
@@ -209,9 +208,8 @@ def add_config_section(
|
|||||||
|
|
||||||
cm.write_config()
|
cm.write_config()
|
||||||
|
|
||||||
def add_config_section_at_top(
|
|
||||||
section: str,
|
def add_config_section_at_top(section: str, instances: List[B]):
|
||||||
instances: List[B]):
|
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
tmp_cfg = tempfile.NamedTemporaryFile(mode="w", delete=False)
|
tmp_cfg = tempfile.NamedTemporaryFile(mode="w", delete=False)
|
||||||
tmp_cfg_path = Path(tmp_cfg.name)
|
tmp_cfg_path = Path(tmp_cfg.name)
|
||||||
|
|||||||
Reference in New Issue
Block a user