Add lastjob
[gruntmaster-data.git] / gruntmaster-problem
CommitLineData
014ee8a6
MG
1#!/usr/bin/perl -w
2use v5.14;
3
4use Gruntmaster::Data;
5use Gruntmaster::Page::Submit;
6
7use IO::Prompter [ -style => 'bold', '-stdio', '-verbatim' ];
8use File::Slurp qw/read_file/;
9use Term::ANSIColor qw/RED RESET/;
0d2f8987 10use Getopt::Long qw/:config require_order/;
014ee8a6
MG
11
12##################################################
13
14my $contest;
15
16sub cmd_help{
17 exec perldoc => $0
18}
19
20sub 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
28sub cmd_add{
29 my $id = shift;
30 my $name = prompt 'Problem name';
646feed4 31 my $private = prompt('Private?', '-yn') eq 'y';
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
646feed4
MG
59 insert_problem $id => (
60 name => $name,
61 level => $level,
62 statement => $statement,
63 author => $author,
64 owner => $owner,
65 generator => $generator,
66 runner => $runner,
67 judge => $judge,
68 testcnt => $testcnt,
69 ($private ? (private => $private) : ()),
70 (defined $timeout ? (timeout => $timeout) : ()),
71 (defined $olimit ? (olimit => $olimit) : ()));
014ee8a6
MG
72 set_problem_meta $id => \%meta;
73 PUBLISH genpage => $contest ? "ct/$contest/pb/index.html" : 'pb/index.html';
74 PUBLISH genpage => $contest ? "ct/$contest/pb/$id.html" : "pb/$id.html";
75}
76
77sub cmd_set{
78 my $file;
79 GetOptions ( 'file!' => \$file );
80 my ($id, %values) = @ARGV;
81 %values = map { $_ => scalar read_file $values{$_} } keys %values if $file;
82 edit_problem $id => %values;
83 PUBLISH genpage => 'pb/index.html';
84 PUBLISH genpage => "pb/$id.html";
85}
86
87sub cmd_list{
88 local $, = "\n";
89 say problems;
90}
91
92sub cmd_rm{
93 remove_problem shift;
94 PUBLISH genpage => $contest ? "ct/$contest/pb/index.html" : 'pb/index.html';
95}
96
97sub cmd_show{
98 local $_ = shift or goto &cmd_list;
99}
100
101##################################################
102
103GetOptions ( 'contest=s' => \$contest );
104local $Gruntmaster::Data::contest = $contest;
105my $cmd = 'cmd_' . shift;
106cmd_help unless exists $main::{$cmd};
107no strict 'refs';
108$cmd->(@ARGV) if exists $main::{$cmd};
109
1101;
111__END__
112
113=encoding utf-8
114
115=head1 NAME
116
117gruntmaster-problem - shell interface to Gruntmaster 6000 problems
118
119=head1 SYNOPSIS
120
e90402be
MG
121 gruntmaster-problem [--contest=mycontest] add problem_id
122 gruntmaster-problem [--contest=mycontest] list
123 gruntmaster-problem [--contest=mycontest] rm problem_id
124 gruntmaster-problem [--contest=mycontest] show problem_id
125 gruntmaster-problem [--contest=mycontest] set [--file] problem_id key value
014ee8a6
MG
126
127=head1 DESCRIPTION
128
e90402be
MG
129gruntmaster-problem is a tool for managing problems.
130
131Select the contest with the optional argument I<--contest>.
132
133=over
134
135=item B<list>
136
137Prints the list of problems in the selected contest.
138
139=item B<show> I<id>
140
141Prints detailed information about problem I<id>.
142
143=item B<add> I<id>
144
145Adds a new problem with id I<id>.
146
147=item B<rm> I<id>
148
149Removes the problem with id I<id>.
150
151=item B<set> I<id> I<key> I<value>
152
153Sets the I<key> configuration option of problem I<id> to I<value>.
154
155=item B<set> --file I<id> I<key> I<file>
156
157Sets the I<key> configuration option of problem I<id> to the contents of the file I<file>.
158
159=back
160
161=head1 AUTHOR
162
163Marius Gavrilescu E<lt>marius@ieval.roE<gt>
164
165=head1 COPYRIGHT AND LICENSE
166
167Copyright (C) 2014 by Marius Gavrilescu
168
169This library is free software: you can redistribute it and/or modify
170it under the terms of the GNU Affero General Public License as published by
171the Free Software Foundation, either version 3 of the License, or
172(at your option) any later version.
014ee8a6
MG
173
174
175=cut
This page took 0.021004 seconds and 4 git commands to generate.