From f277508e7801758fe49bed35f9ae6970604a438e Mon Sep 17 00:00:00 2001 From: SimolZimol <70102430+SimolZimol@users.noreply.github.com> Date: Wed, 9 Jul 2025 00:16:03 +0200 Subject: [PATCH] modified: app.py modified: templates/project_details.html new file: test_install_method.py --- app.py | 77 ++++++++++++++++++++-- templates/project_details.html | 73 +++++++++++++++++---- test_install_method.py | 115 +++++++++++++++++++++++++++++++++ 3 files changed, 247 insertions(+), 18 deletions(-) create mode 100644 test_install_method.py diff --git a/app.py b/app.py index 1aba626..15e3fc7 100644 --- a/app.py +++ b/app.py @@ -178,21 +178,52 @@ class ProjectManager: # Versuche Version aus verschiedenen Quellen zu extrahieren version = self.extract_project_version(project_path, project_name, project_url) + # Bestimme Standard-Start-Modus basierend auf installation_method + def get_default_start_mode(installation_method): + if installation_method in ['image', 'docker_registry', 'docker_url', 'docker_file', 'dockerfile', 'docker_build']: + return 'docker' + elif installation_method == 'native_python': + return 'python' + elif installation_method == 'native_nodejs': + return 'nodejs' + elif installation_method == 'native_batch': + return 'batch' + elif installation_method == 'native_shell': + return 'shell' + elif installation_method == 'clone': + # Bei Clone schauen, welche Dateien vorhanden sind + if os.path.exists(os.path.join(project_path, 'Dockerfile')): + return 'docker' + elif os.path.exists(os.path.join(project_path, 'start.bat')): + return 'batch' + elif os.path.exists(os.path.join(project_path, 'start.sh')): + return 'shell' + elif os.path.exists(os.path.join(project_path, 'package.json')): + return 'nodejs' + elif any(f.endswith('.py') for f in os.listdir(project_path) if os.path.isfile(os.path.join(project_path, f))): + return 'python' + else: + return 'docker' # Fallback + else: + return 'docker' # Standard-Fallback + if version: # Speichere Version in der NEUEN version_app_in Datei (Hauptdatei) version_file = os.path.join(project_path, 'version_app_in') try: with open(version_file, 'w', encoding='utf-8') as f: import json + default_start_mode = get_default_start_mode(installation_method) version_data = { 'version': version, 'installed_at': datetime.now().isoformat(), 'project_url': project_url, 'installation_method': installation_method, + 'preferred_start_mode': default_start_mode, 'last_updated': datetime.now().isoformat() } json.dump(version_data, f, indent=2) - print(f"✅ Version {version} für Projekt {project_name} in version_app_in gespeichert") + print(f"✅ Version {version} für Projekt {project_name} mit Methode '{installation_method}' und Start-Modus '{default_start_mode}' gespeichert") except Exception as e: print(f"❌ Fehler beim Speichern der version_app_in Datei: {e}") @@ -387,12 +418,44 @@ class ProjectManager: 'version': self.get_installed_version(project_name) } - # Bestimme die Installationsmethode aus der Konfiguration - config = self.load_config() - for project in config.get('projects', []): - if project.get('name') == project_name: - info['install_method'] = project.get('install_method', 'unknown') - break + # Lese erweiterte Informationen aus version_app_in + version_file = os.path.join(project_path, 'version_app_in') + if os.path.exists(version_file): + try: + with open(version_file, 'r', encoding='utf-8') as f: + import json + version_data = json.load(f) + info['installation_method'] = version_data.get('installation_method', 'unknown') + info['preferred_start_mode'] = version_data.get('preferred_start_mode', 'docker') + info['project_url'] = version_data.get('project_url', '') + info['last_updated'] = version_data.get('last_updated', '') + except Exception as e: + print(f"⚠ Warnung: Konnte version_app_in für {project_name} nicht lesen: {e}") + info['installation_method'] = 'unknown' + info['preferred_start_mode'] = 'docker' + else: + # Fallback: Bestimme die Installationsmethode aus der Konfiguration + config = self.load_config() + for project in config.get('projects', []): + if project.get('name') == project_name: + info['installation_method'] = project.get('install_method', 'unknown') + break + else: + info['installation_method'] = 'unknown' + + # Standard Start-Modus falls keine version_app_in vorhanden + if info['has_dockerfile']: + info['preferred_start_mode'] = 'docker' + elif info['has_start_bat']: + info['preferred_start_mode'] = 'batch' + elif info['has_start_sh']: + info['preferred_start_mode'] = 'shell' + elif info['has_package_json']: + info['preferred_start_mode'] = 'nodejs' + elif info['has_python_files']: + info['preferred_start_mode'] = 'python' + else: + info['preferred_start_mode'] = 'docker' # Lese README falls vorhanden readme_files = ['README.md', 'readme.md', 'README.txt', 'readme.txt'] diff --git a/templates/project_details.html b/templates/project_details.html index 16747cf..e6b9a10 100644 --- a/templates/project_details.html +++ b/templates/project_details.html @@ -166,6 +166,57 @@ +
+
+ {% if project.installation_method == 'clone' %} + + {% elif project.installation_method in ['image', 'docker_registry', 'docker_url', 'docker_file'] %} + + {% elif project.installation_method in ['dockerfile', 'docker_build'] %} + + {% elif project.installation_method == 'native_python' %} + + {% elif project.installation_method == 'native_nodejs' %} + + {% elif project.installation_method == 'native_batch' %} + + {% elif project.installation_method == 'native_shell' %} + + {% else %} + + {% endif %} +
+ Installationsmethode +
+ {% if project.installation_method == 'clone' %} + Git Clone + {% elif project.installation_method == 'image' %} + Docker Image + {% elif project.installation_method == 'docker_registry' %} + Docker Registry + {% elif project.installation_method == 'docker_url' %} + Docker URL + {% elif project.installation_method == 'docker_file' %} + Docker File + {% elif project.installation_method == 'dockerfile' %} + Dockerfile Build + {% elif project.installation_method == 'docker_build' %} + Docker Build + {% elif project.installation_method == 'native_python' %} + Python Native + {% elif project.installation_method == 'native_nodejs' %} + Node.js Native + {% elif project.installation_method == 'native_batch' %} + Windows Batch + {% elif project.installation_method == 'native_shell' %} + Linux/macOS Shell + {% else %} + {{ project.installation_method or 'Unbekannt' }} + {% endif %} +
+
+
+
{% if project.readme %} @@ -268,36 +319,36 @@ diff --git a/test_install_method.py b/test_install_method.py new file mode 100644 index 0000000..23316a9 --- /dev/null +++ b/test_install_method.py @@ -0,0 +1,115 @@ +#!/usr/bin/env python3 +"""Test script to verify that installation_method is correctly saved""" + +import requests +import json +import os +import time + +# Konfiguration +BASE_URL = "http://localhost:5000" +TEST_PROJECT_NAME = "test-install-method" +TEST_PROJECT_URL = "https://github.com/defunkt/jquery-pjax.git" # Kleines Test-Repository + +def test_installation_method(method): + """Teste Installation mit spezifischer Methode""" + print(f"\n🧪 Teste Installation mit Methode: {method}") + + # Lösche Projekt falls es existiert + project_path = f"c:\\Users\\Simon.Speedy\\Documents\\dev projekte\\Test\\app installer\\projects\\{TEST_PROJECT_NAME}" + if os.path.exists(project_path): + import shutil + shutil.rmtree(project_path) + print(f"🗑️ Existierendes Projekt {TEST_PROJECT_NAME} entfernt") + + # Installiere Projekt + data = { + 'project_url': TEST_PROJECT_URL, + 'project_name': TEST_PROJECT_NAME, + 'installation_method': method + } + + print(f"📤 Sende POST-Request an /install_project mit:") + print(f" - URL: {TEST_PROJECT_URL}") + print(f" - Name: {TEST_PROJECT_NAME}") + print(f" - Methode: {method}") + + response = requests.post(f"{BASE_URL}/install_project", data=data) + + if response.status_code == 200: + result = response.json() + print(f"✅ Response: {result}") + + if result.get('success'): + # Warte kurz für Dateisystem + time.sleep(1) + + # Prüfe version_app_in Datei + version_file = os.path.join(project_path, "version_app_in") + if os.path.exists(version_file): + with open(version_file, 'r', encoding='utf-8') as f: + version_data = json.load(f) + + saved_method = version_data.get('installation_method', 'NICHT_GEFUNDEN') + print(f"💾 Gespeicherte Methode in version_app_in: {saved_method}") + + if saved_method == method: + print(f"✅ ERFOLG: Methode '{method}' korrekt gespeichert!") + return True + else: + print(f"❌ FEHLER: Erwartet '{method}', gefunden '{saved_method}'") + return False + else: + print(f"❌ FEHLER: version_app_in Datei nicht gefunden!") + return False + else: + print(f"❌ Installation fehlgeschlagen: {result.get('message')}") + return False + else: + print(f"❌ HTTP-Fehler: {response.status_code}") + return False + +def main(): + print("🚀 Starte Test der installation_method Bugfix") + + # Teste verschiedene Methoden + test_methods = [ + 'clone', + 'native_python', + 'docker_build', + 'dockerfile' + ] + + results = {} + + for method in test_methods: + try: + results[method] = test_installation_method(method) + except Exception as e: + print(f"❌ Fehler beim Testen von Methode '{method}': {e}") + results[method] = False + + # Kurze Pause zwischen Tests + time.sleep(2) + + # Zusammenfassung + print("\n" + "="*50) + print("📊 TESTERGEBNISSE:") + print("="*50) + + success_count = 0 + for method, success in results.items(): + status = "✅ BESTANDEN" if success else "❌ FEHLGESCHLAGEN" + print(f" {method:15} - {status}") + if success: + success_count += 1 + + print(f"\n🎯 {success_count}/{len(test_methods)} Tests bestanden") + + if success_count == len(test_methods): + print("🎉 Alle Tests erfolgreich! Der Bug ist behoben!") + else: + print("⚠️ Einige Tests fehlgeschlagen. Weitere Arbeit erforderlich.") + +if __name__ == "__main__": + main()