From ef88162d260c31071679afce1149e0b488509f4d Mon Sep 17 00:00:00 2001
From: Christian Pointner <equinox@helsinki.at>
Date: Wed, 3 Aug 2016 20:50:45 +0200
Subject: use new rhrdlibs pv_execute_action function for add_note


diff --git a/rhautoimport.pm b/rhautoimport.pm
index 0f9f197..1af005f 100644
--- a/rhautoimport.pm
+++ b/rhautoimport.pm
@@ -28,8 +28,6 @@ package rhautoimport;
 use File::Basename;
 use File::Temp;
 use File::Slurp;
-use IPC::Open3;
-use IO::Handle;
 use LWP::Simple;
 use XML::Feed;
 use RHRD::rddb;
@@ -269,33 +267,11 @@ sub import_uri
 
 sub pv_add_note
 {
-  my ( $title, $text, $id, $date, $type, $index ) = @_;
-  my @script = ('python', '/srv/pv/pv/manage.py', 'addnote', $id, $date, $type);
-  push(@script , $index) unless (!defined $index);
-
-  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 $title . "\n" . $text;
-  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);
-  }
+  my ($title, $text, $id, $date, $type, $index) = @_;
+  my @args = ($id, $date, $type);
+  push(@args , $index) if defined($index);
+
+  return RHRD::utils::pv_execute_action('addnote', $title . "\n" . $text, @args);
 }
 
 1;
-- 
cgit v0.10.2