Move most problem parameters out of problem_meta
[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/:config require_order/;
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 $private = prompt 'Private?', '-yn';
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;
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';
41
42 my $timeout = prompt 'Time limit (seconds)', '-n';
43 my $olimit = prompt 'Output limit (bytes)', '-i';
44 say 'Memory limits are broken, so I won\'t ask you for one';
45
46 prompt_file \%meta, gen => '[Generator::Run] Generator' if $generator eq 'Run';
47
48 if ($runner eq 'File') {
49 $meta{tests}[$_ - 1] = prompt "[Runner::File] Score for test ${_} [10]", '-i', -default => 10 for 1 .. $testcnt;
50 }
51
52 prompt_file \%meta, ver => '[Runner::Verifier] Verifier' if $runner eq 'Verifier';
53
54 if ($runner eq 'Interactive') {
55 say RED, 'WARNING: Runner::Interactive is experimental', RESET;
56 prompt_file \%meta, int => '[Runner::Interactive] Interactive verifier';
57 }
58
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) : ());
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
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
114
115 =head1 DESCRIPTION
116
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.
161
162
163 =cut
This page took 0.033019 seconds and 4 git commands to generate.