mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Fix and enh variables for app resources
Co-authored-by: Alexandre Aubin <alex.aubin@mailoo.org>
This commit is contained in:
parent
38b1c53f8a
commit
835303200d
1 changed files with 7 additions and 4 deletions
|
@ -152,26 +152,29 @@ class AppResource:
|
||||||
"__APP__": self.app,
|
"__APP__": self.app,
|
||||||
"__YNH_ARCH__": system_arch(),
|
"__YNH_ARCH__": system_arch(),
|
||||||
"__YNH_DEBIAN_VERSION__": debian_version(),
|
"__YNH_DEBIAN_VERSION__": debian_version(),
|
||||||
|
"__YNH_APP_UPSTREAM_VERSION__": manager.wanted["version"].split("~")[0] if manager.wanted else manager.current["version"].split("~")[0],
|
||||||
}
|
}
|
||||||
|
|
||||||
def recursive_apply(function: Callable, data: Any) -> Any:
|
def recursive_apply(function: Callable, data: Any) -> Any:
|
||||||
if isinstance(data, dict): # FIXME: hashable?
|
if isinstance(data, dict): # FIXME: hashable?
|
||||||
return {
|
return {
|
||||||
key: recursive_apply(value, function) for key, value in data.items()
|
key: recursive_apply(function, value) for key, value in data.items()
|
||||||
}
|
}
|
||||||
|
|
||||||
if isinstance(data, list): # FIXME: iterable?
|
if isinstance(data, list): # FIXME: iterable?
|
||||||
return [recursive_apply(value, function) for value in data]
|
return [recursive_apply(function, value) for value in data]
|
||||||
|
|
||||||
return function(data)
|
return function(data)
|
||||||
|
|
||||||
def replace_tokens_in_strings(data: Any):
|
def replace_tokens_in_strings(data: Any):
|
||||||
if not isinstance(data, str):
|
if not isinstance(data, str):
|
||||||
return
|
return data
|
||||||
for token, replacement in replacements.items():
|
for token, replacement in replacements.items():
|
||||||
data = data.replace(token, replacement)
|
data = data.replace(token, replacement)
|
||||||
|
|
||||||
recursive_apply(replace_tokens_in_strings, properties)
|
return data
|
||||||
|
|
||||||
|
properties = recursive_apply(replace_tokens_in_strings, properties)
|
||||||
|
|
||||||
for key, value in properties.items():
|
for key, value in properties.items():
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
|
|
Loading…
Add table
Reference in a new issue