From 08110a869ce2a4d14ccf5414f9d3057348c8d4f5 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 12 Apr 2010 13:58:20 +0000 Subject: added error callback to command line some cleanup diff --git a/rhimport b/rhimport index 3e3a36e..15a030b 100755 --- a/rhimport +++ b/rhimport @@ -337,6 +337,14 @@ if(!$FILE || !$DROPBOX) { ########################################### ## command line mode +my $cl_error_cb = sub { + my ($text) = @_; + + print "\n$text .. cancel operation [Y/n]? "; + my $x = scalar(); + $x =~ /^n/i; +}; + (-e "$FILE") or die "file '$FILE' not found"; if($POOL) { print "will import from playlist $FILE, with user $user\n\n"; @@ -365,9 +373,9 @@ if($POOL) { rhimport::clear_carts($dbh, $group, $to_cart); } - $ret = rhimport::import_playlist($FILE, $DROPBOX); + $ret = rhimport::import_playlist($FILE, $DROPBOX, 0, $cl_error_cb); } else { - $ret = rhimport::import_single($FILE, $DROPBOX); + $ret = rhimport::import_single($FILE, $DROPBOX, 0); } $dbh->disconnect(); diff --git a/rhimport.pm b/rhimport.pm index f96f7b4..c970bcf 100644 --- a/rhimport.pm +++ b/rhimport.pm @@ -102,7 +102,7 @@ sub get_used_carts sub clear_carts { - my ($dbh, $group, $to_cart, $error_cb) = @_; + my ($dbh, $group, $to_cart) = @_; my ($low_cart, $high_cart) = ($to_cart, $to_cart); if($to_cart == 0) { @@ -155,9 +155,7 @@ sub import_playlist my $cnt = 0; my $ret = 0; for my $entry ( @entries ) { - if($progress_cb) { - $progress_cb->($cnt, $num_entries, $entry); - } + $progress_cb->($cnt, $num_entries, $entry) if($progress_cb); $ret = import_file($entry, $dropbox, $error_cb); last if($ret == 0); @@ -165,9 +163,7 @@ sub import_playlist $cnt++; } - if($progress_cb) { - $progress_cb->($num_entries, $num_entries, "Import abgeschlossen!"); - } + $progress_cb->($num_entries, $num_entries, "Import abgeschlossen!") if($progress_cb); return $ret; } @@ -176,14 +172,9 @@ sub import_single { my ($file, $dropbox, $progress_cb, $error_cb) = @_; print "Starting import from file $file to $dropbox\n"; - if($progress_cb) { - $progress_cb->(0, 1, $file); - } + $progress_cb->(0, 1, $file) if($progress_cb); my $ret = import_file($file, $dropbox, $error_cb); - - if($progress_cb) { - $progress_cb->(1, 1, "Import abgeschlossen!"); - } + $progress_cb->(1, 1, "Import abgeschlossen!") if($progress_cb); return $ret; } @@ -214,6 +205,7 @@ sub ssh_exec_command { my $errstr = ""; if ( $? >> 8 ) { $errstr = join('', <$error>); + $errstr = "unkown error" if($errstr eq ""); } return ($out, $errstr); } -- cgit v0.10.2