modified: app.py

modified:   templates/project_details.html
	new file:   test_install_method.py
This commit is contained in:
SimolZimol
2025-07-09 00:16:03 +02:00
parent 2058c30f17
commit f277508e78
3 changed files with 247 additions and 18 deletions

77
app.py
View File

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

View File

@@ -166,6 +166,57 @@
</div>
</div>
</div>
<div class="col-md-6">
<div class="d-flex align-items-center">
{% if project.installation_method == 'clone' %}
<i class="fab fa-git-alt me-2 text-success"></i>
{% elif project.installation_method in ['image', 'docker_registry', 'docker_url', 'docker_file'] %}
<i class="fab fa-docker me-2 text-primary"></i>
{% elif project.installation_method in ['dockerfile', 'docker_build'] %}
<i class="fas fa-cog me-2 text-secondary"></i>
{% elif project.installation_method == 'native_python' %}
<i class="fab fa-python me-2 text-success"></i>
{% elif project.installation_method == 'native_nodejs' %}
<i class="fab fa-node-js me-2 text-success"></i>
{% elif project.installation_method == 'native_batch' %}
<i class="fas fa-terminal me-2 text-info"></i>
{% elif project.installation_method == 'native_shell' %}
<i class="fas fa-terminal me-2 text-success"></i>
{% else %}
<i class="fas fa-question-circle me-2 text-muted"></i>
{% endif %}
<div>
<strong>Installationsmethode</strong>
<div class="text-muted">
{% 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 %}
</div>
</div>
</div>
</div>
</div>
{% if project.readme %}
@@ -268,36 +319,36 @@
</label>
<select class="form-select form-select-sm" id="startModeSelect" onchange="updateStartModeUI()">
{% if project.has_dockerfile %}
<option value="docker" selected>
<i class="fab fa-docker"></i> Docker Container (Standard)
<option value="docker" {% if project.preferred_start_mode == 'docker' %}selected{% endif %}>
<i class="fab fa-docker"></i> Docker Container{% if project.preferred_start_mode == 'docker' %} (Empfohlen){% endif %}
</option>
{% endif %}
{% if project.has_start_bat %}
<option value="batch" {% if not project.has_dockerfile %}selected{% endif %}>
<i class="fas fa-terminal"></i> Windows Batch (.bat)
<option value="batch" {% if project.preferred_start_mode == 'batch' %}selected{% endif %}>
<i class="fas fa-terminal"></i> Windows Batch (.bat){% if project.preferred_start_mode == 'batch' %} (Empfohlen){% endif %}
</option>
{% endif %}
{% if project.has_start_sh %}
<option value="shell" {% if not project.has_dockerfile and not project.has_start_bat %}selected{% endif %}>
<i class="fas fa-terminal"></i> Shell Script (.sh)
<option value="shell" {% if project.preferred_start_mode == 'shell' %}selected{% endif %}>
<i class="fas fa-terminal"></i> Shell Script (.sh){% if project.preferred_start_mode == 'shell' %} (Empfohlen){% endif %}
</option>
{% endif %}
{% if project.has_package_json %}
<option value="nodejs" {% if not project.has_dockerfile and not project.has_start_bat and not project.has_start_sh %}selected{% endif %}>
<i class="fab fa-node-js"></i> Node.js (npm start)
<option value="nodejs" {% if project.preferred_start_mode == 'nodejs' %}selected{% endif %}>
<i class="fab fa-node-js"></i> Node.js (npm start){% if project.preferred_start_mode == 'nodejs' %} (Empfohlen){% endif %}
</option>
{% endif %}
{% if project.has_python_files %}
<option value="python">
<i class="fab fa-python"></i> Python (direkt)
<option value="python" {% if project.preferred_start_mode == 'python' %}selected{% endif %}>
<i class="fab fa-python"></i> Python (direkt){% if project.preferred_start_mode == 'python' %} (Empfohlen){% endif %}
</option>
{% endif %}
<option value="custom">
<option value="custom" {% if project.preferred_start_mode == 'custom' %}selected{% endif %}>
<i class="fas fa-wrench"></i> Custom (manuell)
</option>
</select>

115
test_install_method.py Normal file
View File

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