]> mj.ucw.cz Git - moe.git/blob - public/submit
Cleaned up handling of SDIR and SRCN.
[moe.git] / public / submit
1 #!/bin/bash
2 # The Evaluator -- Public Submit Script
3 # (c) 2001--2004 Martin Mares <mj@ucw.cz>
4
5 set -e
6 [ -n "$MO_ROOT" -a -d "$MO_ROOT" ] || { echo >&2 "MO_ROOT not set, giving up." ; exit 1 ; }
7 . $MO_ROOT/bin/lib
8 . $MO_ROOT/config
9
10 function usage
11 {
12         die "Usage: submit [--force] [-s <source-file>] <problem> [<test-number>]"
13 }
14
15 FORCE=0
16 if [ "$1" = --force ] ; then
17         FORCE=1
18         shift
19 fi
20 [ -n "$1" -a "$1" != "--help" ] || usage
21 SRCFILE=
22 while getopts "s:" opt ; do
23         case $opt in
24                 s)      SRCFILE="$OPTARG"
25                         ;;
26                 *)      usage
27                         ;;
28         esac
29 done
30 shift $(($OPTIND-1))
31 [ -n "$1" ] || usage
32 PROBLEM=$1
33 PART=
34 shift
35 if [ -n "$1" ] ; then
36         PART="$1"
37         shift
38 fi
39 [ -z "$1" ] || usage
40 public-setup
41 . $PDIR/config
42
43 function test-verdict
44 {
45         pend "$2"
46         [ $1 == 0 ] && exit 1 || exit 0
47 }
48
49 FAILED=0
50 if [ $TASK_TYPE == open-data ] ; then
51         [ -n "$PART" ] || die "You need to specify test number for open data problems."
52         TEST=$PART
53         pstart "Test case $TEST: "
54         open-locate "$SRCFILE"
55         (
56                 ln "$SDIR/$SRCN" $TDIR/$TEST.out
57                 syntax-check
58                 test-result 1 OK
59         ) || FAILED=1
60 else
61         [ -z "$PART" ] || die "Test number should be given only for open data problems."
62         locate-source "$SRCFILE"
63         compile
64         for TEST in $SAMPLE_TESTS ; do
65                 (
66                 pstart "Checking on sample input $TEST: "
67                 test-run
68                 syntax-check
69                 output-check
70                 die "How could I get there? It's a buuuuug!"
71                 ) || FAILED=$(($FAILED+1))
72         done
73 fi
74
75 if [ $FAILED != 0 ] ; then
76         if [ $FORCE != 0 ] ; then
77                 echo "Submit forced."
78                 pend "TESTS FAILED, but --force given, so submitting anyway."
79         else
80                 pend "TESTS FAILED. Nothing has been submitted!"
81                 pend "Use submit --force if you really want to submit an obviously WRONG solution."
82                 exit 1
83         fi
84 fi
85
86 if [ -n "$REMOTE_SUBMIT" ] ; then
87         pstart "Submitting to the server... "
88         $MO_ROOT/bin/remote-submit $PROBLEM $PART "$SDIR/$SRCN"
89         pend "OK"
90         exit 0
91 fi
92
93 pstart "Submitting... "
94 mkdir -p ~/.submit
95 if [ $TASK_TYPE == open-data ] ; then
96         mkdir -p ~/.submit/$PROBLEM
97         cp "$SDIR/$SRCN" ~/.submit/$PROBLEM/$PART.out
98 else
99         rm -rf ~/.submit/$PROBLEM
100         mkdir -p ~/.submit/$PROBLEM
101         cp "$SDIR/$SRCN" ~/.submit/$PROBLEM/
102 fi
103 pend "OK"