From 983924303d654c07a7ddbf0ff47be1d0ad6062d9 Mon Sep 17 00:00:00 2001 From: SimplifiedPrivacy Date: Thu, 6 Aug 2026 15:29:26 -0400 Subject: [PATCH] importlib for assets such as yaml --- core/assets/__init__.py | 1 + core/assets/yaml_mappings/__init__.py | 1 + core/models/DatabaseOperation.py | 1 + core/models/manage/session_management.py | 2 ++ core/models/manage/wrapper.py | 9 +++++++-- core/models/orm_calls/application_version_calls.py | 2 +- core/services/helpers/load_yaml.py | 11 +++++++++++ pyproject.toml | 3 +++ 8 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 core/assets/__init__.py create mode 100644 core/assets/yaml_mappings/__init__.py create mode 100644 core/services/helpers/load_yaml.py diff --git a/core/assets/__init__.py b/core/assets/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/core/assets/__init__.py @@ -0,0 +1 @@ + diff --git a/core/assets/yaml_mappings/__init__.py b/core/assets/yaml_mappings/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/core/assets/yaml_mappings/__init__.py @@ -0,0 +1 @@ + diff --git a/core/models/DatabaseOperation.py b/core/models/DatabaseOperation.py index f3fa89f..2613c02 100644 --- a/core/models/DatabaseOperation.py +++ b/core/models/DatabaseOperation.py @@ -20,6 +20,7 @@ class DBErrorType(Enum): DATABASE_LOCKED = "database_locked" CORRUPTED_DATABASE = "corrupted_database" PYTHON_MODEL_STRUCTURE = "python_model_structure" + SQLALCHEMY_ERROR = "sqlalchemy_error" UNKNOWN_MODEL = "unknown_model" UNKNOWN = "unknown" diff --git a/core/models/manage/session_management.py b/core/models/manage/session_management.py index 40c0aa6..e8134f0 100644 --- a/core/models/manage/session_management.py +++ b/core/models/manage/session_management.py @@ -59,6 +59,8 @@ def _reinitialize_engine_and_session(): Session = sessionmaker(bind=engine) + + def init_session(): """Initialize the global _session from the global Session factory.""" global _session diff --git a/core/models/manage/wrapper.py b/core/models/manage/wrapper.py index 0b9611a..4d0c3f4 100644 --- a/core/models/manage/wrapper.py +++ b/core/models/manage/wrapper.py @@ -16,6 +16,9 @@ from typing import Type, Dict, Any, Callable, TypeVar from functools import wraps from enum import Enum +import traceback + + """ Purpose: This is a wrapper for other SQL functions to catch errors and do solutions/fixes. @@ -90,12 +93,14 @@ def safe_db_operation(func): session.rollback() return DatabaseOperation( valid=False, - error_type=DBErrorType.UNKNOWN, + error_type=DBErrorType.SQLALCHEMY_ERROR, message=str(e) ) except Exception as e: - # Catch-all for unexpected errors + logger.info("=" * 60) + logger.info(traceback.print_exc()) + logger.info("=" * 60) session.rollback() return DatabaseOperation( valid=False, diff --git a/core/models/orm_calls/application_version_calls.py b/core/models/orm_calls/application_version_calls.py index f845c46..f7f54f1 100644 --- a/core/models/orm_calls/application_version_calls.py +++ b/core/models/orm_calls/application_version_calls.py @@ -23,7 +23,7 @@ def get_application_version(application_code: str, version_number: str) -> Optio if database_object.valid: return database_object.data else: - logger.error(f"Critical Database error with fetching data: {database_object.error_type}") + logger.error(f"Critical Database error with fetching data for {application_code} and version {version_number}: {database_object.error_type} with {database_object.message}") return None diff --git a/core/services/helpers/load_yaml.py b/core/services/helpers/load_yaml.py new file mode 100644 index 0000000..e345cb7 --- /dev/null +++ b/core/services/helpers/load_yaml.py @@ -0,0 +1,11 @@ +from importlib import resources +import yaml +import os + +def load_yaml(which_yaml: str): + text_content = resources.files('core.assets').joinpath(which_yaml).read_text() + return yaml.safe_load(text_content) + +def is_running_in_appimage(): + """Check if running inside an AppImage""" + return bool(os.environ.get('APPIMAGE')) diff --git a/pyproject.toml b/pyproject.toml index 5a65bc5..3b8c699 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,9 @@ [project] name = "sp-hydra-veil-core" version = "2.5.5" +include = [ + { path = "core/assets/**" } +] authors = [ { name = "Simplified Privacy" }, ]