summaryrefslogtreecommitdiff
path: root/lib/RHRD
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-08-03 18:43:13 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-08-03 18:43:13 (GMT)
commitd8ca7692490de9ae1a962eb6092880fb454b5083 (patch)
treedec0b56399ef23450adcf18f2576b873f0eab03e /lib/RHRD
parent255b124db5f7cc4bdba108cc7c77c285f14e8913 (diff)
added remove showid from PV to rhrd-show
Diffstat (limited to 'lib/RHRD')
-rwxr-xr-xlib/RHRD/utils.pm39
1 files changed, 39 insertions, 0 deletions
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;