From 83a8a7d6035372ef9d8e78fb46742f7bf2a3a1ca Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Thu, 16 Jan 2014 17:55:27 +0200 Subject: [PATCH] Add gruntmaster-job --- Makefile.PL | 2 +- gruntmaster-job | 65 +++++++++++++++++++++++++++++++++++++++++ lib/Gruntmaster/Data.pm | 6 +++- 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100755 gruntmaster-job diff --git a/Makefile.PL b/Makefile.PL index 822a1c7..3a7901c 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -4,7 +4,7 @@ use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Gruntmaster::Page', VERSION_FROM => 'lib/Gruntmaster/Page.pm', - EXE_FILES => [ qw/gruntmaster-genpage gruntmaster-genallpages gruntmaster-paged gruntmaster-problem/ ], + EXE_FILES => [ qw/gruntmaster-genpage gruntmaster-genallpages gruntmaster-paged gruntmaster-problem gruntmaster-job/ ], ABSTRACT_FROM => 'lib/Gruntmaster/Page.pm', AUTHOR => 'Marius Gavrilescu ', MIN_PERL_VERSION => '5.14.0', diff --git a/gruntmaster-job b/gruntmaster-job new file mode 100755 index 0000000..b454ad4 --- /dev/null +++ b/gruntmaster-job @@ -0,0 +1,65 @@ +#!/usr/bin/perl -w +use v5.14; + +use Gruntmaster::Data qw/jobcard job_date job_user job_problem job_filesize job_private job_result_text job_daemon clean_job problem_name PUBLISH HDEL/; + +use IO::Prompter [ -style => 'bold', '-stdio', '-verbatim' ]; +use File::Slurp qw/read_file/; +use Term::ANSIColor qw/RED RESET/; +use POSIX qw/strftime/; + +################################################## + +sub cmd_help{ + exec perldoc => $0 +} + +sub cmd_card{ + my $contest = shift; + print jobcard; +} + +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 "Size: ", sprintf "%.2fKB", job_filesize() / 1024; + say "Private: ", (job_private() ? 'yes' : 'no'); + say "Result text: ", job_result_text; + say "Daemon: ", job_daemon; +} + +sub cmd_rerun{ + local $_ = shift or goto &cmd_list; + clean_job; + PUBLISH jobs => $_; +} + +################################################## + +no strict 'refs'; +my $cmd = 'cmd_' . shift; +cmd_help unless exists $main::{$cmd}; +$cmd->(@ARGV) if exists $main::{$cmd}; + +1; +__END__ + +=encoding utf-8 + +=head1 NAME + +gruntmaster-job - shell interface to Gruntmaster 6000 job log + +=head1 SYNOPSIS + + gruntmaster-job card + gruntmaster-job show 5 + gruntmaster-job rerun 7 + +=head1 DESCRIPTION + + + +=cut diff --git a/lib/Gruntmaster/Data.pm b/lib/Gruntmaster/Data.pm index 9504cf8..2f8a184 100644 --- a/lib/Gruntmaster/Data.pm +++ b/lib/Gruntmaster/Data.pm @@ -17,7 +17,7 @@ sub dynsub{ } BEGIN { - for my $cmd (qw/multi exec smembers get hget hset sadd srem incr hmset hsetnx/) { + for my $cmd (qw/multi exec smembers get hget hdel hset sadd srem incr hmset hsetnx/) { dynsub uc $cmd, sub { say "Arguments to \U$cmd: ", join ', ', @_; $redis->$cmd(@_) }; } @@ -73,6 +73,10 @@ defhash contest => qw/start end name owner/; defhash job => qw/date extension filesize private problem result result_text user/; defhash user => qw/name email town university/; +sub clean_job (_){ + HDEL cp . "job.$_[0]", qw/result result_text results daemon/ +} + our @EXPORT_OK = do { no strict 'refs'; grep { $_ =~ /^[a-zA-Z]/ and exists &$_ } keys %{__PACKAGE__ . '::'}; -- 2.39.2