daemon: updating core.configservice and core.configservices to avoid deprecated type hinting
This commit is contained in:
parent
e770bcd47c
commit
3d722a7721
8 changed files with 345 additions and 346 deletions
|
@ -5,7 +5,7 @@ import logging
|
|||
import time
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional
|
||||
from typing import Any, Optional
|
||||
|
||||
from mako import exceptions
|
||||
from mako.lookup import TemplateLookup
|
||||
|
@ -67,7 +67,7 @@ class ConfigService(abc.ABC):
|
|||
validation_timer: int = 5
|
||||
|
||||
# directories to shadow and copy files from
|
||||
shadow_directories: List[ShadowDir] = []
|
||||
shadow_directories: list[ShadowDir] = []
|
||||
|
||||
def __init__(self, node: CoreNode) -> None:
|
||||
"""
|
||||
|
@ -79,9 +79,9 @@ class ConfigService(abc.ABC):
|
|||
class_file = inspect.getfile(self.__class__)
|
||||
templates_path = Path(class_file).parent.joinpath(TEMPLATES_DIR)
|
||||
self.templates: TemplateLookup = TemplateLookup(directories=templates_path)
|
||||
self.config: Dict[str, Configuration] = {}
|
||||
self.custom_templates: Dict[str, str] = {}
|
||||
self.custom_config: Dict[str, str] = {}
|
||||
self.config: dict[str, Configuration] = {}
|
||||
self.custom_templates: dict[str, str] = {}
|
||||
self.custom_config: dict[str, str] = {}
|
||||
configs = self.default_configs[:]
|
||||
self._define_config(configs)
|
||||
|
||||
|
@ -108,47 +108,47 @@ class ConfigService(abc.ABC):
|
|||
|
||||
@property
|
||||
@abc.abstractmethod
|
||||
def directories(self) -> List[str]:
|
||||
def directories(self) -> list[str]:
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
@abc.abstractmethod
|
||||
def files(self) -> List[str]:
|
||||
def files(self) -> list[str]:
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
@abc.abstractmethod
|
||||
def default_configs(self) -> List[Configuration]:
|
||||
def default_configs(self) -> list[Configuration]:
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
@abc.abstractmethod
|
||||
def modes(self) -> Dict[str, Dict[str, str]]:
|
||||
def modes(self) -> dict[str, dict[str, str]]:
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
@abc.abstractmethod
|
||||
def executables(self) -> List[str]:
|
||||
def executables(self) -> list[str]:
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
@abc.abstractmethod
|
||||
def dependencies(self) -> List[str]:
|
||||
def dependencies(self) -> list[str]:
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
@abc.abstractmethod
|
||||
def startup(self) -> List[str]:
|
||||
def startup(self) -> list[str]:
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
@abc.abstractmethod
|
||||
def validate(self) -> List[str]:
|
||||
def validate(self) -> list[str]:
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
@abc.abstractmethod
|
||||
def shutdown(self) -> List[str]:
|
||||
def shutdown(self) -> list[str]:
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
|
@ -276,7 +276,7 @@ class ConfigService(abc.ABC):
|
|||
f"failure to create service directory: {directory}"
|
||||
)
|
||||
|
||||
def data(self) -> Dict[str, Any]:
|
||||
def data(self) -> dict[str, Any]:
|
||||
"""
|
||||
Returns key/value data, used when rendering file templates.
|
||||
|
||||
|
@ -303,7 +303,7 @@ class ConfigService(abc.ABC):
|
|||
"""
|
||||
raise CoreError(f"service({self.name}) unknown template({name})")
|
||||
|
||||
def get_templates(self) -> Dict[str, str]:
|
||||
def get_templates(self) -> dict[str, str]:
|
||||
"""
|
||||
Retrieves mapping of file names to templates for all cases, which
|
||||
includes custom templates, file templates, and text templates.
|
||||
|
@ -331,7 +331,7 @@ class ConfigService(abc.ABC):
|
|||
templates[file] = template
|
||||
return templates
|
||||
|
||||
def get_rendered_templates(self) -> Dict[str, str]:
|
||||
def get_rendered_templates(self) -> dict[str, str]:
|
||||
templates = {}
|
||||
data = self.data()
|
||||
for file in sorted(self.files):
|
||||
|
@ -339,7 +339,7 @@ class ConfigService(abc.ABC):
|
|||
templates[file] = rendered
|
||||
return templates
|
||||
|
||||
def _get_rendered_template(self, file: str, data: Dict[str, Any]) -> str:
|
||||
def _get_rendered_template(self, file: str, data: dict[str, Any]) -> str:
|
||||
file_path = Path(file)
|
||||
template_path = get_template_path(file_path)
|
||||
if file in self.custom_templates:
|
||||
|
@ -426,7 +426,7 @@ class ConfigService(abc.ABC):
|
|||
f"node({self.node.name}) service({self.name}) failed to validate"
|
||||
)
|
||||
|
||||
def _render(self, template: Template, data: Dict[str, Any] = None) -> str:
|
||||
def _render(self, template: Template, data: dict[str, Any] = None) -> str:
|
||||
"""
|
||||
Renders template providing all associated data to template.
|
||||
|
||||
|
@ -440,7 +440,7 @@ class ConfigService(abc.ABC):
|
|||
node=self.node, config=self.render_config(), **data
|
||||
)
|
||||
|
||||
def render_text(self, text: str, data: Dict[str, Any] = None) -> str:
|
||||
def render_text(self, text: str, data: dict[str, Any] = None) -> str:
|
||||
"""
|
||||
Renders text based template providing all associated data to template.
|
||||
|
||||
|
@ -458,7 +458,7 @@ class ConfigService(abc.ABC):
|
|||
f"{exceptions.text_error_template().render_unicode()}"
|
||||
)
|
||||
|
||||
def render_template(self, template_path: str, data: Dict[str, Any] = None) -> str:
|
||||
def render_template(self, template_path: str, data: dict[str, Any] = None) -> str:
|
||||
"""
|
||||
Renders file based template providing all associated data to template.
|
||||
|
||||
|
@ -475,7 +475,7 @@ class ConfigService(abc.ABC):
|
|||
f"{exceptions.text_error_template().render_unicode()}"
|
||||
)
|
||||
|
||||
def _define_config(self, configs: List[Configuration]) -> None:
|
||||
def _define_config(self, configs: list[Configuration]) -> None:
|
||||
"""
|
||||
Initializes default configuration data.
|
||||
|
||||
|
@ -485,7 +485,7 @@ class ConfigService(abc.ABC):
|
|||
for config in configs:
|
||||
self.config[config.id] = config
|
||||
|
||||
def render_config(self) -> Dict[str, str]:
|
||||
def render_config(self) -> dict[str, str]:
|
||||
"""
|
||||
Returns configuration data key/value pairs for rendering a template.
|
||||
|
||||
|
@ -496,7 +496,7 @@ class ConfigService(abc.ABC):
|
|||
else:
|
||||
return {k: v.default for k, v in self.config.items()}
|
||||
|
||||
def set_config(self, data: Dict[str, str]) -> None:
|
||||
def set_config(self, data: dict[str, str]) -> None:
|
||||
"""
|
||||
Set configuration data from key/value pairs.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue