Commit | Line | Data |
---|---|---|
014ee8a6 MG |
1 | #!/usr/bin/perl -w |
2 | use v5.14; | |
3 | ||
4 | use Gruntmaster::Data; | |
5 | use Gruntmaster::Page::Submit; | |
6 | ||
7 | use IO::Prompter [ -style => 'bold', '-stdio', '-verbatim' ]; | |
8 | use File::Slurp qw/read_file/; | |
9 | use Term::ANSIColor qw/RED RESET/; | |
0d2f8987 | 10 | use Getopt::Long qw/:config require_order/; |
014ee8a6 MG |
11 | |
12 | ################################################## | |
13 | ||
14 | my $contest; | |
15 | ||
16 | sub cmd_help{ | |
17 | exec perldoc => $0 | |
18 | } | |
19 | ||
20 | sub prompt_file{ | |
21 | my ($meta, $name, $prefix) = @_; | |
22 | my $filename = prompt '$prefix filename', -complete => 'filenames'; | |
23 | $meta->{files}{$name}{content} = read_file $filename; | |
24 | $meta->{files}{$name}{format} = prompt '$prefix format', -menu => Gruntmaster::Page::Submit::FORMATS; | |
25 | $meta->{files}{$name}{name} = prompt "$prefix filename [$filename]", -default => $filename; | |
26 | } | |
27 | ||
28 | sub cmd_add{ | |
29 | my $id = shift; | |
30 | my $name = prompt 'Problem name'; | |
cd25d613 | 31 | my $private = prompt 'Private?', '-yn'; |
014ee8a6 MG |
32 | my $author = prompt 'Problem author (full name)'; |
33 | my $owner = prompt 'Problem owner (username)'; | |
34 | my $level = prompt 'Problem level', -menu => "beginner\neasy\nmedium\nhard"; | |
35 | my $statement = read_file prompt 'File with problem statement', -complete => 'filenames'; | |
36 | my %meta; | |
cd25d613 MG |
37 | my $generator = prompt 'Generator', -menu => "File\nRun\nUndef"; |
38 | my $runner = prompt 'Runner', -menu => "File\nVerifier\nInteractive"; | |
39 | my $judge = prompt 'Judge', -menu => "Absolute\nPoints"; | |
40 | my $testcnt = prompt 'Test count', '-i'; | |
014ee8a6 | 41 | |
cd25d613 MG |
42 | my $timeout = prompt 'Time limit (seconds)', '-n'; |
43 | my $olimit = prompt 'Output limit (bytes)', '-i'; | |
014ee8a6 MG |
44 | say 'Memory limits are broken, so I won\'t ask you for one'; |
45 | ||
cd25d613 | 46 | prompt_file \%meta, gen => '[Generator::Run] Generator' if $generator eq 'Run'; |
014ee8a6 | 47 | |
cd25d613 MG |
48 | if ($runner eq 'File') { |
49 | $meta{tests}[$_ - 1] = prompt "[Runner::File] Score for test ${_} [10]", '-i', -default => 10 for 1 .. $testcnt; | |
014ee8a6 MG |
50 | } |
51 | ||
cd25d613 | 52 | prompt_file \%meta, ver => '[Runner::Verifier] Verifier' if $runner eq 'Verifier'; |
014ee8a6 | 53 | |
cd25d613 | 54 | if ($runner eq 'Interactive') { |
014ee8a6 | 55 | say RED, 'WARNING: Runner::Interactive is experimental', RESET; |
cd25d613 | 56 | prompt_file \%meta, int => '[Runner::Interactive] Interactive verifier'; |
014ee8a6 MG |
57 | } |
58 | ||
cd25d613 | 59 | insert_problem $id => name => $name, level => $level, statement => $statement, author => $author, owner => $owner, private => $private, generator => $generator, runner => $runner, judge => $judge, testcnt => $testcnt, (defined $timeout ? (timeout => $timeout) : ()), (defined $olimit ? (olimit => $olimit) : ()); |
014ee8a6 MG |
60 | set_problem_meta $id => \%meta; |
61 | PUBLISH genpage => $contest ? "ct/$contest/pb/index.html" : 'pb/index.html'; | |
62 | PUBLISH genpage => $contest ? "ct/$contest/pb/$id.html" : "pb/$id.html"; | |
63 | } | |
64 | ||
65 | sub cmd_set{ | |
66 | my $file; | |
67 | GetOptions ( 'file!' => \$file ); | |
68 | my ($id, %values) = @ARGV; | |
69 | %values = map { $_ => scalar read_file $values{$_} } keys %values if $file; | |
70 | edit_problem $id => %values; | |
71 | PUBLISH genpage => 'pb/index.html'; | |
72 | PUBLISH genpage => "pb/$id.html"; | |
73 | } | |
74 | ||
75 | sub cmd_list{ | |
76 | local $, = "\n"; | |
77 | say problems; | |
78 | } | |
79 | ||
80 | sub cmd_rm{ | |
81 | remove_problem shift; | |
82 | PUBLISH genpage => $contest ? "ct/$contest/pb/index.html" : 'pb/index.html'; | |
83 | } | |
84 | ||
85 | sub cmd_show{ | |
86 | local $_ = shift or goto &cmd_list; | |
87 | } | |
88 | ||
89 | ################################################## | |
90 | ||
91 | GetOptions ( 'contest=s' => \$contest ); | |
92 | local $Gruntmaster::Data::contest = $contest; | |
93 | my $cmd = 'cmd_' . shift; | |
94 | cmd_help unless exists $main::{$cmd}; | |
95 | no strict 'refs'; | |
96 | $cmd->(@ARGV) if exists $main::{$cmd}; | |
97 | ||
98 | 1; | |
99 | __END__ | |
100 | ||
101 | =encoding utf-8 | |
102 | ||
103 | =head1 NAME | |
104 | ||
105 | gruntmaster-problem - shell interface to Gruntmaster 6000 problems | |
106 | ||
107 | =head1 SYNOPSIS | |
108 | ||
e90402be MG |
109 | gruntmaster-problem [--contest=mycontest] add problem_id |
110 | gruntmaster-problem [--contest=mycontest] list | |
111 | gruntmaster-problem [--contest=mycontest] rm problem_id | |
112 | gruntmaster-problem [--contest=mycontest] show problem_id | |
113 | gruntmaster-problem [--contest=mycontest] set [--file] problem_id key value | |
014ee8a6 MG |
114 | |
115 | =head1 DESCRIPTION | |
116 | ||
e90402be MG |
117 | gruntmaster-problem is a tool for managing problems. |
118 | ||
119 | Select the contest with the optional argument I<--contest>. | |
120 | ||
121 | =over | |
122 | ||
123 | =item B<list> | |
124 | ||
125 | Prints the list of problems in the selected contest. | |
126 | ||
127 | =item B<show> I<id> | |
128 | ||
129 | Prints detailed information about problem I<id>. | |
130 | ||
131 | =item B<add> I<id> | |
132 | ||
133 | Adds a new problem with id I<id>. | |
134 | ||
135 | =item B<rm> I<id> | |
136 | ||
137 | Removes the problem with id I<id>. | |
138 | ||
139 | =item B<set> I<id> I<key> I<value> | |
140 | ||
141 | Sets the I<key> configuration option of problem I<id> to I<value>. | |
142 | ||
143 | =item B<set> --file I<id> I<key> I<file> | |
144 | ||
145 | Sets the I<key> configuration option of problem I<id> to the contents of the file I<file>. | |
146 | ||
147 | =back | |
148 | ||
149 | =head1 AUTHOR | |
150 | ||
151 | Marius Gavrilescu E<lt>marius@ieval.roE<gt> | |
152 | ||
153 | =head1 COPYRIGHT AND LICENSE | |
154 | ||
155 | Copyright (C) 2014 by Marius Gavrilescu | |
156 | ||
157 | This library is free software: you can redistribute it and/or modify | |
158 | it under the terms of the GNU Affero General Public License as published by | |
159 | the Free Software Foundation, either version 3 of the License, or | |
160 | (at your option) any later version. | |
014ee8a6 MG |
161 | |
162 | ||
163 | =cut |