From 43731275d2edc6c1b9216cd79b36d21f06832278 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Fri, 31 Dec 2004 03:35:43 +0000 Subject: [PATCH] new nicer progress bar (back-ported from v2) git-svn-id: file:///home/dpavlin/private/svn/webpac/trunk@618 13eb9ef6-21d5-0310-b721-a9d68796d827 --- all2xml.pl | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/all2xml.pl b/all2xml.pl index 3aeb38f..951863a 100755 --- a/all2xml.pl +++ b/all2xml.pl @@ -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; } } -- 2.20.1