mirror of
https://github.com/kevinveenbirkenbach/homepage.veen.world.git
synced 2025-06-28 23:55:31 +02:00
Optimized debugging
This commit is contained in:
parent
268c2eb452
commit
1629d9728d
@ -4,7 +4,6 @@ import requests
|
|||||||
import hashlib
|
import hashlib
|
||||||
import yaml
|
import yaml
|
||||||
from utils.configuration_resolver import ConfigurationResolver
|
from utils.configuration_resolver import ConfigurationResolver
|
||||||
from pprint import pprint
|
|
||||||
from utils.cache_manager import CacheManager
|
from utils.cache_manager import CacheManager
|
||||||
|
|
||||||
# Initialize the CacheManager
|
# Initialize the CacheManager
|
||||||
@ -35,9 +34,6 @@ FLASK_ENV = os.getenv("FLASK_ENV", "production")
|
|||||||
def reload_config_in_dev():
|
def reload_config_in_dev():
|
||||||
if FLASK_ENV == "development":
|
if FLASK_ENV == "development":
|
||||||
load_config(app)
|
load_config(app)
|
||||||
print("DEVELOPMENT ENVIRONMENT")
|
|
||||||
else:
|
|
||||||
print("PRODUCTIVE ENVIRONMENT")
|
|
||||||
|
|
||||||
# Cache the icons
|
# Cache the icons
|
||||||
for card in app.config["cards"]:
|
for card in app.config["cards"]:
|
||||||
|
@ -23,7 +23,6 @@ class CacheManager:
|
|||||||
"""
|
"""
|
||||||
if not os.path.exists(self.cache_dir):
|
if not os.path.exists(self.cache_dir):
|
||||||
os.makedirs(self.cache_dir)
|
os.makedirs(self.cache_dir)
|
||||||
print(f"Created cache directory: {self.cache_dir}")
|
|
||||||
|
|
||||||
def clear_cache(self):
|
def clear_cache(self):
|
||||||
"""
|
"""
|
||||||
@ -34,7 +33,6 @@ class CacheManager:
|
|||||||
file_path = os.path.join(self.cache_dir, filename)
|
file_path = os.path.join(self.cache_dir, filename)
|
||||||
if os.path.isfile(file_path):
|
if os.path.isfile(file_path):
|
||||||
os.remove(file_path)
|
os.remove(file_path)
|
||||||
print(f"Deleted: {file_path}")
|
|
||||||
|
|
||||||
def cache_file(self, file_url):
|
def cache_file(self, file_url):
|
||||||
"""
|
"""
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from pprint import pprint
|
||||||
|
import inspect
|
||||||
class ConfigurationResolver:
|
class ConfigurationResolver:
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
"""
|
"""
|
||||||
@ -25,26 +27,30 @@ class ConfigurationResolver:
|
|||||||
path (str): The current path in the configuration for debugging purposes.
|
path (str): The current path in the configuration for debugging purposes.
|
||||||
"""
|
"""
|
||||||
if isinstance(current_config, dict):
|
if isinstance(current_config, dict):
|
||||||
|
self._debug(current_config,path,inspect.currentframe().f_lineno)
|
||||||
# Traverse all key-value pairs in the dictionary
|
# Traverse all key-value pairs in the dictionary
|
||||||
for key, value in list(current_config.items()):
|
for key, value in list(current_config.items()):
|
||||||
if key == "subitems" and isinstance(value, list):
|
if key == "subitems" and isinstance(value, list):
|
||||||
# Überprüfen, ob die relevanten Subitems enthalten sind
|
pass
|
||||||
subitems_to_promote = [item for item in value if item.get("link")]
|
#self._debug(value,path,inspect.currentframe().f_lineno)
|
||||||
if subitems_to_promote:
|
#for index, item in enumerate(current_config[key]):
|
||||||
# Füge nur die relevanten Subitems direkt ein
|
# #self._debug(value,path,inspect.currentframe().f_lineno)
|
||||||
current_config[key] = subitems_to_promote
|
# if "link" in item:
|
||||||
|
# self._debug(value,path,inspect.currentframe().f_lineno)
|
||||||
|
# self._recursive_resolve(item, root_config, path=f"{path}[{index}]")
|
||||||
|
|
||||||
elif key == "link":
|
elif key == "link":
|
||||||
# Found a `link` entry, attempt to resolve it
|
# Found a `link` entry, attempt to resolve it
|
||||||
try:
|
try:
|
||||||
print(f"Resolving link '{value}' at path '{path}'") # Debugging
|
|
||||||
target = self._find_entry(root_config, value.lower().replace(" ", "_"))
|
target = self._find_entry(root_config, value.lower().replace(" ", "_"))
|
||||||
|
|
||||||
if isinstance(target, dict):
|
if isinstance(target, dict):
|
||||||
|
self._debug(value,path,inspect.currentframe().f_lineno)
|
||||||
# Replace the current dictionary with the resolved dictionary
|
# Replace the current dictionary with the resolved dictionary
|
||||||
current_config.clear()
|
current_config.clear()
|
||||||
current_config.update(target)
|
current_config.update(target)
|
||||||
elif isinstance(target, str):
|
elif isinstance(target, str):
|
||||||
|
self._debug(value,path,inspect.currentframe().f_lineno)
|
||||||
# Replace the `link` entry with the resolved string
|
# Replace the `link` entry with the resolved string
|
||||||
current_config[key] = target
|
current_config[key] = target
|
||||||
else:
|
else:
|
||||||
@ -58,6 +64,7 @@ class ConfigurationResolver:
|
|||||||
f"Current path: {path}, Current config: {current_config}"
|
f"Current path: {path}, Current config: {current_config}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
self._debug(value,path,inspect.currentframe().f_lineno)
|
||||||
# Recursively resolve non-`link` entries
|
# Recursively resolve non-`link` entries
|
||||||
self._recursive_resolve(value, root_config, path=f"{path}.{key}")
|
self._recursive_resolve(value, root_config, path=f"{path}.{key}")
|
||||||
|
|
||||||
@ -66,6 +73,13 @@ class ConfigurationResolver:
|
|||||||
for index, item in enumerate(current_config):
|
for index, item in enumerate(current_config):
|
||||||
self._recursive_resolve(item, root_config, path=f"{path}[{index}]")
|
self._recursive_resolve(item, root_config, path=f"{path}[{index}]")
|
||||||
|
|
||||||
|
def _debug(self, value, path, line, condition="accounts"):
|
||||||
|
if condition in path:
|
||||||
|
print("LINE:" + str(line))
|
||||||
|
print("PATH:" + path)
|
||||||
|
print("VALUE:")
|
||||||
|
pprint(value)
|
||||||
|
|
||||||
def _find_entry(self, config, path):
|
def _find_entry(self, config, path):
|
||||||
"""
|
"""
|
||||||
Finds an entry in the configuration by navigating a dot-separated path.
|
Finds an entry in the configuration by navigating a dot-separated path.
|
||||||
@ -81,7 +95,6 @@ class ConfigurationResolver:
|
|||||||
KeyError: If the path cannot be resolved.
|
KeyError: If the path cannot be resolved.
|
||||||
ValueError: If the resolved entry is not of the expected type.
|
ValueError: If the resolved entry is not of the expected type.
|
||||||
"""
|
"""
|
||||||
print(f"Current path being resolved: {path}")
|
|
||||||
parts = path.split('.') # Split the path into segments
|
parts = path.split('.') # Split the path into segments
|
||||||
current = config
|
current = config
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user