]>
iEval git - gruntmaster-data.git/blob - gruntmaster-problem
6 use File
::Temp qw
/tempfile/;
8 use IO
::Prompter
[ -style
=> 'bold', '-stdio', '-verbatim' ];
9 use File
::Slurp qw
/read_file write_file/;
10 use JSON qw
/encode_json/;
11 use Term
::ANSIColor qw
/RED RESET/;
12 use Getopt
::Long qw
/:config require_order/;
14 use constant LEVEL_VALUES
=> {
21 ##################################################
23 my $dsn = $ENV{GRUNTMASTER_DSN
} // 'dbi:Pg:';
24 my $db = Gruntmaster
::Data
->connect($dsn);
32 my $name = prompt
'Problem name';
33 my $private = prompt
('Private?', '-yn') eq 'y';
34 my $contest = prompt
'Contest';
35 my $author = prompt
'Problem author (full name)';
36 my $writer = prompt
'Problem statement writer (full name)';
37 my $owner = prompt
'Problem owner (username)';
38 my $level = prompt
'Problem level', -menu
=> "beginner\neasy\nmedium\nhard";
39 my $value = LEVEL_VALUES
->{$level};
40 my $statement = read_file prompt
'File with problem statement', -complete
=> 'filenames';
41 my $generator = prompt
'Generator', -menu
=> "File\nRun\nUndef";
42 my $runner = prompt
'Runner', -menu
=> "File\nVerifier\nInteractive";
43 my $judge = prompt
'Judge', -menu
=> "Absolute\nPoints";
44 my $testcnt = prompt
'Test count', '-i';
46 my $timeout = prompt
'Time limit (seconds)', '-n';
47 my $olimit = prompt
'Output limit (bytes)', '-i';
48 say 'Memory limits are broken, so I won\'t ask you for one';
50 my (@tests, $gensource, $genformat, $versource, $verformat);
52 if ($generator eq 'Run') {
53 $gensource = read_file prompt
, '[Generator::Run] Generator file name', -complete
=> 'filenames';
54 $genformat = prompt
'[Generator::Run] Generator format', -menu
=> [qw
/C CPP MONO JAVA PASCAL PERL PYTHON/];
57 if ($runner eq 'File') {
58 my $default = $judge eq 'Points' ?
10 : 'Ok';
59 $tests[$_ - 1] = prompt
"[Runner::File] Score for test ${_} [$default]", -default => $default for 1 .. $testcnt;
62 if ($runner eq 'Verifier' || $runner eq 'Interactive') {
63 say RED
, 'WARNING: Runner::Interactive is experimental', RESET
if $runner eq 'Interactive';
64 $versource = prompt
"[Runner::$runner] Verifier file name", -complete
=> 'filenames';
65 $verformat = prompt
"[Runner::$runner] Verifier format", -menu
=> [qw
/C CPP MONO JAVA PASCAL PERL PYTHON/];
73 statement
=> $statement,
77 generator
=> $generator,
82 $options{private
} = $private if $private;
83 $options{timeout
} = $timeout if $timeout;
84 $options{olimit
} = $olimit if $olimit;
85 $options{tests
} = encode_json \
@tests if @tests;
86 $options{gensource
} = $gensource if $gensource;
87 $options{genformat
} = $genformat if $genformat;
88 $options{versource
} = $versource if $versource;
89 $options{verformat
} = $verformat if $verformat;
90 $db->problems->create (\
%options);
92 $db->contest_problems->create({problem
=> $id, contest
=> $contest}) if $contest;
97 GetOptions
( 'file!' => \
$file );
98 my ($id, %values) = @ARGV;
99 %values = map { $_ => scalar read_file
$values{$_} } keys %values if $file;
100 $db->problem($id)->update(\
%values);
105 say $db->problem($id)->get_column($col)
110 my ($fh, $file) = tempfile
'gruntmaster-problem-editXXXX', TMPDIR
=> 1, UNLINK
=> 1;
111 write_file
$fh, $db->problem($id)->get_column($col);
113 my $editor = $ENV{EDITOR
} // 'editor';
114 system $editor, $file;
115 $db->problem($id)->update({$col => scalar read_file
$file}) or die "$!";
120 say map {$_->id} $db->problems->all
125 $db->problem($id)->delete;
129 my %columns = $db->problem(shift)->get_columns;
132 Author: $columns{author}
133 Statement written by: $columns{writer}
134 Owner: $columns{owner}
135 Level: $columns{level}
136 Output limit: $columns{olimit}
137 Time limit: $columns{timeout}
138 Test count: $columns{testcnt}
139 Generator: $columns{generator}
140 Runner: $columns{runner}
141 Judge: $columns{judge}
142 Private: $columns{private}
146 ##################################################
148 my $cmd = 'cmd_' . shift;
149 cmd_help
unless exists $main::{$cmd};
160 gruntmaster-problem - shell interface to Gruntmaster 6000 problems
164 gruntmaster-problem add problem_id
165 gruntmaster-problem list
166 gruntmaster-problem rm problem_id
167 gruntmaster-problem show problem_id
168 gruntmaster-problem set [--file] problem_id key value
169 gruntmaster-problem get problem_id key
170 gruntmaster-problem edit problem_id key
174 gruntmaster-problem is a tool for managing problems.
180 Prints the list of problems in the selected contest.
184 Prints detailed information about problem I<id>.
188 Adds a new problem with id I<id>.
192 Removes the problem with id I<id>.
194 =item B<set> I<id> I<key> I<value>
196 Sets the I<key> configuration option of problem I<id> to I<value>.
198 =item B<get> I<id> I<key>
200 Get the value of the I<key> configuration option of problem I<id>
202 =item B<edit> I<id> I<key>
204 Opens an editor with the value of the I<key> configuration option. After the editor exits, the option is updated to the value of the file.
206 =item B<set> --file I<id> I<key> I<file>
208 Sets the I<key> configuration option of problem I<id> to the contents of the file I<file>.
214 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
216 =head1 COPYRIGHT AND LICENSE
218 Copyright (C) 2014 by Marius Gavrilescu
220 This library is free software; you can redistribute it and/or modify
221 it under the same terms as Perl itself, either Perl version 5.18.1 or,
222 at your option, any later version of Perl 5 you may have available.
This page took 0.060188 seconds and 4 git commands to generate.