summaryrefslogtreecommitdiffstats
path: root/lib/MDV/Draklive/Progress.pm
diff options
context:
space:
mode:
authorOlivier Blin <oblin@mandriva.com>2008-10-28 23:47:21 +0000
committerOlivier Blin <oblin@mandriva.com>2008-10-28 23:47:21 +0000
commit970bbb3887e4d1ca89ee1ca117defaa85c6845e7 (patch)
tree755462f25db6309971598d81aae864433be69295 /lib/MDV/Draklive/Progress.pm
parent0743fdbac70eff08481084934ef5f38a0d15cd74 (diff)
downloaddraklive-970bbb3887e4d1ca89ee1ca117defaa85c6845e7.tar
draklive-970bbb3887e4d1ca89ee1ca117defaa85c6845e7.tar.gz
draklive-970bbb3887e4d1ca89ee1ca117defaa85c6845e7.tar.bz2
draklive-970bbb3887e4d1ca89ee1ca117defaa85c6845e7.tar.xz
draklive-970bbb3887e4d1ca89ee1ca117defaa85c6845e7.zip
extract progress code in a new MDV::Draklive::Progress object
Diffstat (limited to 'lib/MDV/Draklive/Progress.pm')
-rw-r--r--lib/MDV/Draklive/Progress.pm31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/MDV/Draklive/Progress.pm b/lib/MDV/Draklive/Progress.pm
new file mode 100644
index 0000000..128ffe3
--- /dev/null
+++ b/lib/MDV/Draklive/Progress.pm
@@ -0,0 +1,31 @@
+package MDV::Draklive::Progress;
+
+use POSIX qw(strftime);
+
+sub new {
+ my ($class, $total, $time, $o_exp_divide) = @_;
+ bless {
+ total => $total,
+ current => 0,
+ start_time => $time,
+ exp_divide => $o_exp_divide,
+ maxl => length($total) - $o_exp_divide,
+ }, $class;
+}
+
+sub show {
+ my ($progress, $time) = @_;
+ my $elapsed_time = $time - $progress->{start_time};
+ my $eta = $progress->{current} ? int($elapsed_time*$progress->{total}/$progress->{current}) : -1;
+ printf("\r%3d%% (%$progress->{maxl}s/%-$progress->{maxl}s), %8s/%8s (ETA)",
+ int(100*$progress->{current}/$progress->{total}),
+ (map { substr($_, 0, length($_)-$progress->{exp_divide}) } $progress->{current}, $progress->{total}),
+ (map { POSIX::strftime("%H:%M:%S", gmtime($_)) } $elapsed_time, $eta));
+}
+
+sub end {
+ my ($_progress) = @_;
+ print "\n";
+}
+
+1;