mirror of
https://github.com/Ladebeze66/llm_ticket3.git
synced 2025-12-15 22:06:50 +01:00
162 lines
6.2 KiB
Python
Executable File
162 lines
6.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
Script pour aider à la migration des imports dans le projet.
|
|
Ce script identifie les imports obsolètes et suggère des remplacements
|
|
selon la nouvelle structure de répertoires.
|
|
"""
|
|
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
# Mappings des anciens imports vers les nouveaux
|
|
IMPORT_MAPPINGS = {
|
|
'from formatters.clean_html import': 'from formatters.clean_html import',
|
|
'from formatters.json_to_markdown import': 'from formatters.json_to_markdown import',
|
|
'from formatters.markdown_to_json import': 'from formatters.markdown_to_json import',
|
|
'from formatters.report_formatter import': 'from formatters.report_formatter import',
|
|
'from loaders.ticket_data_loader import': 'from loaders.ticket_data_loader import',
|
|
'from odoo.auth_manager import': 'from odoo.auth_manager import',
|
|
'from odoo.ticket_manager import': 'from odoo.ticket_manager import',
|
|
'from odoo.message_manager import': 'from odoo.message_manager import',
|
|
'from odoo.attachment_manager import': 'from odoo.attachment_manager import',
|
|
'from odoo.retrieve_ticket import': 'from odoo.retrieve_ticket import',
|
|
'from core.utils import': 'from core.utils import',
|
|
'import formatters.clean_html': 'import formatters.clean_html',
|
|
'import formatters.json_to_markdown': 'import formatters.json_to_markdown',
|
|
'import formatters.markdown_to_json': 'import formatters.markdown_to_json',
|
|
'import formatters.report_formatter': 'import formatters.report_formatter',
|
|
'import loaders.ticket_data_loader': 'import loaders.ticket_data_loader',
|
|
'import odoo.auth_manager': 'import odoo.auth_manager',
|
|
'import odoo.ticket_manager': 'import odoo.ticket_manager',
|
|
'import odoo.message_manager': 'import odoo.message_manager',
|
|
'import odoo.attachment_manager': 'import odoo.attachment_manager',
|
|
'import odoo.retrieve_ticket': 'import odoo.retrieve_ticket',
|
|
'import core.utils': 'import core.utils',
|
|
'from formatters.clean_html import': 'from formatters.clean_html import',
|
|
'from formatters.report_formatter import': 'from formatters.report_formatter import',
|
|
'from loaders.ticket_data_loader import': 'from loaders.ticket_data_loader import',
|
|
'import formatters.clean_html': 'import formatters.clean_html',
|
|
'import formatters.report_formatter': 'import formatters.report_formatter',
|
|
'import loaders.ticket_data_loader': 'import loaders.ticket_data_loader',
|
|
}
|
|
|
|
# Modules qui sont désormais dans des sous-modules utils
|
|
UTILS_SUBMAPPING = {
|
|
'from agents.utils.report_utils import get_timestamp': 'from agents.utils.report_utils import get_timestamp',
|
|
'from agents.utils.report_utils import extraire_et_traiter_json': 'from agents.utils.report_utils import extraire_et_traiter_json',
|
|
'from agents.utils.report_utils import generer_tableau_questions_reponses': 'from agents.utils.report_utils import generer_tableau_questions_reponses',
|
|
}
|
|
|
|
def find_python_files(root_dir='.', exclude_dirs=None):
|
|
"""
|
|
Trouve tous les fichiers Python dans le répertoire racine.
|
|
|
|
Args:
|
|
root_dir: Répertoire racine pour la recherche
|
|
exclude_dirs: Liste des répertoires à exclure
|
|
|
|
Returns:
|
|
Liste des chemins de fichiers Python
|
|
"""
|
|
if exclude_dirs is None:
|
|
exclude_dirs = ['venv', '__pycache__', '.git']
|
|
|
|
python_files = []
|
|
|
|
for dirpath, dirnames, filenames in os.walk(root_dir):
|
|
# Exclure les répertoires spécifiés
|
|
dirnames[:] = [d for d in dirnames if d not in exclude_dirs]
|
|
|
|
for filename in filenames:
|
|
if filename.endswith('.py'):
|
|
python_files.append(os.path.join(dirpath, filename))
|
|
|
|
return python_files
|
|
|
|
def scan_imports(file_path):
|
|
"""
|
|
Scanne un fichier pour les imports à mettre à jour.
|
|
|
|
Args:
|
|
file_path: Chemin du fichier à scanner
|
|
|
|
Returns:
|
|
Liste des imports à mettre à jour (ancien, nouveau)
|
|
"""
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
imports_to_update = []
|
|
|
|
for old_import, new_import in IMPORT_MAPPINGS.items():
|
|
if old_import in content:
|
|
imports_to_update.append((old_import, new_import))
|
|
|
|
for old_import, new_import in UTILS_SUBMAPPING.items():
|
|
if old_import in content:
|
|
imports_to_update.append((old_import, new_import))
|
|
|
|
return imports_to_update
|
|
|
|
def update_file(file_path, imports_to_update, dry_run=True):
|
|
"""
|
|
Met à jour les imports dans un fichier.
|
|
|
|
Args:
|
|
file_path: Chemin du fichier à mettre à jour
|
|
imports_to_update: Liste des imports à mettre à jour (ancien, nouveau)
|
|
dry_run: Si True, affiche seulement les changements sans les appliquer
|
|
|
|
Returns:
|
|
True si des modifications ont été apportées, False sinon
|
|
"""
|
|
if not imports_to_update:
|
|
return False
|
|
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
modified_content = content
|
|
for old_import, new_import in imports_to_update:
|
|
modified_content = modified_content.replace(old_import, new_import)
|
|
|
|
if modified_content != content:
|
|
if dry_run:
|
|
print(f"Modifications pour {file_path}:")
|
|
for old_import, new_import in imports_to_update:
|
|
print(f" {old_import} -> {new_import}")
|
|
else:
|
|
with open(file_path, 'w', encoding='utf-8') as f:
|
|
f.write(modified_content)
|
|
print(f"Updated {file_path}")
|
|
return True
|
|
|
|
return False
|
|
|
|
def main():
|
|
"""
|
|
Fonction principale.
|
|
"""
|
|
dry_run = True
|
|
if len(sys.argv) > 1 and sys.argv[1] == '--apply':
|
|
dry_run = False
|
|
|
|
python_files = find_python_files()
|
|
files_with_obsolete_imports = 0
|
|
|
|
for file_path in python_files:
|
|
imports_to_update = scan_imports(file_path)
|
|
if update_file(file_path, imports_to_update, dry_run):
|
|
files_with_obsolete_imports += 1
|
|
|
|
if dry_run:
|
|
print(f"\nTrouvé {files_with_obsolete_imports} fichiers avec des imports obsolètes.")
|
|
print("Exécutez avec l'option --apply pour appliquer les modifications.")
|
|
else:
|
|
print(f"\nMis à jour {files_with_obsolete_imports} fichiers.")
|
|
|
|
if __name__ == "__main__":
|
|
main() |