📚 Improved code organization and structure in backend modules 🚧🔧

This commit is contained in:
2025-06-11 14:20:21 +02:00
parent c4bd6ff4dc
commit c386b34d3a
10 changed files with 42 additions and 13 deletions

View File

@ -246,7 +246,7 @@ def get_environment_type():
# Windows-spezifische Fixes
if os.name == 'nt':
try:
from utils.windows_fixes import get_windows_thread_manager
from utils.core_system import get_windows_thread_manager
print("[OK] Windows-Fixes (sichere Version) geladen")
except ImportError as e:
get_windows_thread_manager = None
@ -259,7 +259,7 @@ from models import init_database, create_initial_admin, User, get_db_session
from utils.logging_config import setup_logging, get_logger, log_startup_info
from utils.job_scheduler import JobScheduler, get_job_scheduler
from utils.queue_manager import start_queue_manager, stop_queue_manager
from utils.settings import SECRET_KEY, SESSION_LIFETIME
from utils.utilities_collection import SECRET_KEY, SESSION_LIFETIME
# Blueprints importieren
from blueprints.auth import auth_blueprint
@ -377,7 +377,7 @@ def apply_production_config(app):
app_logger.info("[PRODUCTION] Aktiviere Production-Konfiguration für Mercedes-Benz TBA")
# Dynamische Werte setzen
from utils.settings import SECRET_KEY, SESSION_LIFETIME
from utils.utilities_collection import SECRET_KEY, SESSION_LIFETIME
ProductionConfig.SECRET_KEY = os.environ.get('SECRET_KEY') or SECRET_KEY
ProductionConfig.PERMANENT_SESSION_LIFETIME = SESSION_LIFETIME
@ -431,7 +431,7 @@ def apply_development_config(app):
app_logger.info("[DEVELOPMENT] Aktiviere Development-Konfiguration")
# Dynamische Werte setzen
from utils.settings import SECRET_KEY, SESSION_LIFETIME
from utils.utilities_collection import SECRET_KEY, SESSION_LIFETIME
DevelopmentConfig.SECRET_KEY = os.environ.get('SECRET_KEY') or SECRET_KEY
DevelopmentConfig.PERMANENT_SESSION_LIFETIME = SESSION_LIFETIME

View File

@ -726,7 +726,7 @@ def create_backup():
with zipfile.ZipFile(backup_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
# 1. Datenbank-Datei hinzufügen
try:
from utils.settings import DATABASE_PATH
from utils.utilities_collection import DATABASE_PATH
if os.path.exists(DATABASE_PATH):
zipf.write(DATABASE_PATH, 'database/main.db')
created_files.append('database/main.db')
@ -854,7 +854,7 @@ def optimize_database():
try:
admin_api_logger.info(f"Datenbank-Optimierung angefordert von Admin {current_user.username}")
from utils.settings import DATABASE_PATH
from utils.utilities_collection import DATABASE_PATH
optimization_results = {
'vacuum_completed': False,

View File

@ -9,7 +9,7 @@ from flask_login import login_required, current_user
from datetime import datetime, timedelta
from models import User, get_db_session, SystemLog
from utils.logging_config import get_logger
from utils.settings import SESSION_LIFETIME
from utils.utilities_collection import SESSION_LIFETIME
# Blueprint erstellen
sessions_blueprint = Blueprint('sessions', __name__, url_prefix='/api/session')

View File

@ -15,7 +15,7 @@ from datetime import datetime
from models import get_db_session, SystemLog
from utils.logging_config import get_logger
from utils.data_management import file_manager, save_job_file, save_guest_file, save_avatar_file, save_asset_file, save_log_file, save_backup_file, save_temp_file, delete_file as delete_file_safe
from utils.settings import UPLOAD_FOLDER, ALLOWED_EXTENSIONS
from utils.utilities_collection import UPLOAD_FOLDER, ALLOWED_EXTENSIONS
# Blueprint erstellen
uploads_blueprint = Blueprint('uploads', __name__, url_prefix='/api')

View File

@ -15,7 +15,7 @@ from flask_login import UserMixin
import bcrypt
import secrets
from utils.settings import DATABASE_PATH, ensure_database_directory
from utils.utilities_collection import DATABASE_PATH, ensure_database_directory
from utils.logging_config import get_logger
# ===== DATABASE CLEANUP INTEGRATION =====

View File

@ -45,7 +45,7 @@ class FileManager:
def __init__(self, base_upload_folder: str = None):
try:
from utils.settings import UPLOAD_FOLDER, ALLOWED_EXTENSIONS
from utils.utilities_collection import UPLOAD_FOLDER, ALLOWED_EXTENSIONS
self.base_folder = base_upload_folder or UPLOAD_FOLDER
self.allowed_extensions = ALLOWED_EXTENSIONS
except ImportError:

View File

@ -23,7 +23,7 @@ from flask_login import current_user
from utils.logging_config import get_logger
from models import Job, Printer, JobOrder, get_db_session
from utils.data_management import save_job_file, save_temp_file
from utils.settings import ALLOWED_EXTENSIONS, MAX_FILE_SIZE, UPLOAD_FOLDER
from utils.utilities_collection import ALLOWED_EXTENSIONS, MAX_FILE_SIZE, UPLOAD_FOLDER
logger = get_logger("drag_drop")

View File

@ -71,7 +71,7 @@ class TapoController:
"""Initialisiere den Tapo Controller"""
# Lazy import um zirkuläre Abhängigkeiten zu vermeiden
try:
from utils.settings import TAPO_USERNAME, TAPO_PASSWORD, DEFAULT_TAPO_IPS, TAPO_TIMEOUT, TAPO_RETRY_COUNT
from utils.utilities_collection import TAPO_USERNAME, TAPO_PASSWORD, DEFAULT_TAPO_IPS, TAPO_TIMEOUT, TAPO_RETRY_COUNT
self.username = TAPO_USERNAME
self.password = TAPO_PASSWORD
self.default_ips = DEFAULT_TAPO_IPS

View File

@ -9,7 +9,7 @@ from sqlalchemy.orm import joinedload
from utils.logging_config import get_logger
from models import Job, Printer, get_db_session
from utils.settings import TAPO_USERNAME, TAPO_PASSWORD
from utils.utilities_collection import TAPO_USERNAME, TAPO_PASSWORD
from utils.hardware_integration import tapo_controller
# Legacy function - use tapo_controller.test_connection instead
def test_tapo_connection(*args, **kwargs):

View File

@ -38,6 +38,21 @@ class Config:
SESSION_LIFETIME = 3600
MAX_FILE_SIZE = 100 * 1024 * 1024 # 100MB
ALLOWED_EXTENSIONS = ['.gcode', '.stl', '.obj']
UPLOAD_FOLDER = "backend/uploads"
# TAPO Smart Plug Configuration
TAPO_USERNAME = "till.tomczak@mercedes-benz.com"
TAPO_PASSWORD = "744563017196A"
DEFAULT_TAPO_IPS = [
"192.168.0.103",
"192.168.0.104",
"192.168.0.100",
"192.168.0.101",
"192.168.0.102",
"192.168.0.105"
]
TAPO_TIMEOUT = 10
TAPO_RETRY_COUNT = 3
@classmethod
def get_all(cls) -> Dict[str, Any]:
@ -215,6 +230,20 @@ def get_system_status() -> Dict[str, Any]:
DATABASE_PATH = Config.DATABASE_PATH
SECRET_KEY = Config.SECRET_KEY
SESSION_LIFETIME = Config.SESSION_LIFETIME
UPLOAD_FOLDER = Config.UPLOAD_FOLDER
ALLOWED_EXTENSIONS = Config.ALLOWED_EXTENSIONS
MAX_FILE_SIZE = Config.MAX_FILE_SIZE
TAPO_USERNAME = Config.TAPO_USERNAME
TAPO_PASSWORD = Config.TAPO_PASSWORD
DEFAULT_TAPO_IPS = Config.DEFAULT_TAPO_IPS
TAPO_TIMEOUT = Config.TAPO_TIMEOUT
TAPO_RETRY_COUNT = Config.TAPO_RETRY_COUNT
def ensure_database_directory():
"""Erstellt das Datenbank-Verzeichnis."""
db_dir = os.path.dirname(DATABASE_PATH)
if db_dir:
os.makedirs(db_dir, exist_ok=True)
def send_email(recipient, subject, message):
return email_notification.send_notification(recipient, subject, message)