From: Marius Gavrilescu Date: Tue, 14 Jan 2014 09:16:56 +0000 (+0200) Subject: Add gruntmaster-problem X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=4f3ef2475e29f4dd17f10ce8af5c4e989dac64e8;p=gruntmaster-page.git Add gruntmaster-problem --- diff --git a/gruntmaster-problem b/gruntmaster-problem new file mode 100755 index 0000000..32e8e2b --- /dev/null +++ b/gruntmaster-problem @@ -0,0 +1,104 @@ +#!/usr/bin/perl -w +use v5.14; + +use Gruntmaster::Data qw/insert_problem remove_problem set_problem_meta problems/; + +use IO::Prompter [ -style => 'bold', '-stdio', '-verbatim' ]; +use File::Slurp qw/read_file/; +use Term::ANSIColor qw/RED RESET/; + +################################################## + +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 => [keys Gruntmaster::Page::Log::FORMAT_EXTENSION()]; + $meta->{files}{$name}{name} = prompt "$prefix filename [$filename]", -default => $filename; + +} + +sub cmd_add{ + my $id = shift; + my $contest = prompt 'Contest'; + local $Gruntmaster::Data::contest = $contest if $contest; + my $name = prompt 'Problem name'; + my $level = prompt 'Problem level'; + my $statement = read_file prompt 'File with problem statement', -complete => 'filenames'; + my %meta; + $meta{generator} = prompt 'Generator', -menu => "File\nRun\nUndef"; + $meta{runner} = prompt 'Runner', -menu => "File\nVerifier\nInteractive"; + $meta{judge} = prompt 'Judge', -menu => "Absolute\nPoints"; + $meta{testcnt} = prompt 'Test count', '-i'; + + if ($meta{generator} eq 'File') { + my $prefix = prompt '[Generator::File] Input file prefix'; + $meta{infile}[$_ - 1] = read_file "$prefix$_.in" for 1 .. $meta{testcnt}; + } + + prompt_file \%meta, gen => '[Generator::Run] Generator' if $meta{generator} eq 'Run'; + + if ($meta{runner} eq 'File') { + my $prefix = prompt '[Runner::File] Output file prefix'; + $meta{okfile}[$_ - 1] = read_file "$prefix$_.ok" for 1 .. $meta{testcnt}; + $meta{tests}[$_ - 1] = prompt "[Runner::File] Score for test ${_} [10]", '-i', -default => 10 for 1 .. $meta{testcnt}; + } + + prompt_file \%meta, ver => '[Runner::Verifier] Verifier' if $meta{runner} eq 'Verifier'; + + if ($meta{runner} eq 'Interactive') { + say RED, 'WARNING: Runner::Interactive is experimental', RESET; + prompt_file int => '[Runner::Interactive] Interactive verifier'; + } + + insert_problem $id => name => $name, level => $level, statement => $statement; + set_problem_meta $id => \%meta; +} + +sub cmd_list{ + my $contest = shift; + local $Gruntmaster::Data::contest = $contest if $contest; + print problems; +} + +sub cmd_rm{ + remove_problem shift +} + +sub cmd_show{ + local $_ = shift or goto &cmd_list; +} + +################################################## + +no strict 'refs'; +my $cmd = 'cmd_' . shift; +cmd_help unless exists $main::{$cmd}; +$cmd->(@ARGV) if exists $main::{$cmd}; + +1; +__END__ + +=encoding utf-8 + +=head1 NAME + +gruntmaster-problem - shell interface to Gruntmaster 6000 problems + +=head1 SYNOPSIS + + gruntmaster-problem add problem_id + gruntmaster-problem list + gruntmaster-problem rm problem_id + gruntmaster-problem show problem_id + + +=head1 DESCRIPTION + + + +=cut