From d8ca7692490de9ae1a962eb6092880fb454b5083 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 3 Aug 2016 20:43:13 +0200 Subject: added remove showid from PV to rhrd-show diff --git a/lib/RHRD/utils.pm b/lib/RHRD/utils.pm index cdb810c..63e51c4 100755 --- a/lib/RHRD/utils.pm +++ b/lib/RHRD/utils.pm @@ -24,6 +24,8 @@ package RHRD::utils; use strict; use POSIX; +use IPC::Open3; +use IO::Handle; use DateTime; use DateTime::TimeZone; use LWP::Simple; @@ -226,4 +228,41 @@ sub fetch_parse_json } +######################################### +## PV + +sub pv_execute_action +{ + my $action = shift; + my $stdin = shift; + my @args = @_; + + my @script = ('python', '/srv/pv/pv/manage.py', $action, @args); + + my ($reader, $writer, $error ) = ( new IO::Handle, new IO::Handle, new IO::Handle ); + $writer->autoflush(1); + local $SIG{CHLD} = 'DEFAULT'; + my $pid = open3($writer, $reader, $error, @script); + binmode($reader, ":utf8"); + binmode($writer, ":utf8"); + binmode($error, ":utf8"); + print $writer $stdin if defined($stdin); + close $writer; + waitpid $pid, 0; + my $err_out = join('', <$error>); + my $read_out = join('', <$reader>); + if ( $? >> 8 ) { + my $log = "\n\nPV: adding note returned non-zero value\n"; + $log .= "STDERR:\n" . $err_out . "\n" unless $err_out eq ''; + $log .= "STDOUT:\n" . $read_out . "\n" unless $read_out eq ''; + return(1, $log); + } else { + my $log = ''; + $log .= $read_out . "\n" unless $read_out eq ''; + $log .= $err_out . "\n" unless $err_out eq ''; + return(0, $log); + } +} + + return 1; diff --git a/utils/rhrd-show b/utils/rhrd-show index 58ed014..c52d63d 100755 --- a/utils/rhrd-show +++ b/utils/rhrd-show @@ -291,7 +291,16 @@ sub remove return 1; } if(scalar @carts == 0) { - print "group '" . $group . "' is now empty .. you should probably remove it!\n"; + print ">> group '" . $group . "' is now empty .. you should probably remove it!\n\n"; + } + + my @args = ($showid); + my ($ret, $log) = RHRD::utils::pv_execute_action('remove_automation_id', undef, @args); + if($ret) { + print "Error: removing showid from PV failed:"; + print $log; + } else { + print "removed show $showid from PV\n"; } return 0; -- cgit v0.10.2