]> mj.ucw.cz Git - moe.git/blob - submit/remote-submit
Added command-line clients for remote submit and status.
[moe.git] / submit / remote-submit
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 BEGIN {
7         defined $ENV{"MO_ROOT"} or die "Please set MO_ROOT to the contest root directory first.\n";
8 }
9 use lib $ENV{"MO_ROOT"} . "/lib/perl5";
10 use lib ".";            ### FIXME
11
12 use MO::Submit;
13 use Sherlock::Object;
14 use File::stat;
15
16 @ARGV == 2 || @ARGV == 3 or die "Usage: remote-submit <task> [<part>] <filename>\n";
17 my $task = $ARGV[0];
18 my $part = $task;
19 if (@ARGV == 3) {
20         $part = $ARGV[1];
21         shift @ARGV;
22 }
23 my $file = $ARGV[1];
24 my ($ext) = ($file =~ /\.([^.]+)$/) or die "Unable to determine filename extension\n";
25
26 open F, $file or die "Unable to open $file: $!\n";
27 my $s = stat(*F) or die;
28 my $size = $s->size;
29
30 my $conn = new MO::Submit;
31 $conn->connect or die $conn->{"error"} . "\n";
32
33 sub or_die($) {
34         my $r = shift @_;
35         if (!defined $r) { die $conn->{"error"} . "\n"; }
36         my $err = $r->get("-");
37         if ($err) { die "$err\n"; }
38 }
39
40 my $r = new Sherlock::Object("!" => "SUBMIT", "T" => $task, "P" => $part, "X" => $ext, "S" => $size);
41 $r = $conn->request($r);
42 or_die($r);
43
44 $r = $conn->send_file(\*F, $size);
45 or_die($r);
46
47 print "Submitted OK.\n";
48
49 $conn->disconnect;
50 close F;