feat: implement conversion of camel case to kebab case

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2024-05-05 15:08:24 +02:00
parent e986dfbf4c
commit 3885405366
3 changed files with 11 additions and 3 deletions

View File

@@ -140,7 +140,9 @@ class BaseInstance(ABC):
_dir.mkdir(exist_ok=True) _dir.mkdir(exist_ok=True)
def get_service_file_name(self, extension: bool = False) -> str: def get_service_file_name(self, extension: bool = False) -> str:
name = f"{self.__class__.__name__.lower()}" from utils.common import convert_camelcase_to_kebabcase
name = convert_camelcase_to_kebabcase(self.__class__.__name__)
if self.suffix != "": if self.suffix != "":
name += f"-{self.suffix}" name += f"-{self.suffix}"

View File

@@ -174,7 +174,9 @@ class InstanceManager:
raise raise
def find_instances(self) -> List[T]: def find_instances(self) -> List[T]:
name = self.instance_type.__name__.lower() from utils.common import convert_camelcase_to_kebabcase
name = convert_camelcase_to_kebabcase(self.instance_type.__name__)
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()

View File

@@ -6,7 +6,7 @@
# # # #
# This file may be distributed under the terms of the GNU GPLv3 license # # This file may be distributed under the terms of the GNU GPLv3 license #
# ======================================================================= # # ======================================================================= #
import re
from datetime import datetime from datetime import datetime
from pathlib import Path from pathlib import Path
from typing import Dict, Literal, List, Type, Union from typing import Dict, Literal, List, Type, Union
@@ -30,6 +30,10 @@ from utils.sys_utils import (
) )
def convert_camelcase_to_kebabcase(name: str) -> str:
return re.sub(r"(?<!^)(?=[A-Z])", "-", name).lower()
def get_current_date() -> Dict[Literal["date", "time"], str]: def get_current_date() -> Dict[Literal["date", "time"], str]:
""" """
Get the current date | Get the current date |