#!/usr/bin/perl -w use v5.14; use Gruntmaster::Data; use IO::Prompter [ -style => 'bold', '-stdio', '-verbatim' ]; use File::Slurp qw/read_file/; use JSON qw/encode_json/; use Term::ANSIColor qw/RED RESET/; use Getopt::Long qw/:config require_order/; ################################################## my $db = Gruntmaster::Data->connect('dbi:Pg:'); sub cmd_help{ exec perldoc => $0 } sub cmd_add{ my $id = shift; my $name = prompt 'Problem name'; my $private = prompt('Private?', '-yn') eq 'y'; my $contest = prompt 'Contest'; my $author = prompt 'Problem author (full name)'; my $owner = prompt 'Problem owner (username)'; my $level = prompt 'Problem level', -menu => "beginner\neasy\nmedium\nhard"; my $statement = read_file prompt 'File with problem statement', -complete => 'filenames'; my $generator = prompt 'Generator', -menu => "File\nRun\nUndef"; my $runner = prompt 'Runner', -menu => "File\nVerifier\nInteractive"; my $judge = prompt 'Judge', -menu => "Absolute\nPoints"; my $testcnt = prompt 'Test count', '-i'; my $timeout = prompt 'Time limit (seconds)', '-n'; my $olimit = prompt 'Output limit (bytes)', '-i'; say 'Memory limits are broken, so I won\'t ask you for one'; my (@tests, $gensource, $genformat, $versource, $verformat); if ($generator eq 'Run') { $gensource = read_file prompt, '[Generator::Run] Generator file name', -complete => 'filenames'; $genformat = prompt '[Generator::Run] Generator format', -menu => [qw/C CPP MONO JAVA PASCAL PERL PYTHON/]; } if ($runner eq 'File') { my $default = $judge eq 'Points' ? 10 : 'Ok'; $tests[$_ - 1] = prompt "[Runner::File] Score for test ${_} [$default]", -default => $default for 1 .. $testcnt; } if ($runner eq 'Verifier' || $runner eq 'Interactive') { say RED, 'WARNING: Runner::Interactive is experimental', RESET if $runner eq 'Interactive'; $versource = prompt "[Runner::$runner] Verifier file name", -complete => 'filenames'; $verformat = prompt "[Runner::$runner] Verifier format", -menu => [qw/C CPP MONO JAVA PASCAL PERL PYTHON/]; } $db->problems->create ({ id => $id, name => $name, level => $level, statement => $statement, author => $author, owner => $owner, generator => $generator, runner => $runner, judge => $judge, testcnt => $testcnt, (private => $private)x!! $private, (timeout => $timeout)x!! $timeout, (olimit => $olimit)x!! $olimit, (tests => encode_json \@tests)x!! @tests, (gensource => $gensource)x!! $gensource, (genformat => $genformat)x!! $genformat, (versource => $versource)x!! $versource, (verformat => $verformat)x!! $verformat, }); $db->contest_problems->create({problem => $id, contest => $contest}) if $contest; #PUBLISH genpage => $contest ? "ct/$contest/pb/index.html" : 'pb/index.html'; #PUBLISH genpage => $contest ? "ct/$contest/pb/$id.html" : "pb/$id.html"; } sub cmd_set{ my $file; GetOptions ( 'file!' => \$file ); my ($id, %values) = @ARGV; %values = map { $_ => scalar read_file $values{$_} } keys %values if $file; $db->problem($id)->update(\%values); #PUBLISH genpage => 'pb/index.html'; #PUBLISH genpage => "pb/$id.html"; } sub cmd_get{ my ($id, $col) = @ARGV; say $db->problem($id)->get_column($col) } sub cmd_list{ local $, = "\n"; say map {$_->id} $db->problems->all; } sub cmd_rm{ $db->problem(shift)->delete; #PUBLISH genpage => $contest ? "ct/$contest/pb/index.html" : 'pb/index.html'; } sub cmd_show{ local $_ = shift or goto &cmd_list; } ################################################## my $cmd = 'cmd_' . shift; cmd_help unless exists $main::{$cmd}; no strict 'refs'; $cmd->(@ARGV); 1; __END__ =encoding utf-8 =head1 NAME gruntmaster-problem - shell interface to Gruntmaster 6000 problems =head1 SYNOPSIS gruntmaster-problem add problem_id gruntmaster-problem list gruntmaster-problem rm problem_id gruntmaster-problem show problem_id gruntmaster-problem set [--file] problem_id key value gruntmaster-problem get problem_id key =head1 DESCRIPTION gruntmaster-problem is a tool for managing problems. Select the contest with the optional argument I<--contest>. =over =item B Prints the list of problems in the selected contest. =item B I Prints detailed information about problem I. =item B I Adds a new problem with id I. =item B I Removes the problem with id I. =item B I I I Sets the I configuration option of problem I to I. =item B I I Get the value of the I configuration option of problem I =item B --file I I I Sets the I configuration option of problem I to the contents of the file I. =back =head1 AUTHOR Marius Gavrilescu Emarius@ieval.roE =head1 COPYRIGHT AND LICENSE Copyright (C) 2014 by Marius Gavrilescu This library is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. =cut