|
#!/bin/bash
|
|
|
|
if [ "$#" -ne 3 ]; then
|
|
echo "Usage: $0 <dossier_source> <methode (unoconv|soffice)> <nombre_de_processus>"
|
|
exit 1
|
|
fi
|
|
|
|
SOURCE_DIR="$1"
|
|
METHOD="$2"
|
|
NPROC="$3"
|
|
LOG_FILE="conversion_performance_${METHOD}.csv"
|
|
ERROR_LOG="conversion_errors_${METHOD}.log"
|
|
|
|
start_global_time=$(date +%s%3N) # Temps de d?but global
|
|
|
|
echo "D?but de la conversion des fichiers .docx dans $SOURCE_DIR avec $METHOD"
|
|
|
|
if [[ "$METHOD" != "unoconv" && "$METHOD" != "soffice" ]]; then
|
|
echo "M?thode invalide. Choisissez 'unoconv' ou 'soffice'."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Fichier,Taille(Ko),Pages,Temps(ms),RAM(Ko),Statut" > "$LOG_FILE"
|
|
|
|
# V?rification des outils
|
|
if ! command -v unoconv &>/dev/null && [ "$METHOD" == "unoconv" ]; then
|
|
echo "Erreur : unoconv n'est pas install? ou introuvable." | tee -a "$ERROR_LOG"
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v soffice &>/dev/null && [ "$METHOD" == "soffice" ]; then
|
|
echo "Erreur : soffice n'est pas install? ou introuvable." | tee -a "$ERROR_LOG"
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v /usr/bin/time &>/dev/null; then
|
|
echo "Erreur : /usr/bin/time n'est pas install? ou introuvable." | tee -a "$ERROR_LOG"
|
|
exit 1
|
|
fi
|
|
|
|
find "$SOURCE_DIR" -type f -name "*.docx" | xargs -P "$NPROC" -I {} bash -c '
|
|
file="$1"
|
|
method="$2"
|
|
source_dir="$3"
|
|
log_file="$4"
|
|
error_log="$5"
|
|
|
|
output_pdf="$source_dir/$(basename "${file%.docx}.pdf")"
|
|
stats_file="${file}.stats"
|
|
file_size=$(du -k "$file" | cut -f1)
|
|
|
|
start_time=$(date +%s%3N)
|
|
|
|
if [ "$method" == "unoconv" ]; then
|
|
command_str="/usr/bin/time -f \"RAM:%M\" -o \"$stats_file\" unoconv -f pdf \"$file\""
|
|
else
|
|
command_str="/usr/bin/time -f \"RAM:%M\" -o \"$stats_file\" soffice --headless --convert-to pdf --outdir \"$source_dir\" \"$file\""
|
|
fi
|
|
|
|
echo "Commande ex?cut?e : $command_str" >> "$error_log"
|
|
eval $command_str 2>>"$error_log"
|
|
|
|
end_time=$(date +%s%3N)
|
|
elapsed_time=$((end_time - start_time))
|
|
|
|
page_count="N/A"
|
|
if [ -f "$output_pdf" ]; then
|
|
page_count=$(pdfinfo "$output_pdf" 2>/dev/null | grep "Pages:" | awk "{print \$2}")
|
|
fi
|
|
|
|
if [ ! -f "$output_pdf" ]; then
|
|
echo "$(basename "$file"),$file_size,$page_count,$elapsed_time,,FAILED" >> "$log_file"
|
|
echo "Erreur : conversion ?chou?e pour $file" | tee -a "$error_log"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -f "$stats_file" ]; then
|
|
ram_usage=$(grep "RAM" "$stats_file" | cut -d':' -f2 | tr -d " ")
|
|
echo "$(basename "$file"),$file_size,$page_count,$elapsed_time,$ram_usage,OK" >> "$log_file"
|
|
rm "$stats_file"
|
|
else
|
|
echo "$(basename "$file"),$file_size,$page_count,$elapsed_time,,STATS MISSING" >> "$log_file"
|
|
echo "Erreur : stats manquantes pour $file" | tee -a "$error_log"
|
|
fi
|
|
' _ {} "$METHOD" "$SOURCE_DIR" "$LOG_FILE" "$ERROR_LOG"
|
|
|
|
end_global_time=$(date +%s%3N) # Temps de fin global
|
|
total_execution_time=$((end_global_time - start_global_time))
|
|
|
|
echo "Conversion termin?e. R?sultats enregistr?s dans $LOG_FILE, erreurs dans $ERROR_LOG"
|
|
echo "Temps total d'ex?cution : ${total_execution_time}ms"
|
|
echo "Les r?sultats sont maintenant disponibles sous forme de fichier CSV ($LOG_FILE) pour analyse et g?n?ration de graphiques."
|