yet another progress bar fix
[webpac] / all2xml.pl
index 3f6f902..3fc1299 100755 (executable)
@@ -687,7 +687,10 @@ print STDERR "reading ./import_xml/$type.xml\n";
                my $current = shift;
                my $total = shift || 1;
                my $p = int($current * 100 / $total);
-               if ($p != $last_p) {
+               if ($p < $last_p || $current == 1) {
+                       $start_t = time();
+                       $last_p = 0;
+               } elsif ($p != $last_p) {
                        my $rate = ($current / (time() - $start_t || 1));
                        my $eta = ($total-$current) / ($rate || 1);
                        printf STDERR ("%5d [%-38s] %-5d %0.1f/s %s\r",$current,"=" x ($p/3)."$p%>", $total, $rate, fmt_time($eta));
@@ -696,16 +699,30 @@ print STDERR "reading ./import_xml/$type.xml\n";
        }
 
        my $fake_dir = 1;
+       my $fake_pos = 0;
+       my $last_fake_t = time();
        sub fakeprogress {
                return if (! $show_progress);
                my $current = shift @_;
 
-               my @ind = ('-','\\','|','/','-','\\','|','/', '-');
+               my @ind = ('-','\\','|','/','-','\\','|','/');
 
-               $last_p += $fake_dir;
-               $fake_dir = -$fake_dir if ($last_p > 1000 || $last_p < 0);
-               if ($last_p % 10 == 0) {
-                       printf STDERR ("%5d / %5s [%-51s]\r",$current,"?"," " x ($last_p/20).$ind[($last_p/20) % $#ind]);
+               if ($current < $fake_pos) {
+                       $start_t = time();
+                       $last_fake_t = 0;
+                       $fake_dir = 1;
+                       $fake_pos = 0;
+               }
+
+               if (time()-$last_fake_t >= 1) {
+                       $last_fake_t = time();
+                       $fake_pos += $fake_dir;
+                       $fake_dir = -$fake_dir if ($fake_pos > 38);
+               }
+
+               if ($current % 10 == 0) {
+                       my $rate = ($current / (time() - $start_t || 1));
+                       printf STDERR ("%5d [%-38s] %0.1f/s\r",$current, " " x $fake_pos .$ind[($current / 10) % 8], $rate);
                }
        }
 
@@ -915,7 +932,7 @@ all2xml.pl - read various file formats and dump XML for SWISH-E
 
 =head1 DESCRIPTION
 
-This command will read ISIS data file using OpenIsis perl module, MARC
+This command will read ISIS data file using IsisDB perl module, MARC
 records using MARC module and optionally Micro$oft Excel files to
 create one XML file for usage with I<SWISH-E> indexer. Dispite it's name,
 this script B<isn't general xml generator> from isis files (isis allready