From 4b9073b8ee889930cb4d0fd5c76b12648cf37d50 Mon Sep 17 00:00:00 2001 From: syoul Date: Tue, 9 Dec 2025 10:03:55 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20corriger=20le=20script=20Python=20pour?= =?UTF-8?q?=20g=C3=A9rer=20les=20fins=20de=20ligne=20et=20les=20erreurs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - vérification de l'existence du fichier avant lecture - utilisation de splitlines(keepends=True) pour préserver les fins de ligne - gestion d'encodage UTF-8 explicite - amélioration de la gestion des erreurs dans le Dockerfile --- Dockerfile.business | 57 ++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/Dockerfile.business b/Dockerfile.business index f8f9921..691a6f0 100644 --- a/Dockerfile.business +++ b/Dockerfile.business @@ -122,8 +122,16 @@ RUN echo "✅ Page team.tsx créée" RUN cat > /tmp/add_team_link.py << 'PYEOF' import sys import re +import os + f = ".techradar/src/components/Navigation/Navigation.tsx" -with open(f, 'r') as file: + +# Vérifier que le fichier existe +if not os.path.exists(f): + print(f"❌ Fichier {f} introuvable") + sys.exit(1) + +with open(f, 'r', encoding='utf-8') as file: content = file.read() # Vérifier si le lien existe déjà (compter les occurrences) @@ -133,13 +141,16 @@ if team_link_count > 0: # Si plusieurs occurrences, supprimer les doublons if team_link_count > 1: print("⚠️ Détection de doublons, nettoyage...") - lines = content.split('\n') + lines = content.splitlines(keepends=True) + if not lines or lines[-1] and not lines[-1].endswith('\n'): + lines[-1] = lines[-1] + '\n' + new_lines = [] in_team_link = False team_link_added = False skip_until_close = False - for i, line in enumerate(lines): + for line in lines: if 'href="/team"' in line or "href='/team'" in line: if not team_link_added: # Garder la première occurrence @@ -161,13 +172,16 @@ if team_link_count > 0: else: new_lines.append(line) - with open(f, 'w') as file: - file.write('\n'.join(new_lines)) + with open(f, 'w', encoding='utf-8') as file: + file.writelines(new_lines) print("✅ Doublons supprimés") sys.exit(0) # Si le lien n'existe pas, l'ajouter -lines = content.split('\n') +lines = content.splitlines(keepends=True) +if not lines or lines[-1] and not lines[-1].endswith('\n'): + lines[-1] = lines[-1] + '\n' + insert_idx = -1 for i, line in enumerate(lines): if 'href="/overview"' in line: @@ -179,35 +193,36 @@ for i, line in enumerate(lines): if insert_idx > 0: new_lines = lines[:insert_idx] + [ - '
  • ', - ' ', - ' 👥 Équipe', - ' ', - '
  • ' + '
  • \n', + ' \n', + ' 👥 Équipe\n', + ' \n', + '
  • \n' ] + lines[insert_idx:] - with open(f, 'w') as file: - file.write('\n'.join(new_lines)) + with open(f, 'w', encoding='utf-8') as file: + file.writelines(new_lines) print("✅ Navigation.tsx modifié - lien Équipe ajouté") sys.exit(0) else: - print("❌ Impossible de trouver l'emplacement") + print("❌ Impossible de trouver l'emplacement pour insérer le lien") sys.exit(1) PYEOF # Modifier Navigation.tsx pour ajouter le lien Équipe (le script Python gère les doublons) RUN echo "🔧 Modification de Navigation.tsx pour le lien Équipe..." && \ - python3 /tmp/add_team_link.py && \ - team_count=$$(grep -c 'href="/team"' .techradar/src/components/Navigation/Navigation.tsx || echo "0") && \ + python3 /tmp/add_team_link.py || (echo "❌ Erreur lors de l'exécution du script Python" && exit 1) && \ + team_count=$$(grep -c 'href="/team"' .techradar/src/components/Navigation/Navigation.tsx 2>/dev/null || echo "0") && \ if [ "$$team_count" -eq "1" ]; then \ echo "✅ Lien Équipe présent (1 occurrence)"; \ elif [ "$$team_count" -gt "1" ]; then \ - echo "⚠️ Plusieurs occurrences détectées ($$team_count), le script Python devrait les avoir nettoyées"; \ - python3 /tmp/add_team_link.py; \ - final_count=$$(grep -c 'href="/team"' .techradar/src/components/Navigation/Navigation.tsx || echo "0") && \ + echo "⚠️ Plusieurs occurrences détectées ($$team_count), relance du nettoyage..."; \ + python3 /tmp/add_team_link.py || (echo "❌ Erreur lors du nettoyage" && exit 1); \ + final_count=$$(grep -c 'href="/team"' .techradar/src/components/Navigation/Navigation.tsx 2>/dev/null || echo "0") && \ echo "✅ Après nettoyage: $$final_count occurrence(s)"; \ else \ - echo "❌ Lien Équipe non trouvé après modification" && \ - cat .techradar/src/components/Navigation/Navigation.tsx && \ + echo "❌ Lien Équipe non trouvé après modification"; \ + echo "📄 Contenu de Navigation.tsx:"; \ + cat .techradar/src/components/Navigation/Navigation.tsx; \ exit 1; \ fi