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