"Key" => "client-key.pem",
"Cert" => "client-cert.pem",
"CACert" => "ca-cert.pem",
+ "Trace" => 0,
"user" => "testuser",
"sk" => undef,
"error" => undef,
return bless $self;
}
+sub DESTROY($) {
+ my $self = shift @_;
+ $self->disconnect;
+}
+
sub log($$) {
my ($self, $msg) = @_;
- print STDERR "LOG: $msg\n";
+ print STDERR "LOG: $msg\n" if $self->{"Trace"};
}
sub err($$) {
my ($self, $msg) = @_;
- print STDERR "ERROR: $msg\n";
+ print STDERR "ERROR: $msg\n" if $self->{"Trace"};
$self->{"error"} = $msg;
+ $self->disconnect;
}
sub is_connected($) {
sub connect($) {
my $self = shift @_;
- !defined $self->{"sk"} or close $self->{"sk"};
+ $self->disconnect;
$self->log("Connecting to submit server");
my $sk = new IO::Socket::INET(
PeerAddr => $self->{"Server"},
my $err = $reply->get("-");
if (defined $err) {
$self->err("Cannot log in: $err");
- $self->disconnect;
return undef;
}
my ($self, $obj) = @_;
my $sk = $self->{"sk"};
$obj->write($sk); ### FIXME: Flushing
+ if ($sk->error) {
+ $self->err("Connection broken");
+ return undef;
+ }
print $sk "\n";
return $self->reply;
}
}
}
+sub send_file($$$) {
+ my ($self, $fh, $size) = @_;
+ my $sk = $self->{"sk"};
+ while ($size) {
+ my $l = ($size < 4096 ? $size : 4096);
+ my $buf = "";
+ if ($fh->read($buf, $l) != $l) {
+ $self->err("File shrunk during upload");
+ return undef;
+ }
+ $sk->write($buf, $l);
+ if ($sk->error) {
+ $self->err("Connection broken");
+ return undef;
+ }
+ $size -= $l;
+ }
+ return $self->reply;
+}
+
1;
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+BEGIN {
+ defined $ENV{"MO_ROOT"} or die "Please set MO_ROOT to the contest root directory first.\n";
+}
+use lib $ENV{"MO_ROOT"} . "/lib/perl5";
+use lib "."; ### FIXME
+
+use MO::Submit;
+use Sherlock::Object;
+use POSIX;
+
+@ARGV == 0 or die "Usage: remote-status\n";
+
+my $conn = new MO::Submit;
+$conn->connect or die $conn->{"error"} . "\n";
+
+sub or_die($) {
+ my $r = shift @_;
+ if (!defined $r) { die $conn->{"error"} . "\n"; }
+ my $err = $r->get("-");
+ if ($err) { die "$err\n"; }
+}
+
+my $r = new Sherlock::Object("!" => "STATUS");
+$r = $conn->request($r);
+or_die($r);
+#$r->write_indented(*STDOUT);
+
+my %tasks = map { $_->get("T") => $_ } $r->getarray("(T");
+foreach my $task (sort keys %tasks) {
+ my $t = $tasks{$task};
+ my %parts = map { $_->get("P") => $_ } $t->getarray("(P");
+ my @pp = keys %parts;
+ if (@pp != 1) {
+ @pp = sort { $a <=> $b } @pp; # We expect that the parts are numeric
+ }
+ foreach my $part (@pp) {
+ my $p = $parts{$part};
+ my $name = $task;
+ $part eq $task or $name .= "/$part";
+ printf "%-16s", $name;
+
+ my $current_ver = $p->get("V");
+ my $printed = 0;
+ foreach my $v ($p->getarray("(V")) {
+ if ($v && $v->get("V") == $current_ver) {
+ my $time = strftime("%H:%M:%S", localtime $v->get("T"));
+ print "OK (",
+ "$part.", $v->get("X"), ", ",
+ $v->get("L"), " bytes, ",
+ $v->get("S"), " $time)\n";
+ $printed = 1;
+ }
+ }
+ $printed or print "---\n";
+ }
+}
+
+$conn->disconnect;
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+BEGIN {
+ defined $ENV{"MO_ROOT"} or die "Please set MO_ROOT to the contest root directory first.\n";
+}
+use lib $ENV{"MO_ROOT"} . "/lib/perl5";
+use lib "."; ### FIXME
+
+use MO::Submit;
+use Sherlock::Object;
+use File::stat;
+
+@ARGV == 2 || @ARGV == 3 or die "Usage: remote-submit <task> [<part>] <filename>\n";
+my $task = $ARGV[0];
+my $part = $task;
+if (@ARGV == 3) {
+ $part = $ARGV[1];
+ shift @ARGV;
+}
+my $file = $ARGV[1];
+my ($ext) = ($file =~ /\.([^.]+)$/) or die "Unable to determine filename extension\n";
+
+open F, $file or die "Unable to open $file: $!\n";
+my $s = stat(*F) or die;
+my $size = $s->size;
+
+my $conn = new MO::Submit;
+$conn->connect or die $conn->{"error"} . "\n";
+
+sub or_die($) {
+ my $r = shift @_;
+ if (!defined $r) { die $conn->{"error"} . "\n"; }
+ my $err = $r->get("-");
+ if ($err) { die "$err\n"; }
+}
+
+my $r = new Sherlock::Object("!" => "SUBMIT", "T" => $task, "P" => $part, "X" => $ext, "S" => $size);
+$r = $conn->request($r);
+or_die($r);
+
+$r = $conn->send_file(\*F, $size);
+or_die($r);
+
+print "Submitted OK.\n";
+
+$conn->disconnect;
+close F;