-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_results_md.sh
More file actions
executable file
·99 lines (80 loc) · 2.71 KB
/
Copy pathprocess_results_md.sh
File metadata and controls
executable file
·99 lines (80 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env bash
# Enable error handling and detailed logging
set +e # Exit on error
set +x # Enable debug output (remove this line to reduce verbosity)
# Function to log messages with timestamp
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
}
# Function to log errors
log_error() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ERROR: $1" >&2
}
# Cleanup function
cleanup() {
if [ -n "$temp_file" ] && [ -f "$temp_file" ]; then
rm -f "$temp_file"
log "Cleaned up temporary file: $temp_file"
fi
}
# Set up signal handlers
trap cleanup EXIT
trap 'log_error "Script interrupted by signal"; exit 130' INT TERM
# Check if pandoc is available
if ! command -v pandoc >/dev/null 2>&1; then
log_error "pandoc is not installed or not in PATH"
exit 1
fi
# Process all markdown files in benchmark results
log "Starting processing of benchmark result files..."
# Initialize counters
processed_count=0
error_count=0
# Use find for recursive search of markdown files
while IFS= read -r -d '' md_file; do
if [ -f "$md_file" ]; then
log "Processing file: $md_file"
md_dir=$(dirname "$md_file")
base_name=$(basename "$md_file" .md)
output_file="${md_dir}/${base_name}.html"
# Skip if output file already exists
if [ -f "$output_file" ]; then
log "Skipping $md_file - output file $output_file already exists"
continue
fi
log "Converting $md_file to $output_file"
# Check file sizes for debugging
original_size=$(wc -c < "$md_file")
log "File sizes - Original: ${original_size} bytes"
# Run pandoc with timeout and better error handling
log "Running pandoc conversion..."
if pandoc "$md_file" -f markdown -t html -o "$output_file" 2>&1; then
sed -e 's/\(href="[^"]*\)\.md"/\1.html"/g' \
-e "s/\(href='[^']*\)\.md'/\1.html'/g" \
-i "$output_file"
log "Successfully converted: $md_file -> $output_file"
((processed_count++))
else
pandoc_exit_code=$?
log_error "Pandoc failed with exit code $pandoc_exit_code for file: $md_file"
# Check if output file was partially created
if [ -f "$output_file" ]; then
log "Removing partially created output file: $output_file"
rm -f "$output_file"
fi
((error_count++))
fi
else
log "Skipping non-file or non-existent: $md_file"
fi
done < <(find results/ -name "*.md" -print0 2>/dev/null)
# Final summary
log "Processing complete!"
log "Files processed successfully: $processed_count"
log "Files with errors: $error_count"
if [ $error_count -gt 0 ]; then
log_error "Some files failed to process. Check the logs above for details."
exit 1
else
log "All files processed successfully!"
fi