daemon: update config service files to use paths for retrieving templates and generating files in the same consistent way
This commit is contained in:
parent
df5ff02f95
commit
44b7b6a27e
13 changed files with 18 additions and 6 deletions
|
@ -19,6 +19,20 @@ logger = logging.getLogger(__name__)
|
||||||
TEMPLATES_DIR: str = "templates"
|
TEMPLATES_DIR: str = "templates"
|
||||||
|
|
||||||
|
|
||||||
|
def get_template_path(file_path: Path) -> str:
|
||||||
|
"""
|
||||||
|
Utility to convert a given file path to a valid template path format.
|
||||||
|
|
||||||
|
:param file_path: file path to convert
|
||||||
|
:return: template path
|
||||||
|
"""
|
||||||
|
if file_path.is_absolute():
|
||||||
|
template_path = str(file_path.relative_to("/"))
|
||||||
|
else:
|
||||||
|
template_path = str(file_path)
|
||||||
|
return template_path
|
||||||
|
|
||||||
|
|
||||||
class ConfigServiceMode(enum.Enum):
|
class ConfigServiceMode(enum.Enum):
|
||||||
BLOCKING = 0
|
BLOCKING = 0
|
||||||
NON_BLOCKING = 1
|
NON_BLOCKING = 1
|
||||||
|
@ -295,10 +309,7 @@ class ConfigService(abc.ABC):
|
||||||
templates = {}
|
templates = {}
|
||||||
for file in self.files:
|
for file in self.files:
|
||||||
file_path = Path(file)
|
file_path = Path(file)
|
||||||
if file_path.is_absolute():
|
template_path = get_template_path(file_path)
|
||||||
template_path = str(file_path.relative_to("/"))
|
|
||||||
else:
|
|
||||||
template_path = str(file_path)
|
|
||||||
if file in self.custom_templates:
|
if file in self.custom_templates:
|
||||||
template = self.custom_templates[file]
|
template = self.custom_templates[file]
|
||||||
template = self.clean_text(template)
|
template = self.clean_text(template)
|
||||||
|
@ -322,11 +333,12 @@ class ConfigService(abc.ABC):
|
||||||
"node(%s) service(%s) template(%s)", self.node.name, self.name, file
|
"node(%s) service(%s) template(%s)", self.node.name, self.name, file
|
||||||
)
|
)
|
||||||
file_path = Path(file)
|
file_path = Path(file)
|
||||||
|
template_path = get_template_path(file_path)
|
||||||
if file in self.custom_templates:
|
if file in self.custom_templates:
|
||||||
text = self.custom_templates[file]
|
text = self.custom_templates[file]
|
||||||
rendered = self.render_text(text, data)
|
rendered = self.render_text(text, data)
|
||||||
elif self.templates.has_template(file_path.name):
|
elif self.templates.has_template(template_path):
|
||||||
rendered = self.render_template(file_path.name, data)
|
rendered = self.render_template(template_path, data)
|
||||||
else:
|
else:
|
||||||
text = self.get_text_template(file)
|
text = self.get_text_template(file)
|
||||||
rendered = self.render_text(text, data)
|
rendered = self.render_text(text, data)
|
||||||
|
|
Loading…
Add table
Reference in a new issue