summaryrefslogtreecommitdiff
path: root/rhimport.pm
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2010-03-24 14:21:08 (GMT)
committerChristian Pointner <equinox@helsinki.at>2010-03-24 14:21:08 (GMT)
commitd88725966786bce05a961438c673b62d86ea64ce (patch)
tree889d4f7b73fbf1b2ca9bc325026cca9014f6a023 /rhimport.pm
parent5b52de65b47f868e0b3224e06e766116afc81b39 (diff)
added progress bar
Diffstat (limited to 'rhimport.pm')
-rw-r--r--rhimport.pm41
1 files changed, 34 insertions, 7 deletions
diff --git a/rhimport.pm b/rhimport.pm
index 4db154c..2541660 100644
--- a/rhimport.pm
+++ b/rhimport.pm
@@ -128,27 +128,54 @@ sub clear_carts
sub import_playlist
{
- my ($playlist, $dropbox) = @_;
-
- print "Starting import from playlist $playlist to $dropbox\n";
+ my ($playlist, $dropbox, $progress_cb) = @_;
+ print "Starting import from playlist $playlist to $dropbox";
+ my @entries;
open (FILE, $playlist) or die "can't open playlist $playlist: $!";
while (my $entry = <FILE>) {
next if($entry =~ /^#/);
next if($entry =~ /^\s/);
$entry =~ s/\n$//;
- import_file($entry, $dropbox);
+ push @entries, $entry;
}
close(FILE);
+ my $num_entries = scalar(@entries);
+ print " ($num_entries Files in list)\n";
+
+ my $cnt = 0;
+ my $ret = 0;
+ for my $entry ( @entries ) {
+ if($progress_cb) {
+ $progress_cb->($cnt, $num_entries, $entry);
+ }
- return 0;
+ $ret = import_file($entry, $dropbox);
+ last if($ret != 0);
+
+ $cnt++;
+ }
+
+ if($progress_cb) {
+ $progress_cb->($num_entries, $num_entries, "Import abgeschlossen!");
+ }
+
+ return $ret;
}
sub import_single
{
- my ($file, $dropbox) = @_;
+ my ($file, $dropbox, $progress_cb) = @_;
print "Starting import from file $file to $dropbox\n";
- import_file($file, $dropbox);
+ if($progress_cb) {
+ $progress_cb->(0, 1, $file);
+ }
+ my $ret = import_file($file, $dropbox, $progress_cb);
+
+ if($progress_cb) {
+ $progress_cb->(1, 1, "Import abgeschlossen!");
+ }
+ return $ret;
}
sub import_file