importlib for assets such as yaml

This commit is contained in:
SimplifiedPrivacy 2026-08-06 15:29:26 -04:00
parent 4fe26db1db
commit 983924303d
8 changed files with 27 additions and 3 deletions

1
core/assets/__init__.py Normal file
View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@

View file

@ -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"

View file

@ -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

View file

@ -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,

View file

@ -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

View file

@ -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'))

View file

@ -1,6 +1,9 @@
[project]
name = "sp-hydra-veil-core"
version = "2.5.5"
include = [
{ path = "core/assets/**" }
]
authors = [
{ name = "Simplified Privacy" },
]