new nicer progress bar (back-ported from v2)
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 31 Dec 2004 03:35:43 +0000 (03:35 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 31 Dec 2004 03:35:43 +0000 (03:35 +0000)
git-svn-id: file:///home/dpavlin/private/svn/webpac/trunk@618 13eb9ef6-21d5-0310-b721-a9d68796d827

all2xml.pl

index 3aeb38f..951863a 100755 (executable)
@@ -667,15 +667,30 @@ print STDERR "reading ./import_xml/$type.xml\n";
 
        $config=XMLin("./import_xml/$type.xml", ForceArray => [ $type2tag{$type_base}, 'config', 'format' ], ForceContent => 1 );
 
+       # helper for progress bar
+       sub fmt_time {
+               my $t = shift || 0;
+               my $out = "";
+
+               my ($ss,$mm,$hh) = gmtime($t);
+               $out .= "${hh}h" if ($hh);
+               $out .= sprintf("%02d:%02d", $mm,$ss);
+               $out .= "  " if ($hh == 0);
+               return $out;
+       }
+
        # output current progress indicator
        my $last_p = 0;
+       my $start_t = time();
        sub progress {
                return if (! $show_progress);
                my $current = shift;
                my $total = shift || 1;
                my $p = int($current * 100 / $total);
                if ($p != $last_p) {
-                       printf STDERR ("%5d / %5d [%-51s] %-2d %% \r",$current,$total,"=" x ($p/2).">", $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));
                        $last_p = $p;
                }
        }