summaryrefslogtreecommitdiff
path: root/rhimport.pm
diff options
context:
space:
mode:
Diffstat (limited to 'rhimport.pm')
-rw-r--r--rhimport.pm70
1 files changed, 51 insertions, 19 deletions
diff --git a/rhimport.pm b/rhimport.pm
index d4c5ab8..264119d 100644
--- a/rhimport.pm
+++ b/rhimport.pm
@@ -27,11 +27,13 @@ package rhimport;
use IO::Handle;
use IPC::Open3;
+use File::Spec;
my $ssh_host = "airplay";
my $ssh_user = "rhimport";
my $ssh_key_file = "id_dsa";
-my $ssh_dir = "~/.rhimport/";
+my $ssh_dir = "/programm/.rhimport";
+my $rdimport_wrapper = "/usr/local/bin/dropbox_newfile.pl";
sub get_dropboxes
{
@@ -118,16 +120,16 @@ sub clear_carts
}
$sth->finish();
-# my $sql = qq{delete from CUTS where CART_NUMBER='$cart';};
-# my $sth = $dbh->prepare($sql);
-# $sth->execute();
-# $sth->finish();
-
-# my $sql = qq{delete from CARTS where NUMBER='$cart';};
-# my $sth = $dbh->prepare($sql);
-# $sth->execute();
-# $sth->finish();
-
+ $sql = qq{delete from CUTS where CART_NUMBER='$cart';};
+ $sth = $dbh->prepare($sql);
+ $sth->execute();
+ $sth->finish();
+
+ $sql = qq{delete from CART where NUMBER='$cart';};
+ $sth = $dbh->prepare($sql);
+ $sth->execute();
+ $sth->finish();
+
$cart++;
}
}
@@ -157,7 +159,7 @@ sub import_playlist
}
$ret = import_file($entry, $dropbox);
- last if($ret != 0);
+ last if($ret ne "");
$cnt++;
}
@@ -186,7 +188,7 @@ sub import_single
sub scp_put_file {
my ($file) = @_;
- my @cmd = ( 'scp', '-prqB' , '-i', $ssh_key_file, $file, "$ssh_user\@$ssh_host:$ssh_dir" );
+ my @cmd = ( 'scp', '-prqB' , '-i', $ssh_key_file, $file, "$ssh_user\@$ssh_host:$ssh_dir/" );
my ($reader, $writer, $error ) = ( new IO::Handle, new IO::Handle, new IO::Handle );
$writer->autoflush(1);
local $SIG{CHLD} = 'DEFAULT';
@@ -194,11 +196,27 @@ sub scp_put_file {
waitpid $pid, 0;
my $errstr = "";
if ( $? >> 8 ) {
- my $errstr = join('', <$error>);
+ $errstr = join('', <$error>);
}
return $errstr;
}
+sub ssh_exec_command {
+ my ($command) = @_;
+ my @cmd = ( 'ssh', '-q' , '-i', $ssh_key_file, "$ssh_user\@$ssh_host" , $command );
+ 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, @cmd);
+ waitpid $pid, 0;
+ my $out = join('', <$reader>);
+ my $errstr = "";
+ if ( $? >> 8 ) {
+ $errstr = join('', <$error>);
+ }
+ return ($out, $errstr);
+}
+
sub import_file
{
my ($file, $dropbox) = @_;
@@ -208,13 +226,23 @@ sub import_file
### copy file to master server and
my $err = scp_put_file($file);
- die $err unless $err eq "";
+ if($err ne "") {
+ print "Transfer Error\n";
+ return $err;
+ }
+ print "transferred .. ";
### remotly call rdimport
+ my ($volume, $directories, $remote_file) = File::Spec->splitpath($file);
+ $remote_file = "$ssh_dir/$remote_file";
+ my ($out ,$error) = ssh_exec_command("$rdimport_wrapper --path \"$dropbox\" --file \"$remote_file\"");
+ if($error ne "") {
+ print "Import Error\n";
+ return $error;
+ }
- print "Ok\n";
-
- return 0;
+ print "imported OK\n";
+ return "";
}
sub delete_file
@@ -222,7 +250,11 @@ sub delete_file
my ($filename) = @_;
print " - deleting $filename\n";
- ### call unlink on remote machine (master server)
+ my ($out ,$err) = ssh_exec_command("rm \"$filename\"");
+ if($err ne "") {
+ return 1;
+ }
+ return 0;
}
1;