Update app/custom_node_manager.py
Browse files- app/custom_node_manager.py +25 -1
app/custom_node_manager.py
CHANGED
|
@@ -8,7 +8,6 @@ import json
|
|
| 8 |
import logging
|
| 9 |
from functools import lru_cache
|
| 10 |
|
| 11 |
-
from json_util import merge_json_recursive
|
| 12 |
|
| 13 |
|
| 14 |
# Extra locale files to load into main.json
|
|
@@ -18,6 +17,31 @@ EXTRA_LOCALE_FILES = [
|
|
| 18 |
"settings.json",
|
| 19 |
]
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def safe_load_json_file(file_path: str) -> dict:
|
| 23 |
if not os.path.exists(file_path):
|
|
|
|
| 8 |
import logging
|
| 9 |
from functools import lru_cache
|
| 10 |
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
# Extra locale files to load into main.json
|
|
|
|
| 17 |
"settings.json",
|
| 18 |
]
|
| 19 |
|
| 20 |
+
def merge_json_recursive(base, update):
|
| 21 |
+
"""Recursively merge two JSON-like objects.
|
| 22 |
+
- Dictionaries are merged recursively
|
| 23 |
+
- Lists are concatenated
|
| 24 |
+
- Other types are overwritten by the update value
|
| 25 |
+
Args:
|
| 26 |
+
base: Base JSON-like object
|
| 27 |
+
update: Update JSON-like object to merge into base
|
| 28 |
+
Returns:
|
| 29 |
+
Merged JSON-like object
|
| 30 |
+
"""
|
| 31 |
+
if not isinstance(base, dict) or not isinstance(update, dict):
|
| 32 |
+
if isinstance(base, list) and isinstance(update, list):
|
| 33 |
+
return base + update
|
| 34 |
+
return update
|
| 35 |
+
|
| 36 |
+
merged = base.copy()
|
| 37 |
+
for key, value in update.items():
|
| 38 |
+
if key in merged:
|
| 39 |
+
merged[key] = merge_json_recursive(merged[key], value)
|
| 40 |
+
else:
|
| 41 |
+
merged[key] = value
|
| 42 |
+
|
| 43 |
+
return merged
|
| 44 |
+
|
| 45 |
|
| 46 |
def safe_load_json_file(file_path: str) -> dict:
|
| 47 |
if not os.path.exists(file_path):
|