mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Apply __APP__ -> self.app recursively thanks to recursive_apply
This commit is contained in:
parent
dc8f51e2f8
commit
7981653c23
1 changed files with 12 additions and 6 deletions
|
@ -34,6 +34,7 @@ from moulinette.utils.filesystem import (
|
||||||
)
|
)
|
||||||
from yunohost.utils.system import system_arch
|
from yunohost.utils.system import system_arch
|
||||||
from yunohost.utils.error import YunohostError, YunohostValidationError
|
from yunohost.utils.error import YunohostError, YunohostValidationError
|
||||||
|
from yunohost.utils.algorithms import recursive_apply
|
||||||
|
|
||||||
logger = getActionLogger("yunohost.app_resources")
|
logger = getActionLogger("yunohost.app_resources")
|
||||||
|
|
||||||
|
@ -146,15 +147,20 @@ class AppResource:
|
||||||
def __init__(self, properties: Dict[str, Any], app: str, manager=None):
|
def __init__(self, properties: Dict[str, Any], app: str, manager=None):
|
||||||
self.app = app
|
self.app = app
|
||||||
self.manager = manager
|
self.manager = manager
|
||||||
|
properties = self.default_properties | properties
|
||||||
|
|
||||||
for key, value in self.default_properties.items():
|
replacements: dict[str, str] = {
|
||||||
if isinstance(value, str):
|
"__APP__": self.app,
|
||||||
value = value.replace("__APP__", self.app)
|
}
|
||||||
setattr(self, key, value)
|
|
||||||
|
def replace_tokens_in_strings(data: Any):
|
||||||
|
if not isinstance(data, str):
|
||||||
|
return
|
||||||
|
for token, replacement in replacements.items():
|
||||||
|
data = data.replace(token, replacement)
|
||||||
|
recursive_apply(replace_tokens_in_strings, properties)
|
||||||
|
|
||||||
for key, value in properties.items():
|
for key, value in properties.items():
|
||||||
if isinstance(value, str):
|
|
||||||
value = value.replace("__APP__", self.app)
|
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
|
|
||||||
def get_setting(self, key):
|
def get_setting(self, key):
|
||||||
|
|
Loading…
Add table
Reference in a new issue