diff options
author | Christian Pointner <equinox@helsinki.at> | 2010-04-06 16:42:56 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2010-04-06 16:42:56 (GMT) |
commit | 7e563eecd8b86a372a1e8040c01debd7ebede909 (patch) | |
tree | 5a0c694e99ae5679e45573932edc65b8018da85e | |
parent | d2b849fd657d99968545a3d4ddfe25033f19bb94 (diff) |
first working version (command line)
some issues with error handling and gui remain
-rwxr-xr-x | rhimport | 12 | ||||
-rw-r--r-- | rhimport.pm | 70 |
2 files changed, 60 insertions, 22 deletions
@@ -32,8 +32,8 @@ use lib '/usr/share/perl5/rhimport/'; use rhimport; my $DBHOST = "airplay"; -my $DBUSER = "rivendellro"; -my $DBPW = "lldrivenro"; +my $DBUSER = "rivendell"; +my $DBPW = "lldriven"; my $DB = "rivendell"; my $HELP = 0; my $FILE = ""; @@ -371,4 +371,10 @@ if($POOL) { } $dbh->disconnect(); -exit $ret; + +if($ret ne "") { + print STDERR $ret; + exit 1; +} + +exit 0; 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; |