Optimized debugging

This commit is contained in:
Kevin Veen-Birkenbach 2025-01-10 05:30:45 +01:00
parent 268c2eb452
commit 1629d9728d
3 changed files with 21 additions and 14 deletions

View File

@ -4,7 +4,6 @@ import requests
import hashlib
import yaml
from utils.configuration_resolver import ConfigurationResolver
from pprint import pprint
from utils.cache_manager import CacheManager
# Initialize the CacheManager
@ -35,9 +34,6 @@ FLASK_ENV = os.getenv("FLASK_ENV", "production")
def reload_config_in_dev():
if FLASK_ENV == "development":
load_config(app)
print("DEVELOPMENT ENVIRONMENT")
else:
print("PRODUCTIVE ENVIRONMENT")
# Cache the icons
for card in app.config["cards"]:

View File

@ -23,7 +23,6 @@ class CacheManager:
"""
if not os.path.exists(self.cache_dir):
os.makedirs(self.cache_dir)
print(f"Created cache directory: {self.cache_dir}")
def clear_cache(self):
"""
@ -34,7 +33,6 @@ class CacheManager:
file_path = os.path.join(self.cache_dir, filename)
if os.path.isfile(file_path):
os.remove(file_path)
print(f"Deleted: {file_path}")
def cache_file(self, file_url):
"""

View File

@ -1,3 +1,5 @@
from pprint import pprint
import inspect
class ConfigurationResolver:
def __init__(self, config):
"""
@ -25,26 +27,30 @@ class ConfigurationResolver:
path (str): The current path in the configuration for debugging purposes.
"""
if isinstance(current_config, dict):
self._debug(current_config,path,inspect.currentframe().f_lineno)
# Traverse all key-value pairs in the dictionary
for key, value in list(current_config.items()):
if key == "subitems" and isinstance(value, list):
# Überprüfen, ob die relevanten Subitems enthalten sind
subitems_to_promote = [item for item in value if item.get("link")]
if subitems_to_promote:
# Füge nur die relevanten Subitems direkt ein
current_config[key] = subitems_to_promote
pass
#self._debug(value,path,inspect.currentframe().f_lineno)
#for index, item in enumerate(current_config[key]):
# #self._debug(value,path,inspect.currentframe().f_lineno)
# 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":
# Found a `link` entry, attempt to resolve it
try:
print(f"Resolving link '{value}' at path '{path}'") # Debugging
target = self._find_entry(root_config, value.lower().replace(" ", "_"))
if isinstance(target, dict):
self._debug(value,path,inspect.currentframe().f_lineno)
# Replace the current dictionary with the resolved dictionary
current_config.clear()
current_config.update(target)
elif isinstance(target, str):
self._debug(value,path,inspect.currentframe().f_lineno)
# Replace the `link` entry with the resolved string
current_config[key] = target
else:
@ -58,13 +64,21 @@ class ConfigurationResolver:
f"Current path: {path}, Current config: {current_config}"
)
else:
self._debug(value,path,inspect.currentframe().f_lineno)
# Recursively resolve non-`link` entries
self._recursive_resolve(value, root_config, path=f"{path}.{key}")
elif isinstance(current_config, list):
# Traverse all items in the list
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):
"""
@ -81,7 +95,6 @@ class ConfigurationResolver:
KeyError: If the path cannot be resolved.
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
current = config