-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrun_loadsubmissions.sh
executable file
·78 lines (65 loc) · 1.79 KB
/
run_loadsubmissions.sh
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
#!/bin/bash
# Function to print usage
usage() {
echo "Usage: $0 <source_directory> <course_name> <exercise_name> <delay_in_seconds>"
echo "Example: $0 /path/to/source coursec e1 5"
exit 1
}
# Check if exactly four arguments were supplied
if [ "$#" -ne 4 ]; then
usage
fi
# Define the source directory, course name, exercise name, and delay
SRC_DIR=$1
COURSE_NAME=$2
EXERCISE_NAME=$3
DELAY=$4
# Check if the supplied source directory is valid
if [ ! -d "$SRC_DIR" ]; then
echo "Error: $SRC_DIR is not a directory"
usage
fi
# Initialize counter
INDEX=1
SHOULD_MOVE_FILES=false
# Check if files are already distributed
for SUBDIR in "$SRC_DIR"/*; do
if [ -d "$SUBDIR/ex2" ]; then
SHOULD_MOVE_FILES=false
break
else
SHOULD_MOVE_FILES=true
fi
done
# Move files if not already distributed
if $SHOULD_MOVE_FILES; then
echo "Distributing files..."
for FILE in "$SRC_DIR"/*; do
if [ -f "$FILE" ]; then
# Create the index and ex2 directories
DEST_DIR="$SRC_DIR/$INDEX/ex2"
mkdir -p "$DEST_DIR"
# Move the file to the destination directory
mv "$FILE" "$DEST_DIR"
# Increment the counter
INDEX=$((INDEX + 1))
fi
done
echo "Files have been distributed."
else
echo "Files are already distributed."
fi
# Execute the custom Python command for each distributed folder with delay
for SUBDIR in "$SRC_DIR"/*; do
if [ -d "$SUBDIR/ex2" ]; then
DEST_DIR="$SUBDIR/ex2"
COMMAND="python manage.py loadsubmissions $COURSE_NAME/$EXERCISE_NAME $DEST_DIR"
echo "Running command for $DEST_DIR"
echo "Command: $COMMAND"
# Execute the command
eval $COMMAND
# Wait for the specified delay before continuing to the next one
sleep $DELAY
fi
done
echo "Commands executed successfully for all folders."