From c386b34d3ab40722827cf25a5df5a34fd88284bd Mon Sep 17 00:00:00 2001 From: Till Tomczak Date: Wed, 11 Jun 2025 14:20:21 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9A=20Improved=20code=20organization?= =?UTF-8?q?=20and=20structure=20in=20backend=20modules=20=F0=9F=9A=A7?= =?UTF-8?q?=F0=9F=94=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app.py | 8 ++++---- backend/blueprints/admin_unified.py | 4 ++-- backend/blueprints/sessions.py | 2 +- backend/blueprints/uploads.py | 2 +- backend/models.py | 2 +- backend/utils/data_management.py | 2 +- backend/utils/drag_drop_system.py | 2 +- backend/utils/hardware_integration.py | 2 +- backend/utils/job_scheduler.py | 2 +- backend/utils/utilities_collection.py | 29 +++++++++++++++++++++++++++ 10 files changed, 42 insertions(+), 13 deletions(-) diff --git a/backend/app.py b/backend/app.py index 6b5246430..5fb1142cd 100644 --- a/backend/app.py +++ b/backend/app.py @@ -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 diff --git a/backend/blueprints/admin_unified.py b/backend/blueprints/admin_unified.py index 7944f90bb..c2c3eacbf 100644 --- a/backend/blueprints/admin_unified.py +++ b/backend/blueprints/admin_unified.py @@ -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, diff --git a/backend/blueprints/sessions.py b/backend/blueprints/sessions.py index 574d23b3f..233dd4bb0 100644 --- a/backend/blueprints/sessions.py +++ b/backend/blueprints/sessions.py @@ -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') diff --git a/backend/blueprints/uploads.py b/backend/blueprints/uploads.py index 9f29fe2f4..0929e5b4b 100644 --- a/backend/blueprints/uploads.py +++ b/backend/blueprints/uploads.py @@ -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') diff --git a/backend/models.py b/backend/models.py index 3c02ab5af..bea5d5f1f 100644 --- a/backend/models.py +++ b/backend/models.py @@ -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 ===== diff --git a/backend/utils/data_management.py b/backend/utils/data_management.py index 7f1dfd695..787e3b92f 100644 --- a/backend/utils/data_management.py +++ b/backend/utils/data_management.py @@ -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: diff --git a/backend/utils/drag_drop_system.py b/backend/utils/drag_drop_system.py index 2bdbd97e1..deffaed98 100644 --- a/backend/utils/drag_drop_system.py +++ b/backend/utils/drag_drop_system.py @@ -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") diff --git a/backend/utils/hardware_integration.py b/backend/utils/hardware_integration.py index b04a6b551..dde66c5e8 100644 --- a/backend/utils/hardware_integration.py +++ b/backend/utils/hardware_integration.py @@ -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 diff --git a/backend/utils/job_scheduler.py b/backend/utils/job_scheduler.py index 852911e93..bf30f3d80 100644 --- a/backend/utils/job_scheduler.py +++ b/backend/utils/job_scheduler.py @@ -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): diff --git a/backend/utils/utilities_collection.py b/backend/utils/utilities_collection.py index a3e44dedb..a0c8a281f 100644 --- a/backend/utils/utilities_collection.py +++ b/backend/utils/utilities_collection.py @@ -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)