From: Martin Mares Date: Thu, 15 May 2008 09:46:14 +0000 (+0200) Subject: Moved everything related to MO-P to mop/. This cleans up bin/. X-Git-Tag: python-dummy-working~201 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=f33e36eda1f3334370020f9c24bc14f1a0e09356;p=eval.git Moved everything related to MO-P to mop/. This cleans up bin/. These utilities are however not compiled yet. --- diff --git a/bin/mo-back-grab b/bin/mo-back-grab deleted file mode 100755 index 5628034..0000000 --- a/bin/mo-back-grab +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -if [ -z "$1" ] ; then - echo "Directory name expected" - exit 1 -fi -rm -rf solutions/mo* -for m in `cd $1 ; echo *` ; do - echo -n "$m:" - for d in $1/$m/mo??/mo?? ; do - u=`basename $d` - if [ $u != mo00 -a -d $d/.submit ] ; then - echo -n " $u" - if [ -d solutions/$u ] ; then - echo -n "" - else - cp -a $d/.submit solutions/$u - fi - fi - done - echo -done diff --git a/bin/mo-back-status b/bin/mo-back-status deleted file mode 100755 index e3eecc6..0000000 --- a/bin/mo-back-status +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh -if [ -z "$1" ] ; then - echo "Directory name expected" - exit 1 -fi -for m in `cd $1 ; echo *` ; do - echo -n "$m:" - for d in $1/$m/mo??/mo?? ; do - u=`basename $d` - if [ $u != mo00 -a `ls $d | wc -l` -gt 0 ] ; then - echo -n " $u" - if [ -d $d/.submit ] ; then - echo -n '(' - ( cd $d/.submit ; echo -n * ) - echo -n ')' - fi - fi - done - echo -done diff --git a/bin/mo-backup b/bin/mo-backup deleted file mode 100755 index 00b13f8..0000000 --- a/bin/mo-backup +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh -if [ -z "$1" ] ; then - D=back/`date '+%H%M'` -else - D=$1 -fi -mkdir -p $D -for m in `seq 27 74` ; do - m="ceoi$m" - echo -n "$m: " - mkdir $p $D/$m - pushd $D/$m >/dev/null - ssh root@$m 'cd /mo/users ; tar czf - . --exclude=.kde' | tar xzf - - popd >/dev/null - du -s $D/$m | cut -f 1 -done diff --git a/bin/mo-create-contestants b/bin/mo-create-contestants deleted file mode 100755 index 3cc4445..0000000 --- a/bin/mo-create-contestants +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } -set -e -. config - -H=`pwd` -cd $MO_ROOT -rm -rf users -mkdir users -cd users - -for a in `cd $H && bin/mo-get-users` ; do - echo "Creating $a" - mkdir $a $a/$a - chown root.$a $a - chmod 750 $a - cp -a `find $H/template -mindepth 1 -maxdepth 1` $a/$a/ - - if [ -n "$REMOTE_SUBMIT" ] ; then - M=$a/$a/.mo - mkdir $M - cp $H/certs/$a-cert.pem $M/cert.pem - cp $H/certs/$a-key.pem $M/key.pem - chmod 600 $M/key.pem - cp $H/certs/ca-cert.pem $M/ - fi - - chown $a.$a $a/$a -R - chmod 700 $a/$a -done diff --git a/bin/mo-create-eval b/bin/mo-create-eval deleted file mode 100755 index 707053c..0000000 --- a/bin/mo-create-eval +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } -set -e -. config - -H=`pwd` -cd $MO_ROOT/eval - -echo "Creating $EVAL_USER" -rm -rf eval -mkdir eval -cd eval -cp -a $H/* . -chmod +x bin/* -if [ -d ~/.ssh ] ; then echo "Copying SSH configuration from ~/.ssh" ; cp -a ~/.ssh . ; fi -cd .. -chown -R $EVAL_USER.$EVAL_GROUP eval -chmod 750 eval diff --git a/bin/mo-create-logins b/bin/mo-create-logins deleted file mode 100755 index f6fc868..0000000 --- a/bin/mo-create-logins +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/bash - -[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } -set -e -. config - -mode=$1 - -case "$mode" in - eval) uid=$EVAL_UID_MIN;; - users) uid=$CT_UID_MIN;; - *) echo "Usage: $0 [eval|users]!"; exit 1;; -esac - ->>etcshadow >>etcpasswd >>etcgroup -expire=$((`date +%s` / 86400 - 1)) - -case $mode in - eval) - echo -n Enter password for evaluation users: - read passwd - passwd=`echo $passwd | bin/md5crypt` - gid=$uid - tgid=$(($gid+1)) - rgid=$(($gid+2)) - echo $EVAL_USER:x:$uid:$gid:MO Evaluator:$MO_ROOT/eval/eval:/bin/bash >> etcpasswd - echo $EVAL_USER:$passwd:$expire:0:99999:7::: >> etcshadow - echo $EVAL_GROUP:x:$gid: >> etcgroup - echo $TEST_GROUP:x:$tgid:$EVAL_USER >> etcgroup - - if [ -n "$REMOTE_SUBMIT" ] ; then - uid=$(($uid + 1)) - echo $REMOTE_SUBMIT_USER:x:$uid:$rgid:MO Submitter:$MO_ROOT/eval/submit:/bin/bash >> etcpasswd - echo $REMOTE_SUBMIT_USER:$passwd:$expire:0:99999:7::: >> etcshadow - echo $REMOTE_SUBMIT_GROUP:x:$rgid: >> etcgroup - fi - - tuid=$(($uid + 1)) - for tester in $TEST_USERS; do - echo $tester:x:$tuid:$tgid:MO Tester `expr $tuid - $uid`:$MO_ROOT/eval/$tester:/bin/bash >> etcpasswd - echo $tester:$passwd:$expire:0:99999:7::: >> etcshadow - tuid=$(($tuid + 1)) - done - ;; - - users) -# if [ -f logins.tex ]; then echo "File logins.tex exists! Bailing out!"; exit 1; fi - cat > logins.tex <<- EOF - \\nopagenumbers - \\voffset=-1.5cm\\vsize=280mm\\hoffset=-0.75cm\\advance\\hsize by 3cm - \\raggedright\\parindent=0pt - \\font\\ftt=cstt17 - \\font\\frm=csr17 - \\font\\fit=csti17 - \\ftt - \\def\\user#1#2#3{\\vbox to 4.5cm{\\hsize=6cm\\vss\\vss{\\fit Practice Session}\\vss\\vss{\\frm #3}\\vss\\vss#1\\vss#2\\vss\\vss}} - \\leavevmode - EOF - - bin/mo-get-users --full | while read user name; do - passwd=`apg -n1 -m6 -Mncl | cut -d" " -f1 | tr l1O0 '@*?-' ` - passwd_md5=`echo $passwd | bin/md5crypt` - echo $user:x:$uid:$uid:$name:$MO_ROOT/users/$user/$user:/bin/bash >> etcpasswd - echo $user:x:$uid: >> etcgroup - echo $user:$passwd_md5:`expr \`date +%s\` / 86400 - 1`:0:99999:7::: >> etcshadow - echo "\\user{$user}{$passwd}{$name}" >> logins.tex - uid=$(($uid + 1)) - done - - cat >> logins.tex <<- EOF - \\vfil - \\bye - EOF - ;; -esac diff --git a/bin/mo-create-packages b/bin/mo-create-packages deleted file mode 100755 index bad77cd..0000000 --- a/bin/mo-create-packages +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -# Create contestant directories with their solutions and test logs - -[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } -set -e -. config - -H=`pwd` -cd $MO_ROOT -rm -rf users2 -mkdir users2 -cd users2 - -for a in `cd $H && bin/mo-get-users` ; do - echo "Creating $a" - mkdir $a $a/$a - chown root.$a $a - chmod 750 $a - cp -a `find $H/template -type f -name ".*"` $a/$a/ - if [ -d $H/solutions/$a ] ; then cp -a $H/solutions/$a $a/$a/solutions ; fi - if [ -d $H/testing/$a ] ; then cp -a $H/testing/$a $a/$a/testing ; fi - chown $a.$a $a/$a -R - chmod 700 $a/$a -done diff --git a/bin/mo-create-public b/bin/mo-create-public deleted file mode 100755 index 91c9c8e..0000000 --- a/bin/mo-create-public +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } -set -e -. config - -echo "Populating $MO_ROOT/public" -H=`pwd` -cd $MO_ROOT/public -rm -rf bin lib - -sed '/^\(TEST_USER\|MO_ROOT\)=/s/^/#/' <$H/config >config - -mkdir bin -cp -a $H/public/[a-z]* bin/ -for a in `cat $H/public/COPY` ; do - cp -a $H/$a bin/ -done - -if [ -n "$REMOTE_SUBMIT" ] ; then - cp $H/submit/{contest,remote-submit,remote-status} bin/ - mkdir lib - cp -a $H/submit/lib . -fi - -mkdir -p problems - -if [ `id -u` == 0 ] ; then - chown -R $EVAL_USER.$EVAL_GROUP . - chmod 755 . -fi diff --git a/bin/mo-create-submit b/bin/mo-create-submit deleted file mode 100755 index 2d34543..0000000 --- a/bin/mo-create-submit +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } -set -e -. config -[ -n "$REMOTE_SUBMIT" ] || { echo "Remote submit not enabled." ; exit 1 ; } - -echo "Creating submit directory" - -H=`pwd` -cd $MO_ROOT/eval/submit -mkdir -p certs -cp $H/certs/server* certs/ -cp $H/certs/ca-cert.pem certs/ - -rm -rf submit -mkdir -p submit -cp $H/submit/{submitd,config,show-submits} submit/ - -mkdir -p solutions -for a in `cd $H && bin/mo-get-users` ; do - mkdir -p solutions/$a -done - -rm -rf lib -cp -a $H/submit/lib lib - -rm -rf tmp -mkdir -p tmp - -mkdir -p log history - -chown -R $REMOTE_SUBMIT_USER.$REMOTE_SUBMIT_GROUP $MO_ROOT/eval/submit diff --git a/bin/mo-create-testusers b/bin/mo-create-testusers deleted file mode 100755 index aec3535..0000000 --- a/bin/mo-create-testusers +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } -set -e -. config - -H=`pwd` -cd $MO_ROOT/eval - -# mo-test home -for u in $TEST_USERS ; do - echo "Creating $u" - rm -rf ./$u - mkdir $u - chown $u.$TEST_GROUP $u - chmod 770 $u - cp $H/bin/box eval/bin/box-$u - chown $u.$EVAL_GROUP eval/bin/box-$u - chmod 4550 eval/bin/box-$u -done diff --git a/bin/mo-ev-all b/bin/mo-ev-all deleted file mode 100755 index 8ce6dff..0000000 --- a/bin/mo-ev-all +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -[ -n "$1" ] || { echo "Usage: mo-ev-all " ; exit 1 ; } - -while [ -n "$1" ] ; do - for user in `bin/mo-get-users` ; do - echo -e "\n### USER $user TASK $1 ###\n" - bin/ev $user $1 - done - shift -done diff --git a/bin/mo-ev-inc b/bin/mo-ev-inc deleted file mode 100755 index 26f856b..0000000 --- a/bin/mo-ev-inc +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -[ -n "$1" ] || { echo "Usage: mo-ev-inc [--force] " ; exit 1 ; } - -force=0 -if [ "$1" == --force ] ; then - force=1 - shift -fi -for user in `bin/mo-get-users` ; do - for task in "$@" ; do - echo -n "$user/$task: " - if [ -d solutions/$user/$task ] ; then - N=`cd solutions/$user/$task && cat * | md5sum | head -c16` - else - N=none - fi - if [ -f testing/$user/$task/sum ] ; then - O=`cat testing/$user/$task/sum` - else - O=none - fi - if [ $force == 1 -a $N != none ] ; then - O=forced - fi - echo -n "($O $N) " - if [ $O == $N ] ; then - echo OK - elif [ $N == none ] ; then - rm -rf testing/$user/$task - echo DELETED - else - echo CHANGED - bin/ev $user $task - echo $N >testing/$user/$task/sum - fi - done -done diff --git a/bin/mo-get-users b/bin/mo-get-users deleted file mode 100755 index f85919e..0000000 --- a/bin/mo-get-users +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -if [ "$1" = --help ] ; then - echo "Usage: mo-get-users [--full]" -fi -[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } -set -e -. config - -if [ -z "$CT_USER_LIST" ] ; then - if [ "$1" = --full ] ; then - FORM='$1,$5' - else - FORM='$1' - fi - awk -F: = $CT_UID_MIN && \$3 <= $CT_UID_MAX) print $FORM; }" -else - if [ "$1" = --full ] ; then - cut -d ' ' -f 1,2 <$CT_USER_LIST - else - cut -d ' ' -f 1 <$CT_USER_LIST - fi -fi diff --git a/bin/mo-grab b/bin/mo-grab deleted file mode 100755 index 9ce2f19..0000000 --- a/bin/mo-grab +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -[ -n "$1" ] || { echo "Usage: mo-grab " ; exit 1 ; } -[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } -set -e -. config - -for user in `bin/mo-get-users` ; do - echo -n "$user:" - H=`eval echo ~$user`/.submit - if [ -d $H ] ; then - [ -d solutions/$user ] || mkdir -p solutions/$user - for t in $@ ; do - rm -rf solutions/$user/$t - if [ -d $H/$t ] ; then - echo -n " $t" - cp -dr $H/$t solutions/$user/$t - fi - done - echo - else - echo " ---" - fi -done -chown -R $EVAL_USER solutions -chmod -R a+r solutions diff --git a/bin/mo-grab-remote b/bin/mo-grab-remote deleted file mode 100755 index 6181b4e..0000000 --- a/bin/mo-grab-remote +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -[ -n "$1" ] || { echo "Usage: mo-grab-remote " ; exit 1 ; } -[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } -set -e -. config - -for user in `bin/mo-get-users` ; do - echo -n "$user:" - mkdir -p solutions/$user - for t in $@ ; do - rm -rf solutions/$user/$t - D=$MO_ROOT/eval/submit/solutions/$user/$t - if [ -d $D ] ; then - echo -n " $t" - cp -a $D solutions/$user/$t - fi - done - echo -done diff --git a/bin/mo-install b/bin/mo-install deleted file mode 100755 index f4456a9..0000000 --- a/bin/mo-install +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } -set -e -. config - -H=`pwd` - -# The eval directory -cd $MO_ROOT -rm -rf eval -mkdir eval -chgrp $EVAL_GROUP eval -chmod 755 eval -cd eval - -# mo-eval home -( cd $H && bin/mo-create-eval ) - -# testusers -( cd eval && bin/mo-create-testusers ) - -# mo-submit home -if [ -n "$REMOTE_SUBMIT" ] ; then - mkdir submit - chmod 750 submit - if [ -d ~/.ssh ] ; then echo "Copying SSH configuration from ~/.ssh" ; cp -a ~/.ssh submit/ ; fi - ( cd $H && bin/mo-create-submit ) -fi - -# create public -cd $MO_ROOT -echo "Creating public" -rm -rf public -mkdir public - -# populate public -( cd eval/eval ; bin/mo-create-public ) diff --git a/bin/mo-merge-tests b/bin/mo-merge-tests deleted file mode 100755 index 03ef1ef..0000000 --- a/bin/mo-merge-tests +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/perl - -# This script recalculates points according to grouping of testcases. -# This is no longer necessary, because the score table and report generators -# already know how to handle merging of groups, but we still keep it as an example. - -@ARGV == 1 or die "Usage: mo-merge \n"; -my $task = $ARGV[0]; -foreach my $s (`ls -d testing/*/$task`) { - chomp $s; - if (! -s "$s/points.old") { - if (-s "$s/points") { - rename "$s/points", "$s/points.old" or die "Rename $s/points failed: $!"; - } else { - print "$s: NO POINTS?\n"; - next; - } - } - open X, "$s/points.old" or die; - my %tests = (); - my %cmts = (); - while () { - chomp; - my ($test, $subtest, $pts, $cmt) = /^(\d+)([a-z]*)\s+(\d+)\s*(.*)/ or die; - if (!exists($tests{$test}) || $tests{$test} > $pts) { - $tests{$test} = $pts; - $cmts{$test} = $cmt; - } - } - close X; - open X, ">$s/points" or die; - foreach my $test (sort { $a <=> $b } keys %tests) { - print X "$test $tests{$test} $cmts{$test}\n"; - } - close X; -} diff --git a/bin/mo-push-certs b/bin/mo-push-certs deleted file mode 100755 index 54b84ba..0000000 --- a/bin/mo-push-certs +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } -set -e -. config - -while IFS=" " read LOGIN FULL MACH ; do - if [ -z "$1" -o "$1" == "$LOGIN" ] ; then - echo "$LOGIN -> $MACH" - D=/mo/users/$LOGIN/$LOGIN/ - rsync -av $D/.mo root@$MACH:$D/ - fi $MACH" - D=/mo/users/$LOGIN/$LOGIN/ - rsync -av ~mo-eval/testing/$LOGIN root@$MACH:$D/results - ssh root@$MACH "cd $D && chown -R $LOGIN.$LOGIN results" - fi testing/$user/REPORT" or die; - print REP "Evaluation report for CEOI 2007 Day 2\n\n"; - my $total = 0; - foreach my $task (@ARGV) { - print REP "### Task $task ###\n\n"; - if (open PTS, "testing/$user/$task/points") { - my %merged_pts = (); - my %split_comm = (); - while () { - chomp; - my ($test, $pts, $comm) = /(\S+)\s+(\S+)\s+(.*)/; - my $merged = $test; - $merged =~ s/[^0-9]//; - if (!defined($merged_pts{$merged}) || $merged_pts{$merged} > $pts) { - $merged_pts{$merged} = $pts; - } - $split_comm{$merged}{$test} = $comm; - } - close PTS; - my $tt = 0; - foreach my $merged (sort { $a <=> $b } keys %merged_pts) { - printf REP "Test %2s: %2d points", $merged, $merged_pts{$merged}; - $tt += $merged_pts{$merged}; - my @k = sort keys %{$split_comm{$merged}}; - if (@k == 1) { - print REP " -- ", $split_comm{$merged}{$k[0]}, "\n"; - } else { - print REP " -- "; - my $cc = 0; - foreach my $t (@k) { - $cc++ and print REP ", "; - print REP "$t: $split_comm{$merged}{$t}"; - } - print REP "\n"; - } - } - print REP "\nTOTAL: $tt points\n\n"; - $total += $tt; - print " $tt"; - } else { - print REP "No solution submitted.\n\n"; - print " -"; - } - } - print REP "### TOTAL FOR DAY 2 ###\n\n"; - print REP "$total points\n"; - print REP "\n\n(generated on ", strftime("%Y-%m-%d %H:%M:%S", localtime), ")\n"; - close REP; - print " -> $total\n"; -} diff --git a/bin/mo-score b/bin/mo-score deleted file mode 100755 index 4dec3a1..0000000 --- a/bin/mo-score +++ /dev/null @@ -1,285 +0,0 @@ -#!/usr/bin/perl - -$debug = 0; -$detail = 0; -$html = 0; -$tex = 0; -$extras = 0; -$alt = 0; -$merged = 0; -$usage = "Usage: mo-score [--detail] [--alt] [--extras] [--html] [--tex] [--merged] [/] ..."; -while (($arg = $ARGV[0]) =~ /^--([a-z]+)$/) { - shift @ARGV; - $var = "\$$1"; - if (!eval "defined $var") { die $usage; } - eval "$var = 1;"; -} -@ARGV || die $usage; - -print STDERR "Scanning contestants... "; -open (CT, "bin/mo-get-users --full |") || die "Cannot get list of contestants"; -while () { - chomp; - ($u,$f) = split /\t/; - ($u eq "somebody") && next; - $users{$u}=$f; -} -close CT; -print STDERR 0+keys %users, "\n"; - -print STDERR "Scanning exceptions... "; -if ($extras && open (EX, "exceptions")) { - while () { - chomp; - (/^$/ || /^#/) && next; - @a = split /\s+/; - $u = shift @a; - defined $users{$u} || die "Unknown user $u"; - while (@a) { $extra{$u} += shift @a; } - } - close EX; - print STDERR "OK\n"; -} else { print STDERR "none\n"; } - -print STDERR "Scanning task results... "; -%messages = (); -%error_codes = (); -foreach $u (keys %users) { - foreach $task (@ARGV) { - my ($dir, $t) = ("testing", $task); - if ($task =~ m@^(.*)/([^/]*)$@) { - $dir = $1; - $t = $2; - } - $known_tasks{$t} = 1; - $tt = "$dir/$u/$t/points" . ($alt ? ".alt" : ""); - -f $tt || next; - print STDERR "$u/$t "; - open (X, $tt) || die "Unable to open $tt"; - while () { - chomp; - /^(\S+) (-?\d+)\s*(.*)/ || die "Parse error: $_"; - $ttest = $1; - $tpts = $2; - $trem = $3; - $trem =~ s/\[.*//; - ($ttest_merged = $ttest) =~ s/[^0-9]//g; - $ttest = $ttest_merged if $merged; - $known_tests{$t}{$ttest} = 1; - $cmt = $tpts; - if ($tpts == 0 && $trem ne "OK") { - if ($trem =~ /^Compile /) { $cmt = "CE"; } - elsif ($trem =~ /^Time limit exceeded/) { $cmt = "TO"; } - elsif ($trem =~ /^Exited with error /) { $cmt = "RE"; } - elsif ($trem =~ /^Caught fatal signal /) { $cmt = "SG"; } - elsif ($trem =~ /^([A-Za-z])\S*\s+([A-Za-z])/) { - ($cmt = "$1$2") =~ tr/a-z/A-Z/; - } - if (!defined $messages{$trem}) { - $messages{$trem} = $cmt; - if (!defined $error_codes{$cmt}) { - $error_codes{$cmt} = $trem; - } else { - $error_codes{$cmt} .= ", $trem"; - } - } - } - if (!defined($results{$u}{$t}{$ttest}) || $results{$u}{$t}{$ttest} > $tpts) { - $results{$u}{$t}{$ttest} = $tpts; - $comment{$u}{$t}{$ttest} = $cmt; - } - if (!defined($results_merged{$u}{$t}{$ttest_merged}) || $results_merged{$u}{$t}{$ttest_merged} > $tpts) { - $results_merged{$u}{$t}{$ttest_merged} = $tpts; - } - } - close X; - } - foreach my $t (keys %known_tasks) { - $total{$u}{$t} = 0; - foreach my $pts (values %{$results_merged{$u}{$t}}) { $total{$u}{$t} += $pts; } - } -} -print STDERR "OK\n"; - -print STDERR "Creating table template... "; -@header = ("Rank","User","Name"); -@body = ('','$u','$users{$u}'); -@bodysums = (); -@footer = ('"Total"','',''); -if (keys %extra) { - push @header, "Extra"; - push @body, '$extra{$u}'; - $col = 0+@footer; - push @bodysums, $col; - push @footer, "sum($col)"; -} -@tasks = (); -foreach $task (@ARGV) { - my $t = ($task =~ m@/([^/]*)$@) ? $1 : $task; - defined $known_tasks{$t} || die "Unknown task $t"; - push @tasks, $t; - push @header, substr($t, 0, 4); - push @body, "(\$xx = \$total{\$u}{'$t'}) > 0 ? \$xx : 0"; - $col = 0+@footer; - push @footer, "sum($col)"; - push @bodysums, $col; - if ($detail) { - foreach $s (sort { $a <=> $b } keys %{$known_tests{$t}}) { - push @header, "$s"; - push @body, "\$comment{\$u}{'$t'}{'$s'}"; - $col = 0+@footer; - push @footer, "sum($col)"; - } - } -} -push @header, "Total"; -push @body, join('+', map { $_ = "\$$_" } @bodysums); -$col = 0+@footer; -push @footer, "sum($col)"; -print STDERR "OK\n"; - -print STDERR "h: ", join(':',@header), "\n" if $debug; -print STDERR "b: ", join(':',@body), "\n" if $debug; -print STDERR "f: ", join(':',@footer), "\n" if $debug; - -print STDERR "Filling in results... "; -@table = (); -foreach $u (keys %users) { - $row = []; - foreach my $c (@body) { - $c =~ s/\$(\d+)/\$\$row[$1]/g; - $x = eval $c; - push @$row, (defined $x ? $x : '-'); - } - print STDERR "row: ", join(':',@$row), "\n" if $debug; - push @table, $row; -} -print STDERR "OK\n"; - -print STDERR "Sorting... "; -$sortcol = @{$table[0]} - 1; -$namecol = 2; -@table = sort { - my $p, $an, $bn; - $p = $$b[$sortcol] <=> $$a[$sortcol]; - ($an = $$a[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/; - ($bn = $$b[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/; - $p ? $p : ($an cmp $bn); -} @table; -$i=0; -while ($i < @table) { - $j = $i; - while ($i < @table && ${$table[$i]}[$sortcol] == ${$table[$j]}[$sortcol]) { - $i++; - } - if ($i == $j+1) { - ${table[$j]}[0] = "$i."; - } else { - ${table[$j]}[0] = $j+1 . ".-" . $i . "."; - $j++; - while ($j < $i) { ${table[$j++]}[0] = ""; }; - } -} -print STDERR "OK\n"; - -print STDERR "Attaching headers and footers... "; -sub sum { my $col=shift @_; my $t=0; foreach my $z (0..@table-1) { $t += ${$table[$z]}[$col]; } $t; } -map { $_ = eval $_; } @footer; -push @table, \@footer; -unshift @table, \@header; -print STDERR "OK\n"; - -if ($debug) { - foreach $r (@table) { print join(':',@$r), "\n"; } -} elsif ($html) { - print '', "\n"; - print "Rank list\n"; - print "

Rank list

\n"; - - my @perm; - &printHtmlHeader(\@perm); - print ""; - - foreach $r (@table[1..($#table - 1)]) { - &printHtmlRow(@{$r}[@perm]); - } - - print ""; - &printHtmlRow(@{$table[$#table]}[@perm]); - - print "\n"; - if ($detail) { - print "

Error codes

    \n"; - foreach $r (sort keys %error_codes) { print "
  • $r: $error_codes{$r}\n"; } - print "
\n"; - } - print "\n"; -} elsif ($tex) { - print "\\error{TeX output not supported yet!}\n"; -} else { - foreach $r (@table) { print join("\t",@$r), "\n"; } - print "\n"; - foreach $r (sort keys %error_codes) { print "$r: $error_codes{$r}\n"; } -} - - -sub printHtmlRow { - print "", join('',map { - if ($hdr) { $_ = "$_"; } - else { $_ = " 14 ? " width=150" : "") . ">$_"; } - } @_), "\n"; -} - - -sub printHtmlHeader { - - my ($perm) = @_; - - my $colspec = ""; - my $hdr1; - my $hdr2; - - @$perm = (0, 1, 2); - my $p = 3; - - if ($detail) { - $hdr1 = "RankUserName"; - $extras and $p++ and push @$perm, 3 and $hdr1.="Extra" and $colspec.=""; ##Extra hack - for my $task (@tasks) { - - my $nSub = scalar(keys %{$known_tests{$task}}); - - $p++; - map { push @$perm, $p++ } (1..$nSub); - push @$perm, $p - $nSub - 1; - - $colspec .= "\n"; - $colspec .= "\n"; - $hdr1 .= "$task"; - $hdr2 .= join("", map { "$_" } sort {$a <=> $b} keys %{$known_tests{$task}}); - $hdr2 .= "Total"; - } - - $hdr1 .= "Total"; - - } else { ## no detail - - $hdr1 = "RankUserName"; - $extras and $p++ and push @$perm, 3 and $hdr1.="Extra" and $colspec.=""; ##Extra hack - - for my $task (@tasks) { - push @$perm, $p++; - $hdr1 .= "$task"; - } - $hdr1 .= "Total"; - $colspec .= ""; - } - - push @$perm, $p++; - - print "\n"; - print "$colspec\n"; - print "$hdr1\n"; - print "$hdr2\n" if $detail; - -} diff --git a/bin/print-score b/bin/print-score deleted file mode 100755 index 292ca59..0000000 --- a/bin/print-score +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -set -e -[ -n "$1" ] -sed <$1 's/^/ /' | a2ps -Ma4 -r --columns=1 --rows=1 --font-size=10 --borders=no -B -o /tmp/score.ps -print /tmp/score.ps diff --git a/mop/mo-back-grab b/mop/mo-back-grab new file mode 100755 index 0000000..5628034 --- /dev/null +++ b/mop/mo-back-grab @@ -0,0 +1,21 @@ +#!/bin/sh +if [ -z "$1" ] ; then + echo "Directory name expected" + exit 1 +fi +rm -rf solutions/mo* +for m in `cd $1 ; echo *` ; do + echo -n "$m:" + for d in $1/$m/mo??/mo?? ; do + u=`basename $d` + if [ $u != mo00 -a -d $d/.submit ] ; then + echo -n " $u" + if [ -d solutions/$u ] ; then + echo -n "" + else + cp -a $d/.submit solutions/$u + fi + fi + done + echo +done diff --git a/mop/mo-back-status b/mop/mo-back-status new file mode 100755 index 0000000..e3eecc6 --- /dev/null +++ b/mop/mo-back-status @@ -0,0 +1,20 @@ +#!/bin/sh +if [ -z "$1" ] ; then + echo "Directory name expected" + exit 1 +fi +for m in `cd $1 ; echo *` ; do + echo -n "$m:" + for d in $1/$m/mo??/mo?? ; do + u=`basename $d` + if [ $u != mo00 -a `ls $d | wc -l` -gt 0 ] ; then + echo -n " $u" + if [ -d $d/.submit ] ; then + echo -n '(' + ( cd $d/.submit ; echo -n * ) + echo -n ')' + fi + fi + done + echo +done diff --git a/mop/mo-backup b/mop/mo-backup new file mode 100755 index 0000000..00b13f8 --- /dev/null +++ b/mop/mo-backup @@ -0,0 +1,16 @@ +#!/bin/sh +if [ -z "$1" ] ; then + D=back/`date '+%H%M'` +else + D=$1 +fi +mkdir -p $D +for m in `seq 27 74` ; do + m="ceoi$m" + echo -n "$m: " + mkdir $p $D/$m + pushd $D/$m >/dev/null + ssh root@$m 'cd /mo/users ; tar czf - . --exclude=.kde' | tar xzf - + popd >/dev/null + du -s $D/$m | cut -f 1 +done diff --git a/mop/mo-create-contestants b/mop/mo-create-contestants new file mode 100755 index 0000000..3cc4445 --- /dev/null +++ b/mop/mo-create-contestants @@ -0,0 +1,31 @@ +#!/bin/bash + +[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } +set -e +. config + +H=`pwd` +cd $MO_ROOT +rm -rf users +mkdir users +cd users + +for a in `cd $H && bin/mo-get-users` ; do + echo "Creating $a" + mkdir $a $a/$a + chown root.$a $a + chmod 750 $a + cp -a `find $H/template -mindepth 1 -maxdepth 1` $a/$a/ + + if [ -n "$REMOTE_SUBMIT" ] ; then + M=$a/$a/.mo + mkdir $M + cp $H/certs/$a-cert.pem $M/cert.pem + cp $H/certs/$a-key.pem $M/key.pem + chmod 600 $M/key.pem + cp $H/certs/ca-cert.pem $M/ + fi + + chown $a.$a $a/$a -R + chmod 700 $a/$a +done diff --git a/mop/mo-create-eval b/mop/mo-create-eval new file mode 100755 index 0000000..707053c --- /dev/null +++ b/mop/mo-create-eval @@ -0,0 +1,19 @@ +#!/bin/bash + +[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } +set -e +. config + +H=`pwd` +cd $MO_ROOT/eval + +echo "Creating $EVAL_USER" +rm -rf eval +mkdir eval +cd eval +cp -a $H/* . +chmod +x bin/* +if [ -d ~/.ssh ] ; then echo "Copying SSH configuration from ~/.ssh" ; cp -a ~/.ssh . ; fi +cd .. +chown -R $EVAL_USER.$EVAL_GROUP eval +chmod 750 eval diff --git a/mop/mo-create-logins b/mop/mo-create-logins new file mode 100755 index 0000000..f6fc868 --- /dev/null +++ b/mop/mo-create-logins @@ -0,0 +1,75 @@ +#!/bin/bash + +[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } +set -e +. config + +mode=$1 + +case "$mode" in + eval) uid=$EVAL_UID_MIN;; + users) uid=$CT_UID_MIN;; + *) echo "Usage: $0 [eval|users]!"; exit 1;; +esac + +>>etcshadow >>etcpasswd >>etcgroup +expire=$((`date +%s` / 86400 - 1)) + +case $mode in + eval) + echo -n Enter password for evaluation users: + read passwd + passwd=`echo $passwd | bin/md5crypt` + gid=$uid + tgid=$(($gid+1)) + rgid=$(($gid+2)) + echo $EVAL_USER:x:$uid:$gid:MO Evaluator:$MO_ROOT/eval/eval:/bin/bash >> etcpasswd + echo $EVAL_USER:$passwd:$expire:0:99999:7::: >> etcshadow + echo $EVAL_GROUP:x:$gid: >> etcgroup + echo $TEST_GROUP:x:$tgid:$EVAL_USER >> etcgroup + + if [ -n "$REMOTE_SUBMIT" ] ; then + uid=$(($uid + 1)) + echo $REMOTE_SUBMIT_USER:x:$uid:$rgid:MO Submitter:$MO_ROOT/eval/submit:/bin/bash >> etcpasswd + echo $REMOTE_SUBMIT_USER:$passwd:$expire:0:99999:7::: >> etcshadow + echo $REMOTE_SUBMIT_GROUP:x:$rgid: >> etcgroup + fi + + tuid=$(($uid + 1)) + for tester in $TEST_USERS; do + echo $tester:x:$tuid:$tgid:MO Tester `expr $tuid - $uid`:$MO_ROOT/eval/$tester:/bin/bash >> etcpasswd + echo $tester:$passwd:$expire:0:99999:7::: >> etcshadow + tuid=$(($tuid + 1)) + done + ;; + + users) +# if [ -f logins.tex ]; then echo "File logins.tex exists! Bailing out!"; exit 1; fi + cat > logins.tex <<- EOF + \\nopagenumbers + \\voffset=-1.5cm\\vsize=280mm\\hoffset=-0.75cm\\advance\\hsize by 3cm + \\raggedright\\parindent=0pt + \\font\\ftt=cstt17 + \\font\\frm=csr17 + \\font\\fit=csti17 + \\ftt + \\def\\user#1#2#3{\\vbox to 4.5cm{\\hsize=6cm\\vss\\vss{\\fit Practice Session}\\vss\\vss{\\frm #3}\\vss\\vss#1\\vss#2\\vss\\vss}} + \\leavevmode + EOF + + bin/mo-get-users --full | while read user name; do + passwd=`apg -n1 -m6 -Mncl | cut -d" " -f1 | tr l1O0 '@*?-' ` + passwd_md5=`echo $passwd | bin/md5crypt` + echo $user:x:$uid:$uid:$name:$MO_ROOT/users/$user/$user:/bin/bash >> etcpasswd + echo $user:x:$uid: >> etcgroup + echo $user:$passwd_md5:`expr \`date +%s\` / 86400 - 1`:0:99999:7::: >> etcshadow + echo "\\user{$user}{$passwd}{$name}" >> logins.tex + uid=$(($uid + 1)) + done + + cat >> logins.tex <<- EOF + \\vfil + \\bye + EOF + ;; +esac diff --git a/mop/mo-create-packages b/mop/mo-create-packages new file mode 100755 index 0000000..bad77cd --- /dev/null +++ b/mop/mo-create-packages @@ -0,0 +1,24 @@ +#!/bin/bash +# Create contestant directories with their solutions and test logs + +[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } +set -e +. config + +H=`pwd` +cd $MO_ROOT +rm -rf users2 +mkdir users2 +cd users2 + +for a in `cd $H && bin/mo-get-users` ; do + echo "Creating $a" + mkdir $a $a/$a + chown root.$a $a + chmod 750 $a + cp -a `find $H/template -type f -name ".*"` $a/$a/ + if [ -d $H/solutions/$a ] ; then cp -a $H/solutions/$a $a/$a/solutions ; fi + if [ -d $H/testing/$a ] ; then cp -a $H/testing/$a $a/$a/testing ; fi + chown $a.$a $a/$a -R + chmod 700 $a/$a +done diff --git a/mop/mo-create-public b/mop/mo-create-public new file mode 100755 index 0000000..91c9c8e --- /dev/null +++ b/mop/mo-create-public @@ -0,0 +1,31 @@ +#!/bin/bash + +[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } +set -e +. config + +echo "Populating $MO_ROOT/public" +H=`pwd` +cd $MO_ROOT/public +rm -rf bin lib + +sed '/^\(TEST_USER\|MO_ROOT\)=/s/^/#/' <$H/config >config + +mkdir bin +cp -a $H/public/[a-z]* bin/ +for a in `cat $H/public/COPY` ; do + cp -a $H/$a bin/ +done + +if [ -n "$REMOTE_SUBMIT" ] ; then + cp $H/submit/{contest,remote-submit,remote-status} bin/ + mkdir lib + cp -a $H/submit/lib . +fi + +mkdir -p problems + +if [ `id -u` == 0 ] ; then + chown -R $EVAL_USER.$EVAL_GROUP . + chmod 755 . +fi diff --git a/mop/mo-create-submit b/mop/mo-create-submit new file mode 100755 index 0000000..2d34543 --- /dev/null +++ b/mop/mo-create-submit @@ -0,0 +1,33 @@ +#!/bin/bash + +[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } +set -e +. config +[ -n "$REMOTE_SUBMIT" ] || { echo "Remote submit not enabled." ; exit 1 ; } + +echo "Creating submit directory" + +H=`pwd` +cd $MO_ROOT/eval/submit +mkdir -p certs +cp $H/certs/server* certs/ +cp $H/certs/ca-cert.pem certs/ + +rm -rf submit +mkdir -p submit +cp $H/submit/{submitd,config,show-submits} submit/ + +mkdir -p solutions +for a in `cd $H && bin/mo-get-users` ; do + mkdir -p solutions/$a +done + +rm -rf lib +cp -a $H/submit/lib lib + +rm -rf tmp +mkdir -p tmp + +mkdir -p log history + +chown -R $REMOTE_SUBMIT_USER.$REMOTE_SUBMIT_GROUP $MO_ROOT/eval/submit diff --git a/mop/mo-create-testusers b/mop/mo-create-testusers new file mode 100755 index 0000000..aec3535 --- /dev/null +++ b/mop/mo-create-testusers @@ -0,0 +1,20 @@ +#!/bin/bash + +[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } +set -e +. config + +H=`pwd` +cd $MO_ROOT/eval + +# mo-test home +for u in $TEST_USERS ; do + echo "Creating $u" + rm -rf ./$u + mkdir $u + chown $u.$TEST_GROUP $u + chmod 770 $u + cp $H/bin/box eval/bin/box-$u + chown $u.$EVAL_GROUP eval/bin/box-$u + chmod 4550 eval/bin/box-$u +done diff --git a/mop/mo-ev-all b/mop/mo-ev-all new file mode 100755 index 0000000..8ce6dff --- /dev/null +++ b/mop/mo-ev-all @@ -0,0 +1,11 @@ +#!/bin/bash + +[ -n "$1" ] || { echo "Usage: mo-ev-all " ; exit 1 ; } + +while [ -n "$1" ] ; do + for user in `bin/mo-get-users` ; do + echo -e "\n### USER $user TASK $1 ###\n" + bin/ev $user $1 + done + shift +done diff --git a/mop/mo-ev-inc b/mop/mo-ev-inc new file mode 100755 index 0000000..26f856b --- /dev/null +++ b/mop/mo-ev-inc @@ -0,0 +1,38 @@ +#!/bin/bash + +[ -n "$1" ] || { echo "Usage: mo-ev-inc [--force] " ; exit 1 ; } + +force=0 +if [ "$1" == --force ] ; then + force=1 + shift +fi +for user in `bin/mo-get-users` ; do + for task in "$@" ; do + echo -n "$user/$task: " + if [ -d solutions/$user/$task ] ; then + N=`cd solutions/$user/$task && cat * | md5sum | head -c16` + else + N=none + fi + if [ -f testing/$user/$task/sum ] ; then + O=`cat testing/$user/$task/sum` + else + O=none + fi + if [ $force == 1 -a $N != none ] ; then + O=forced + fi + echo -n "($O $N) " + if [ $O == $N ] ; then + echo OK + elif [ $N == none ] ; then + rm -rf testing/$user/$task + echo DELETED + else + echo CHANGED + bin/ev $user $task + echo $N >testing/$user/$task/sum + fi + done +done diff --git a/mop/mo-get-users b/mop/mo-get-users new file mode 100755 index 0000000..f85919e --- /dev/null +++ b/mop/mo-get-users @@ -0,0 +1,23 @@ +#!/bin/bash + +if [ "$1" = --help ] ; then + echo "Usage: mo-get-users [--full]" +fi +[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } +set -e +. config + +if [ -z "$CT_USER_LIST" ] ; then + if [ "$1" = --full ] ; then + FORM='$1,$5' + else + FORM='$1' + fi + awk -F: = $CT_UID_MIN && \$3 <= $CT_UID_MAX) print $FORM; }" +else + if [ "$1" = --full ] ; then + cut -d ' ' -f 1,2 <$CT_USER_LIST + else + cut -d ' ' -f 1 <$CT_USER_LIST + fi +fi diff --git a/mop/mo-grab b/mop/mo-grab new file mode 100755 index 0000000..9ce2f19 --- /dev/null +++ b/mop/mo-grab @@ -0,0 +1,26 @@ +#!/bin/bash + +[ -n "$1" ] || { echo "Usage: mo-grab " ; exit 1 ; } +[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } +set -e +. config + +for user in `bin/mo-get-users` ; do + echo -n "$user:" + H=`eval echo ~$user`/.submit + if [ -d $H ] ; then + [ -d solutions/$user ] || mkdir -p solutions/$user + for t in $@ ; do + rm -rf solutions/$user/$t + if [ -d $H/$t ] ; then + echo -n " $t" + cp -dr $H/$t solutions/$user/$t + fi + done + echo + else + echo " ---" + fi +done +chown -R $EVAL_USER solutions +chmod -R a+r solutions diff --git a/mop/mo-grab-remote b/mop/mo-grab-remote new file mode 100755 index 0000000..6181b4e --- /dev/null +++ b/mop/mo-grab-remote @@ -0,0 +1,20 @@ +#!/bin/bash + +[ -n "$1" ] || { echo "Usage: mo-grab-remote " ; exit 1 ; } +[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } +set -e +. config + +for user in `bin/mo-get-users` ; do + echo -n "$user:" + mkdir -p solutions/$user + for t in $@ ; do + rm -rf solutions/$user/$t + D=$MO_ROOT/eval/submit/solutions/$user/$t + if [ -d $D ] ; then + echo -n " $t" + cp -a $D solutions/$user/$t + fi + done + echo +done diff --git a/mop/mo-install b/mop/mo-install new file mode 100755 index 0000000..f4456a9 --- /dev/null +++ b/mop/mo-install @@ -0,0 +1,38 @@ +#!/bin/bash + +[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } +set -e +. config + +H=`pwd` + +# The eval directory +cd $MO_ROOT +rm -rf eval +mkdir eval +chgrp $EVAL_GROUP eval +chmod 755 eval +cd eval + +# mo-eval home +( cd $H && bin/mo-create-eval ) + +# testusers +( cd eval && bin/mo-create-testusers ) + +# mo-submit home +if [ -n "$REMOTE_SUBMIT" ] ; then + mkdir submit + chmod 750 submit + if [ -d ~/.ssh ] ; then echo "Copying SSH configuration from ~/.ssh" ; cp -a ~/.ssh submit/ ; fi + ( cd $H && bin/mo-create-submit ) +fi + +# create public +cd $MO_ROOT +echo "Creating public" +rm -rf public +mkdir public + +# populate public +( cd eval/eval ; bin/mo-create-public ) diff --git a/mop/mo-merge-tests b/mop/mo-merge-tests new file mode 100755 index 0000000..03ef1ef --- /dev/null +++ b/mop/mo-merge-tests @@ -0,0 +1,36 @@ +#!/usr/bin/perl + +# This script recalculates points according to grouping of testcases. +# This is no longer necessary, because the score table and report generators +# already know how to handle merging of groups, but we still keep it as an example. + +@ARGV == 1 or die "Usage: mo-merge \n"; +my $task = $ARGV[0]; +foreach my $s (`ls -d testing/*/$task`) { + chomp $s; + if (! -s "$s/points.old") { + if (-s "$s/points") { + rename "$s/points", "$s/points.old" or die "Rename $s/points failed: $!"; + } else { + print "$s: NO POINTS?\n"; + next; + } + } + open X, "$s/points.old" or die; + my %tests = (); + my %cmts = (); + while () { + chomp; + my ($test, $subtest, $pts, $cmt) = /^(\d+)([a-z]*)\s+(\d+)\s*(.*)/ or die; + if (!exists($tests{$test}) || $tests{$test} > $pts) { + $tests{$test} = $pts; + $cmts{$test} = $cmt; + } + } + close X; + open X, ">$s/points" or die; + foreach my $test (sort { $a <=> $b } keys %tests) { + print X "$test $tests{$test} $cmts{$test}\n"; + } + close X; +} diff --git a/mop/mo-push-certs b/mop/mo-push-certs new file mode 100755 index 0000000..54b84ba --- /dev/null +++ b/mop/mo-push-certs @@ -0,0 +1,12 @@ +#!/bin/bash +[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; } +set -e +. config + +while IFS=" " read LOGIN FULL MACH ; do + if [ -z "$1" -o "$1" == "$LOGIN" ] ; then + echo "$LOGIN -> $MACH" + D=/mo/users/$LOGIN/$LOGIN/ + rsync -av $D/.mo root@$MACH:$D/ + fi $MACH" + D=/mo/users/$LOGIN/$LOGIN/ + rsync -av ~mo-eval/testing/$LOGIN root@$MACH:$D/results + ssh root@$MACH "cd $D && chown -R $LOGIN.$LOGIN results" + fi testing/$user/REPORT" or die; + print REP "Evaluation report for CEOI 2007 Day 2\n\n"; + my $total = 0; + foreach my $task (@ARGV) { + print REP "### Task $task ###\n\n"; + if (open PTS, "testing/$user/$task/points") { + my %merged_pts = (); + my %split_comm = (); + while () { + chomp; + my ($test, $pts, $comm) = /(\S+)\s+(\S+)\s+(.*)/; + my $merged = $test; + $merged =~ s/[^0-9]//; + if (!defined($merged_pts{$merged}) || $merged_pts{$merged} > $pts) { + $merged_pts{$merged} = $pts; + } + $split_comm{$merged}{$test} = $comm; + } + close PTS; + my $tt = 0; + foreach my $merged (sort { $a <=> $b } keys %merged_pts) { + printf REP "Test %2s: %2d points", $merged, $merged_pts{$merged}; + $tt += $merged_pts{$merged}; + my @k = sort keys %{$split_comm{$merged}}; + if (@k == 1) { + print REP " -- ", $split_comm{$merged}{$k[0]}, "\n"; + } else { + print REP " -- "; + my $cc = 0; + foreach my $t (@k) { + $cc++ and print REP ", "; + print REP "$t: $split_comm{$merged}{$t}"; + } + print REP "\n"; + } + } + print REP "\nTOTAL: $tt points\n\n"; + $total += $tt; + print " $tt"; + } else { + print REP "No solution submitted.\n\n"; + print " -"; + } + } + print REP "### TOTAL FOR DAY 2 ###\n\n"; + print REP "$total points\n"; + print REP "\n\n(generated on ", strftime("%Y-%m-%d %H:%M:%S", localtime), ")\n"; + close REP; + print " -> $total\n"; +} diff --git a/mop/mo-score b/mop/mo-score new file mode 100755 index 0000000..4dec3a1 --- /dev/null +++ b/mop/mo-score @@ -0,0 +1,285 @@ +#!/usr/bin/perl + +$debug = 0; +$detail = 0; +$html = 0; +$tex = 0; +$extras = 0; +$alt = 0; +$merged = 0; +$usage = "Usage: mo-score [--detail] [--alt] [--extras] [--html] [--tex] [--merged] [/] ..."; +while (($arg = $ARGV[0]) =~ /^--([a-z]+)$/) { + shift @ARGV; + $var = "\$$1"; + if (!eval "defined $var") { die $usage; } + eval "$var = 1;"; +} +@ARGV || die $usage; + +print STDERR "Scanning contestants... "; +open (CT, "bin/mo-get-users --full |") || die "Cannot get list of contestants"; +while () { + chomp; + ($u,$f) = split /\t/; + ($u eq "somebody") && next; + $users{$u}=$f; +} +close CT; +print STDERR 0+keys %users, "\n"; + +print STDERR "Scanning exceptions... "; +if ($extras && open (EX, "exceptions")) { + while () { + chomp; + (/^$/ || /^#/) && next; + @a = split /\s+/; + $u = shift @a; + defined $users{$u} || die "Unknown user $u"; + while (@a) { $extra{$u} += shift @a; } + } + close EX; + print STDERR "OK\n"; +} else { print STDERR "none\n"; } + +print STDERR "Scanning task results... "; +%messages = (); +%error_codes = (); +foreach $u (keys %users) { + foreach $task (@ARGV) { + my ($dir, $t) = ("testing", $task); + if ($task =~ m@^(.*)/([^/]*)$@) { + $dir = $1; + $t = $2; + } + $known_tasks{$t} = 1; + $tt = "$dir/$u/$t/points" . ($alt ? ".alt" : ""); + -f $tt || next; + print STDERR "$u/$t "; + open (X, $tt) || die "Unable to open $tt"; + while () { + chomp; + /^(\S+) (-?\d+)\s*(.*)/ || die "Parse error: $_"; + $ttest = $1; + $tpts = $2; + $trem = $3; + $trem =~ s/\[.*//; + ($ttest_merged = $ttest) =~ s/[^0-9]//g; + $ttest = $ttest_merged if $merged; + $known_tests{$t}{$ttest} = 1; + $cmt = $tpts; + if ($tpts == 0 && $trem ne "OK") { + if ($trem =~ /^Compile /) { $cmt = "CE"; } + elsif ($trem =~ /^Time limit exceeded/) { $cmt = "TO"; } + elsif ($trem =~ /^Exited with error /) { $cmt = "RE"; } + elsif ($trem =~ /^Caught fatal signal /) { $cmt = "SG"; } + elsif ($trem =~ /^([A-Za-z])\S*\s+([A-Za-z])/) { + ($cmt = "$1$2") =~ tr/a-z/A-Z/; + } + if (!defined $messages{$trem}) { + $messages{$trem} = $cmt; + if (!defined $error_codes{$cmt}) { + $error_codes{$cmt} = $trem; + } else { + $error_codes{$cmt} .= ", $trem"; + } + } + } + if (!defined($results{$u}{$t}{$ttest}) || $results{$u}{$t}{$ttest} > $tpts) { + $results{$u}{$t}{$ttest} = $tpts; + $comment{$u}{$t}{$ttest} = $cmt; + } + if (!defined($results_merged{$u}{$t}{$ttest_merged}) || $results_merged{$u}{$t}{$ttest_merged} > $tpts) { + $results_merged{$u}{$t}{$ttest_merged} = $tpts; + } + } + close X; + } + foreach my $t (keys %known_tasks) { + $total{$u}{$t} = 0; + foreach my $pts (values %{$results_merged{$u}{$t}}) { $total{$u}{$t} += $pts; } + } +} +print STDERR "OK\n"; + +print STDERR "Creating table template... "; +@header = ("Rank","User","Name"); +@body = ('','$u','$users{$u}'); +@bodysums = (); +@footer = ('"Total"','',''); +if (keys %extra) { + push @header, "Extra"; + push @body, '$extra{$u}'; + $col = 0+@footer; + push @bodysums, $col; + push @footer, "sum($col)"; +} +@tasks = (); +foreach $task (@ARGV) { + my $t = ($task =~ m@/([^/]*)$@) ? $1 : $task; + defined $known_tasks{$t} || die "Unknown task $t"; + push @tasks, $t; + push @header, substr($t, 0, 4); + push @body, "(\$xx = \$total{\$u}{'$t'}) > 0 ? \$xx : 0"; + $col = 0+@footer; + push @footer, "sum($col)"; + push @bodysums, $col; + if ($detail) { + foreach $s (sort { $a <=> $b } keys %{$known_tests{$t}}) { + push @header, "$s"; + push @body, "\$comment{\$u}{'$t'}{'$s'}"; + $col = 0+@footer; + push @footer, "sum($col)"; + } + } +} +push @header, "Total"; +push @body, join('+', map { $_ = "\$$_" } @bodysums); +$col = 0+@footer; +push @footer, "sum($col)"; +print STDERR "OK\n"; + +print STDERR "h: ", join(':',@header), "\n" if $debug; +print STDERR "b: ", join(':',@body), "\n" if $debug; +print STDERR "f: ", join(':',@footer), "\n" if $debug; + +print STDERR "Filling in results... "; +@table = (); +foreach $u (keys %users) { + $row = []; + foreach my $c (@body) { + $c =~ s/\$(\d+)/\$\$row[$1]/g; + $x = eval $c; + push @$row, (defined $x ? $x : '-'); + } + print STDERR "row: ", join(':',@$row), "\n" if $debug; + push @table, $row; +} +print STDERR "OK\n"; + +print STDERR "Sorting... "; +$sortcol = @{$table[0]} - 1; +$namecol = 2; +@table = sort { + my $p, $an, $bn; + $p = $$b[$sortcol] <=> $$a[$sortcol]; + ($an = $$a[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/; + ($bn = $$b[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/; + $p ? $p : ($an cmp $bn); +} @table; +$i=0; +while ($i < @table) { + $j = $i; + while ($i < @table && ${$table[$i]}[$sortcol] == ${$table[$j]}[$sortcol]) { + $i++; + } + if ($i == $j+1) { + ${table[$j]}[0] = "$i."; + } else { + ${table[$j]}[0] = $j+1 . ".-" . $i . "."; + $j++; + while ($j < $i) { ${table[$j++]}[0] = ""; }; + } +} +print STDERR "OK\n"; + +print STDERR "Attaching headers and footers... "; +sub sum { my $col=shift @_; my $t=0; foreach my $z (0..@table-1) { $t += ${$table[$z]}[$col]; } $t; } +map { $_ = eval $_; } @footer; +push @table, \@footer; +unshift @table, \@header; +print STDERR "OK\n"; + +if ($debug) { + foreach $r (@table) { print join(':',@$r), "\n"; } +} elsif ($html) { + print '', "\n"; + print "Rank list\n"; + print "

Rank list

\n"; + + my @perm; + &printHtmlHeader(\@perm); + print "
"; + + foreach $r (@table[1..($#table - 1)]) { + &printHtmlRow(@{$r}[@perm]); + } + + print ""; + &printHtmlRow(@{$table[$#table]}[@perm]); + + print "
\n"; + if ($detail) { + print "

Error codes

    \n"; + foreach $r (sort keys %error_codes) { print "
  • $r: $error_codes{$r}\n"; } + print "
\n"; + } + print "\n"; +} elsif ($tex) { + print "\\error{TeX output not supported yet!}\n"; +} else { + foreach $r (@table) { print join("\t",@$r), "\n"; } + print "\n"; + foreach $r (sort keys %error_codes) { print "$r: $error_codes{$r}\n"; } +} + + +sub printHtmlRow { + print "", join('',map { + if ($hdr) { $_ = "$_"; } + else { $_ = " 14 ? " width=150" : "") . ">$_"; } + } @_), "\n"; +} + + +sub printHtmlHeader { + + my ($perm) = @_; + + my $colspec = ""; + my $hdr1; + my $hdr2; + + @$perm = (0, 1, 2); + my $p = 3; + + if ($detail) { + $hdr1 = "RankUserName"; + $extras and $p++ and push @$perm, 3 and $hdr1.="Extra" and $colspec.=""; ##Extra hack + for my $task (@tasks) { + + my $nSub = scalar(keys %{$known_tests{$task}}); + + $p++; + map { push @$perm, $p++ } (1..$nSub); + push @$perm, $p - $nSub - 1; + + $colspec .= "\n"; + $colspec .= "\n"; + $hdr1 .= "$task"; + $hdr2 .= join("", map { "$_" } sort {$a <=> $b} keys %{$known_tests{$task}}); + $hdr2 .= "Total"; + } + + $hdr1 .= "Total"; + + } else { ## no detail + + $hdr1 = "RankUserName"; + $extras and $p++ and push @$perm, 3 and $hdr1.="Extra" and $colspec.=""; ##Extra hack + + for my $task (@tasks) { + push @$perm, $p++; + $hdr1 .= "$task"; + } + $hdr1 .= "Total"; + $colspec .= ""; + } + + push @$perm, $p++; + + print "\n"; + print "$colspec\n"; + print "$hdr1\n"; + print "$hdr2\n" if $detail; + +} diff --git a/mop/print-score b/mop/print-score new file mode 100755 index 0000000..292ca59 --- /dev/null +++ b/mop/print-score @@ -0,0 +1,5 @@ +#!/bin/sh +set -e +[ -n "$1" ] +sed <$1 's/^/ /' | a2ps -Ma4 -r --columns=1 --rows=1 --font-size=10 --borders=no -B -o /tmp/score.ps +print /tmp/score.ps