Improve gruntmaster tools
authorMarius Gavrilescu <marius@ieval.ro>
Thu, 15 May 2014 09:07:42 +0000 (12:07 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Thu, 15 May 2014 09:07:42 +0000 (12:07 +0300)
gruntmaster-contest
gruntmaster-job
gruntmaster-problem

index 23fd515e84ef1c7af73bc44d4a819e2e51bc4db2..ff121cddaefed32dad808978b4920a381627a33c 100755 (executable)
@@ -17,15 +17,18 @@ sub cmd_help{
 
 sub cmd_list{
        local $, = "\n";
-       say contests;
+       say map { $_->id } $db->contests->all;
 }
 
 sub cmd_show{
-#      local $_ = shift or goto &cmd_list;
-#      say "Name: ", contest_name;
-#      say "Owner: ", contest_owner;
-#      say "Start: ", strftime '%c', localtime contest_start;
-#      say "End: ", strftime '%c', localtime contest_end;
+       my %columns = $db->contest(shift)->get_columns;
+       $columns{$_} = strftime '%c', localtime $columns{$_} for qw/start stop/;
+       print <<END
+Name: $columns{name}
+Owner: $columns{owner}
+Start: $columns{start}
+Stop: $columns{stop}
+END
 }
 
 sub cmd_add{
@@ -35,15 +38,21 @@ sub cmd_add{
        my $start = str2time prompt 'Start time' or die 'Cannot parse time';
        my $stop = str2time prompt 'Stop time' or die 'Cannot parse time';
 
-       $db->contests->create({id => $id, name => $name, owner => $owner, start => $start, stop => $stop});
-#      insert_contest $id => name => $name, owner => $owner, start => $start, stop => $stop;
-#      PUBLISH genpage => "ct/$id/index.html";
-#      PUBLISH genpage => "ct/index.html";
+       $db->contests->create({id => $id, name => $name, owner => $owner, start => $start, stop => $stop})
 }
 
 sub cmd_rm{
-#      remove_contest shift;
-#      PUBLISH genpage => "ct/index.html";
+       $db->contest(shift)->delete
+}
+
+sub cmd_get{
+       my ($id, $col) = @_;
+       say $db->contest($id)->get_column($col)
+}
+
+sub cmd_set{
+       my ($id, %values) = @_;
+       $db->contest($id)->update(\%values)
 }
 
 ##################################################
@@ -68,6 +77,8 @@ gruntmaster-contest - shell interface to Gruntmaster 6000 contests
   gruntmaster-contest show id
   gruntmaster-contest add id
   gruntmaster-contest rm id
+  gruntmaster-contest get id key
+  gruntmaster-contest set id key value
 
 =head1 DESCRIPTION
 
@@ -89,7 +100,15 @@ Adds a new contest with id I<id>.
 
 =item B<rm> I<id>
 
-Removes the contest with id I<id>
+Removes the contest with id I<id>.
+
+=item B<set> I<id> I<key> I<value>
+
+Sets the I<key> configuration option of contest I<id> to I<value>.
+
+=item B<get> I<id> I<key>
+
+Get the value of the I<key> configuration option of contest I<id>.
 
 =back
 
@@ -101,10 +120,9 @@ Marius Gavrilescu E<lt>marius@ieval.roE<gt>
 
 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.
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself, either Perl version 5.18.1 or,
+at your option, any later version of Perl 5 you may have available.
 
 
 =cut
index 23e9cd2870ea57553a103d4eada12462010a7687..126e1d0dea36772fb0d168410f43f36310cc1197 100755 (executable)
@@ -4,47 +4,52 @@ use v5.14;
 use Gruntmaster::Data;
 
 use IO::Prompter [ -style => 'bold', '-stdio', '-verbatim' ];
-use File::Slurp qw/read_file/;
-use Getopt::Long;
-use Term::ANSIColor qw/RED RESET/;
 use POSIX qw/strftime/;
 
 ##################################################
 
-my $contest;
+my $db = Gruntmaster::Data->connect('dbi:Pg:');
 
 sub cmd_help{
        exec perldoc => $0
 }
 
-sub cmd_card{
-       say jobcard;
+sub cmd_show{
+       my %columns = $db->job(shift)->get_columns;
+       $columns{date} = strftime '%c', localtime $columns{date};
+       $columns{private} = $columns{private} ? 'yes' : 'no';
+
+       print <<END
+Date: $columns{date}
+Owner: $columns{owner}
+Problem: $columns{problem}
+Format: $columns{format}
+Daemon: $columns{daemon}
+Result text: $columns{result_text}
+Private: $columns{private}
+END
 }
 
-sub cmd_show{
-       local $_ = shift or goto &cmd_list;
-       say "Date: " , strftime ('%c', localtime job_date);
-       say "User: ", job_user;
-       say "Problem: ", problem_name job_problem;
-       say "Extension: ", job_extension;
-       say "Size: ", sprintf "%.2fKB", job_filesize() / 1024;
-       say "Private: ", (job_private() ? 'yes' : 'no');
-       say "Result text: ", job_result_text;
-       say "Daemon: ", job_daemon;
-       say "Compile errors: ", job_errors;
+sub cmd_rm{
+       $db->job(shift)->delete
+}
+
+sub cmd_get{
+       my ($id, $col) = @_;
+       say $db->job($id)->get_column($col)
+}
+
+sub cmd_set{
+       my ($id, %values) = @_;
+       $db->job($id)->update(\%values)
 }
 
 sub cmd_rerun{
-       local $_ = shift or goto &cmd_list;
-       clean_job;
-       $contest//='';
-       PUBLISH jobs => "$contest.$_";
+       $db->job(shift)->rerun
 }
 
 ##################################################
 
-GetOptions ( 'contest=s' => \$contest );
-local $Gruntmaster::Data::contest = $contest;
 my $cmd = 'cmd_' . shift;
 cmd_help unless exists $main::{$cmd};
 no strict 'refs';
@@ -61,26 +66,34 @@ gruntmaster-job - shell interface to Gruntmaster 6000 job log
 
 =head1 SYNOPSIS
 
-  gruntmaster-job [--contest=mycontest] card
-  gruntmaster-job [--contest=mycontest] show 5
-  gruntmaster-job [--contest=mycontest] rerun 7
+  gruntmaster-job show id
+  gruntmaster-job rm id
+  gruntmaster-job get id key
+  gruntmaster-job set id key value
+  gruntmaster-job rerun id
 
 =head1 DESCRIPTION
 
 gruntmaster-job is a tool for managing jobs.
 
-Select the contest with the optional argument I<--contest>.
-
 =over
 
-=item B<card>
-
-Prints the number of jobs in the selected contest.
-
 =item B<show> I<id>
 
 Prints detailed information about the job with id I<id>.
 
+=item B<rm> I<id>
+
+Removes the job with id I<id>.
+
+=item B<set> I<id> I<key> I<value>
+
+Sets the I<key> configuration option of job I<id> to I<value>.
+
+=item B<get> I<id> I<key>
+
+Get the value of the I<key> configuration option of job I<id>.
+
 =item B<rerun> I<id>
 
 Reruns job I<id>.
@@ -95,10 +108,9 @@ Marius Gavrilescu E<lt>marius@ieval.roE<gt>
 
 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.
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself, either Perl version 5.18.1 or,
+at your option, any later version of Perl 5 you may have available.
 
 
 =cut
index 1b240e0c4b3772973ac5d53f66d140b4bf961acd..afcb1be7135e065fdc342d694a0297bd328f0f11 100755 (executable)
@@ -53,7 +53,7 @@ sub cmd_add{
                $verformat = prompt "[Runner::$runner] Verifier format", -menu => [qw/C CPP MONO JAVA PASCAL PERL PYTHON/];
        }
 
-       $db->problems->create ({
+       my %options = (
                id => $id,
                name => $name,
                level => $level,
@@ -64,48 +64,58 @@ sub cmd_add{
                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,
-       });
+       );
+       $options{private} = $private if $private;
+       $options{timeout} = $timeout if $timeout;
+       $options{olimit} = $olimit if $olimit;
+       $options{tests} = encode_json \@tests if @tests;
+       $options{gensource} = $gensource if $gensource;
+       $options{genformat} = $genformat if $genformat;
+       $options{versource} = $versource if $versource;
+       $options{verformat} = $verformat if $verformat;
+       $db->problems->create (\%options);
 
        $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;
+       my ($id, %values) = @_;
        %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";
+       $db->problem($id)->update(\%values)
 }
 
 sub cmd_get{
-       my ($id, $col) = @ARGV;
+       my ($id, $col) = @_;
        say $db->problem($id)->get_column($col)
 }
 
 sub cmd_list{
        local $, = "\n";
-       say map {$_->id} $db->problems->all;
+       say map {$_->id} $db->problems->all
 }
 
 sub cmd_rm{
-       $db->problem(shift)->delete;
-       #PUBLISH genpage => $contest ? "ct/$contest/pb/index.html" : 'pb/index.html';
+       $db->problem(shift)->delete
 }
 
 sub cmd_show{
-       local $_ = shift or goto &cmd_list;
+       my %columns = $db->problem(shift)->get_columns;
+       print <<END
+Name: $columns{name}
+Author: $columns{author}
+Statement written by: $columns{writer}
+Owner: $columns{owner}
+Level: $columns{level}
+Output limit: $columns{olimit}
+Time limit: $columns{timeout}
+Test count: $columns{testcnt}
+Generator: $columns{generator}
+Runner: $columns{runner}
+Judge: $columns{judge}
+Private: $columns{private}
+END
 }
 
 ##################################################
@@ -137,8 +147,6 @@ gruntmaster-problem - shell interface to Gruntmaster 6000 problems
 
 gruntmaster-problem is a tool for managing problems.
 
-Select the contest with the optional argument I<--contest>.
-
 =over
 
 =item B<list>
@@ -179,10 +187,9 @@ Marius Gavrilescu E<lt>marius@ieval.roE<gt>
 
 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.
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself, either Perl version 5.18.1 or,
+at your option, any later version of Perl 5 you may have available.
 
 
 =cut
This page took 0.018469 seconds and 4 git commands to generate.