mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Move recursive_apply directly where it's used, having a small algorithms.py just for this is too convoluted
This commit is contained in:
parent
fb2ca1f27d
commit
0864014ea1
2 changed files with 11 additions and 15 deletions
|
@ -1,13 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from typing import Any, Callable
|
||||
|
||||
|
||||
def recursive_apply(function: Callable, data: Any) -> Any:
|
||||
if isinstance(data, dict): # FIXME: hashable?
|
||||
return {key: recursive_apply(value, function) for key, value in data.items()}
|
||||
|
||||
if isinstance(data, list): # FIXME: iterable?
|
||||
return [recursive_apply(value, function) for value in data]
|
||||
|
||||
return function(data)
|
|
@ -22,7 +22,7 @@ import shutil
|
|||
import random
|
||||
import tempfile
|
||||
import subprocess
|
||||
from typing import Dict, Any, List, Union
|
||||
from typing import Dict, Any, List, Union, Callable
|
||||
|
||||
from moulinette import m18n
|
||||
from moulinette.utils.text import random_ascii
|
||||
|
@ -34,7 +34,6 @@ from moulinette.utils.filesystem import (
|
|||
)
|
||||
from yunohost.utils.system import system_arch, debian_version
|
||||
from yunohost.utils.error import YunohostError, YunohostValidationError
|
||||
from yunohost.utils.algorithms import recursive_apply
|
||||
|
||||
logger = getActionLogger("yunohost.app_resources")
|
||||
|
||||
|
@ -155,11 +154,21 @@ class AppResource:
|
|||
"__YNH_DEBIAN_VERSION__": debian_version(),
|
||||
}
|
||||
|
||||
def recursive_apply(function: Callable, data: Any) -> Any:
|
||||
if isinstance(data, dict): # FIXME: hashable?
|
||||
return {key: recursive_apply(value, function) for key, value in data.items()}
|
||||
|
||||
if isinstance(data, list): # FIXME: iterable?
|
||||
return [recursive_apply(value, function) for value in data]
|
||||
|
||||
return function(data)
|
||||
|
||||
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():
|
||||
|
|
Loading…
Add table
Reference in a new issue