From 283dd3e8f08217e28170e47a79a4dc56a518ff69 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 9 Apr 2010 09:35:38 +0000 Subject: fixed return values added error callback git-svn-id: https://svn.helsinki.at/rhimport/trunk@36 7c65635b-ec39-4f67-a626-873dbafdd612 diff --git a/rhimport b/rhimport index 0ccfa0e..3e3a36e 100755 --- a/rhimport +++ b/rhimport @@ -64,7 +64,7 @@ options: -l | --list-allowed list allowed dropboxes and exit EOF - exit; + exit 0; } my $user = `/usr/bin/id -un`; @@ -90,7 +90,7 @@ sub set_mode_playlist_gui() { if(!$guixml) { print STDERR "no GUI definition found!\n"; - exit 0; + exit 2; } $POOL = 1; @@ -110,7 +110,7 @@ sub set_mode_file_gui() { if(!$guixml) { print STDERR "no GUI definition found!\n"; - exit 0; + exit 2; } $POOL = 0; @@ -139,7 +139,7 @@ sub toggle_mode_gui() { if(!$guixml) { print STDERR "no GUI definition found!\n"; - exit 0; + exit 2; } my $co_dropbox = $guixml->get_widget('co_dropbox'); @@ -181,7 +181,7 @@ my $gui_progress_cb = sub { if(!$guixml) { print STDERR "no GUI definition found!\n"; - exit 0; + exit 2; } my $progressbar = $guixml->get_widget('progressbar'); $progressbar->set_text("($elapsed/$max) $text"); @@ -196,7 +196,7 @@ sub start_import_gui() { if(!$guixml) { print STDERR "no GUI definition found!\n"; - exit 0; + exit 2; } my $l_status = $guixml->get_widget('l_status'); @@ -242,7 +242,7 @@ sub show_used_carts_gui() { if(!$guixml) { print STDERR "no GUI definition found!\n"; - exit 0; + exit 2; } my $co_dropbox = $guixml->get_widget('co_dropbox'); @@ -267,7 +267,7 @@ sub clear_status_gui() { if(!$guixml) { print STDERR "no GUI definition found!\n"; - exit 0; + exit 2; } my $l_status = $guixml->get_widget('l_status'); @@ -282,7 +282,7 @@ sub dropbox_updated_gui() { if(!$guixml) { print STDERR "no GUI definition found!\n"; - exit 0; + exit 2; } my $co_dropbox = $guixml->get_widget('co_dropbox'); @@ -372,8 +372,7 @@ if($POOL) { $dbh->disconnect(); -if($ret ne "") { - print STDERR $ret; +if(!$ret) { exit 1; } diff --git a/rhimport.pm b/rhimport.pm index 264119d..f96f7b4 100644 --- a/rhimport.pm +++ b/rhimport.pm @@ -102,7 +102,7 @@ sub get_used_carts sub clear_carts { - my ($dbh, $group, $to_cart) = @_; + my ($dbh, $group, $to_cart, $error_cb) = @_; my ($low_cart, $high_cart) = ($to_cart, $to_cart); if($to_cart == 0) { @@ -116,6 +116,7 @@ sub clear_carts my $sth = $dbh->prepare($sql); $sth->execute(); while(my $cut_name = $sth->fetchrow_array()) { +## TODO: Error handling would be nice! delete_file("/var/snd/$cut_name.wav"); } $sth->finish(); @@ -136,7 +137,7 @@ sub clear_carts sub import_playlist { - my ($playlist, $dropbox, $progress_cb) = @_; + my ($playlist, $dropbox, $progress_cb, $error_cb) = @_; print "Starting import from playlist $playlist to $dropbox"; my @entries; @@ -158,8 +159,8 @@ sub import_playlist $progress_cb->($cnt, $num_entries, $entry); } - $ret = import_file($entry, $dropbox); - last if($ret ne ""); + $ret = import_file($entry, $dropbox, $error_cb); + last if($ret == 0); $cnt++; } @@ -173,12 +174,12 @@ sub import_playlist sub import_single { - my ($file, $dropbox, $progress_cb) = @_; + my ($file, $dropbox, $progress_cb, $error_cb) = @_; print "Starting import from file $file to $dropbox\n"; if($progress_cb) { $progress_cb->(0, 1, $file); } - my $ret = import_file($file, $dropbox, $progress_cb); + my $ret = import_file($file, $dropbox, $error_cb); if($progress_cb) { $progress_cb->(1, 1, "Import abgeschlossen!"); @@ -219,7 +220,7 @@ sub ssh_exec_command { sub import_file { - my ($file, $dropbox) = @_; + my ($file, $dropbox, $error_cb) = @_; print " - importing $file to $dropbox .. "; $| = 1; @@ -228,21 +229,28 @@ sub import_file my $err = scp_put_file($file); if($err ne "") { print "Transfer Error\n"; - return $err; + if($error_cb) { + return $error_cb->($err); + } + return 0; } print "transferred .. "; - ### remotly call rdimport + ### remotely 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; + delete_file($remote_file); + if($error_cb) { + return $error_cb->($err); + } + return 0; } print "imported OK\n"; - return ""; + return 1; } sub delete_file @@ -252,9 +260,9 @@ sub delete_file print " - deleting $filename\n"; my ($out ,$err) = ssh_exec_command("rm \"$filename\""); if($err ne "") { - return 1; + return 0; } - return 0; + return 1; } 1; -- cgit v0.10.2