]> mj.ucw.cz Git - moe.git/blob - mop/public/submit
Moved `public' to MO-P stuff, too. I will decide later where to put it.
[moe.git] / mop / public / submit
1 #!/bin/bash
2 # The Evaluator -- Public Submit Script
3 # (c) 2001--2007 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                 [ -f $PDIR/$TEST.config ] && . $PDIR/$TEST.config
57                 try-ln "$SDIR/$SRCN" $TDIR/$TEST.out
58                 syntax-check
59                 test-result $POINTS_PER_TEST OK
60         ) || FAILED=1
61 else
62         [ -z "$PART" ] || die "Test number should be given only for open data problems."
63         locate-source "$SRCFILE"
64         compile
65         for TEST in $SAMPLE_TESTS ; do
66                 (
67                 pstart "Checking on sample input $TEST: "
68                 [ -f $PDIR/$TEST.config ] && . $PDIR/$TEST.config
69                 test-run
70                 syntax-check
71                 output-check
72                 die "How could I get there? It's a buuuuug!"
73                 ) || FAILED=$(($FAILED+1))
74         done
75 fi
76
77 if [ $FAILED != 0 ] ; then
78         if [ $FORCE != 0 ] ; then
79                 echo "Submit forced."
80                 pend "TESTS FAILED, but --force given, so submitting anyway."
81         else
82                 pend "TESTS FAILED. Nothing has been submitted!"
83                 pend "Use submit --force if you really want to submit an obviously WRONG solution."
84                 exit 1
85         fi
86 fi
87
88 if [ -n "$REMOTE_SUBMIT" ] ; then
89         pstart "Submitting to the server... "
90         $MO_ROOT/bin/remote-submit $PROBLEM $PART "$SDIR/$SRCN"
91         pend "OK"
92         exit 0
93 fi
94
95 pstart "Submitting... "
96 mkdir -p ~/.submit
97 if [ $TASK_TYPE == open-data ] ; then
98         mkdir -p ~/.submit/$PROBLEM
99         cp "$SDIR/$SRCN" ~/.submit/$PROBLEM/$PART.out
100 else
101         rm -rf ~/.submit/$PROBLEM
102         mkdir -p ~/.submit/$PROBLEM
103         cp "$SDIR/$SRCN" ~/.submit/$PROBLEM/
104 fi
105 pend "OK"