use IO::Prompter [ -style => 'bold', '-stdio', '-verbatim' ];
use File::Slurp qw/read_file/;
+use JSON qw/encode_json/;
use Term::ANSIColor qw/RED RESET/;
use Getopt::Long qw/:config require_order/;
##################################################
-my $contest;
+my $db = Gruntmaster::Data->connect('dbi:Pg:');
sub cmd_help{
exec perldoc => $0
}
-sub prompt_file{
- my ($meta, $name, $prefix) = @_;
- my $filename = prompt '$prefix filename', -complete => 'filenames';
- $meta->{files}{$name}{content} = read_file $filename;
- $meta->{files}{$name}{format} = prompt '$prefix format', -menu => [qw/C CPP MONO JAVA PASCAL PERL PYTHON/];
- $meta->{files}{$name}{name} = prompt "$prefix filename [$filename]", -default => $filename;
-}
-
sub cmd_add{
my $id = shift;
my $name = prompt 'Problem name';
my $private = prompt('Private?', '-yn') eq 'y';
+ my $contest = prompt 'Contest';
my $author = prompt 'Problem author (full name)';
my $owner = prompt 'Problem owner (username)';
my $level = prompt 'Problem level', -menu => "beginner\neasy\nmedium\nhard";
my $statement = read_file prompt 'File with problem statement', -complete => 'filenames';
- my %meta;
my $generator = prompt 'Generator', -menu => "File\nRun\nUndef";
my $runner = prompt 'Runner', -menu => "File\nVerifier\nInteractive";
my $judge = prompt 'Judge', -menu => "Absolute\nPoints";
my $olimit = prompt 'Output limit (bytes)', '-i';
say 'Memory limits are broken, so I won\'t ask you for one';
- prompt_file \%meta, gen => '[Generator::Run] Generator' if $generator eq 'Run';
+ my (@tests, $gensource, $genformat, $versource, $verformat);
- if ($runner eq 'File') {
- $meta{tests}[$_ - 1] = prompt "[Runner::File] Score for test ${_} [10]", '-i', -default => 10 for 1 .. $testcnt;
+ if ($generator eq 'Run') {
+ $gensource = read_file prompt, '[Generator::Run] Generator file name', -complete => 'filenames';
+ $genformat = prompt '[Generator::Run] Generator format', -menu => [qw/C CPP MONO JAVA PASCAL PERL PYTHON/];
}
- prompt_file \%meta, ver => '[Runner::Verifier] Verifier' if $runner eq 'Verifier';
+ if ($runner eq 'File') {
+ my $default = $judge eq 'Points' ? 10 : 'Ok';
+ $tests[$_ - 1] = prompt "[Runner::File] Score for test ${_} [$default]", -default => $default for 1 .. $testcnt;
+ }
- if ($runner eq 'Interactive') {
- say RED, 'WARNING: Runner::Interactive is experimental', RESET;
- prompt_file \%meta, int => '[Runner::Interactive] Interactive verifier';
+ if ($runner eq 'Verifier' || $runner eq 'Interactive') {
+ say RED, 'WARNING: Runner::Interactive is experimental', RESET if $runner eq 'Interactive';
+ $versource = prompt "[Runner::$runner] Verifier file name", -complete => 'filenames';
+ $verformat = prompt "[Runner::$runner] Verifier format", -menu => [qw/C CPP MONO JAVA PASCAL PERL PYTHON/];
}
- insert_problem $id => (
+ $db->problems->create ({
+ id => $id,
name => $name,
level => $level,
statement => $statement,
runner => $runner,
judge => $judge,
testcnt => $testcnt,
- ($private ? (private => $private) : ()),
- (defined $timeout ? (timeout => $timeout) : ()),
- (defined $olimit ? (olimit => $olimit) : ()));
- set_problem_meta $id => \%meta;
- PUBLISH genpage => $contest ? "ct/$contest/pb/index.html" : 'pb/index.html';
- PUBLISH genpage => $contest ? "ct/$contest/pb/$id.html" : "pb/$id.html";
+ (private => $private)x!! $private,
+ (timeout => $timeout)x!! $timeout,
+ (olimit => $olimit)x!! $olimit,
+ (tests => encode_json \@tests)x!! @tests,
+ (gensource => $gensource)x!! $gensource,
+ (genformat => $genformat)x!! $genformat,
+ (versource => $versource)x!! $versource,
+ (verformat => $verformat)x!! $verformat,
+ });
+
+ $db->contest_problems->create({problem => $id, contest => $contest}) if $contest;
+ #PUBLISH genpage => $contest ? "ct/$contest/pb/index.html" : 'pb/index.html';
+ #PUBLISH genpage => $contest ? "ct/$contest/pb/$id.html" : "pb/$id.html";
}
sub cmd_set{
GetOptions ( 'file!' => \$file );
my ($id, %values) = @ARGV;
%values = map { $_ => scalar read_file $values{$_} } keys %values if $file;
- edit_problem $id => %values;
- PUBLISH genpage => 'pb/index.html';
- PUBLISH genpage => "pb/$id.html";
+ $db->problem($id)->update(\%values);
+ #PUBLISH genpage => 'pb/index.html';
+ #PUBLISH genpage => "pb/$id.html";
}
sub cmd_list{
local $, = "\n";
- say problems;
+ say map {$_->id} $db->problems->all;
}
sub cmd_rm{
- remove_problem shift;
- PUBLISH genpage => $contest ? "ct/$contest/pb/index.html" : 'pb/index.html';
+ $db->problem(shift)->delete;
+ #PUBLISH genpage => $contest ? "ct/$contest/pb/index.html" : 'pb/index.html';
}
sub cmd_show{
##################################################
-GetOptions ( 'contest=s' => \$contest );
-local $Gruntmaster::Data::contest = $contest;
my $cmd = 'cmd_' . shift;
cmd_help unless exists $main::{$cmd};
no strict 'refs';
-$cmd->(@ARGV) if exists $main::{$cmd};
+$cmd->(@ARGV);
1;
__END__