-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_experiment_list.sh
More file actions
executable file
·70 lines (56 loc) · 1.88 KB
/
update_experiment_list.sh
File metadata and controls
executable file
·70 lines (56 loc) · 1.88 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
#!/bin/bash
# Create a JSON file of all experiment directories for the main index.html
# Check for required dependencies
check_dependency() {
if ! command -v "$1" &> /dev/null; then
echo "Error: Required command '$1' not found. Please install it before running this script."
return 1
fi
}
# Get the script's directory without using readlink (which might not be available)
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
RESULTS_DIR="${SCRIPT_DIR}/results"
OUTPUT_FILE="${RESULTS_DIR}/experiments.json"
# Check if results directory exists
if [ ! -d "$RESULTS_DIR" ]; then
echo "Results directory not found: $RESULTS_DIR"
echo "Creating results directory..."
mkdir -p "$RESULTS_DIR"
if [ ! -d "$RESULTS_DIR" ]; then
echo "Error: Failed to create results directory"
exit 1
fi
fi
# Generate empty JSON array for experiments
echo "[" > "$OUTPUT_FILE"
# Find all experiment directories using a simpler approach
FIRST=true
# Change to results directory
cd "$RESULTS_DIR" || { echo "Error changing to results directory"; exit 1; }
# Use shell globbing instead of find
for DIR in */; do
# Remove trailing slash
DIR_NAME=${DIR%/}
# Skip templates directory if it exists in results
if [[ "$DIR_NAME" == "templates" ]]; then
continue
fi
# Check if the directory contains an index.html file
if [ -f "${DIR_NAME}/index.html" ]; then
if [ "$FIRST" = false ]; then
echo "," >> "$OUTPUT_FILE"
else
FIRST=false
fi
# Add entry to JSON
echo " {" >> "$OUTPUT_FILE"
echo " \"id\": \"${DIR_NAME}\"," >> "$OUTPUT_FILE"
echo " \"path\": \"${DIR_NAME}/index.html\"" >> "$OUTPUT_FILE"
echo " }" >> "$OUTPUT_FILE"
fi
done
# Change back to original directory
cd "$SCRIPT_DIR" || { echo "Error changing back to script directory"; exit 1; }
# Close the JSON array
echo "]" >> "$OUTPUT_FILE"
echo "Experiment list updated at $OUTPUT_FILE"