importlib for assets such as yaml
This commit is contained in:
parent
4fe26db1db
commit
983924303d
8 changed files with 27 additions and 3 deletions
1
core/assets/__init__.py
Normal file
1
core/assets/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
1
core/assets/yaml_mappings/__init__.py
Normal file
1
core/assets/yaml_mappings/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
|
|
@ -20,6 +20,7 @@ class DBErrorType(Enum):
|
||||||
DATABASE_LOCKED = "database_locked"
|
DATABASE_LOCKED = "database_locked"
|
||||||
CORRUPTED_DATABASE = "corrupted_database"
|
CORRUPTED_DATABASE = "corrupted_database"
|
||||||
PYTHON_MODEL_STRUCTURE = "python_model_structure"
|
PYTHON_MODEL_STRUCTURE = "python_model_structure"
|
||||||
|
SQLALCHEMY_ERROR = "sqlalchemy_error"
|
||||||
UNKNOWN_MODEL = "unknown_model"
|
UNKNOWN_MODEL = "unknown_model"
|
||||||
UNKNOWN = "unknown"
|
UNKNOWN = "unknown"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,8 @@ def _reinitialize_engine_and_session():
|
||||||
Session = sessionmaker(bind=engine)
|
Session = sessionmaker(bind=engine)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def init_session():
|
def init_session():
|
||||||
"""Initialize the global _session from the global Session factory."""
|
"""Initialize the global _session from the global Session factory."""
|
||||||
global _session
|
global _session
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,9 @@ from typing import Type, Dict, Any, Callable, TypeVar
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Purpose:
|
Purpose:
|
||||||
This is a wrapper for other SQL functions to catch errors and do solutions/fixes.
|
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()
|
session.rollback()
|
||||||
return DatabaseOperation(
|
return DatabaseOperation(
|
||||||
valid=False,
|
valid=False,
|
||||||
error_type=DBErrorType.UNKNOWN,
|
error_type=DBErrorType.SQLALCHEMY_ERROR,
|
||||||
message=str(e)
|
message=str(e)
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Catch-all for unexpected errors
|
logger.info("=" * 60)
|
||||||
|
logger.info(traceback.print_exc())
|
||||||
|
logger.info("=" * 60)
|
||||||
session.rollback()
|
session.rollback()
|
||||||
return DatabaseOperation(
|
return DatabaseOperation(
|
||||||
valid=False,
|
valid=False,
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ def get_application_version(application_code: str, version_number: str) -> Optio
|
||||||
if database_object.valid:
|
if database_object.valid:
|
||||||
return database_object.data
|
return database_object.data
|
||||||
else:
|
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
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
11
core/services/helpers/load_yaml.py
Normal file
11
core/services/helpers/load_yaml.py
Normal 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'))
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
[project]
|
[project]
|
||||||
name = "sp-hydra-veil-core"
|
name = "sp-hydra-veil-core"
|
||||||
version = "2.5.5"
|
version = "2.5.5"
|
||||||
|
include = [
|
||||||
|
{ path = "core/assets/**" }
|
||||||
|
]
|
||||||
authors = [
|
authors = [
|
||||||
{ name = "Simplified Privacy" },
|
{ name = "Simplified Privacy" },
|
||||||
]
|
]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue