X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=lib%2FBackupPC%2FSearch.pm;h=f2dac44032b8a661042a284e18dbeedc25c63b8e;hp=479b51d70546c13f5eba2781b45c02f68ed2b7a4;hb=1f12f5ba25530a04f3a5e7b86c3ac88d9526fe1d;hpb=aff621b091597104904eafcb4ad6d9fabc2bf7bb diff --git a/lib/BackupPC/Search.pm b/lib/BackupPC/Search.pm index 479b51d..f2dac44 100644 --- a/lib/BackupPC/Search.pm +++ b/lib/BackupPC/Search.pm @@ -12,6 +12,10 @@ use XML::Writer; use IO::File; use Data::Dump qw(dump); +require Exporter; +our @ISA=qw(Exporter); +our @EXPORT=qw(unit); + my $on_page = 100; my $pager_pages = 10; @@ -454,8 +458,6 @@ print STDERR "## sort=". ($param->{'sort'} || 'no sort param') . " burn sql orde ($row->{volumes}, $row->{inc_size_calc}) = getVolumes($row->{id}); } - $row->{size} = sprintf("%0.2f", $row->{size} / 1024 / 1024); - # do some cluster calculation (approximate) $row->{inc_size} = int(( ($row->{inc_size} + 1023 ) / 2 ) * 2); $row->{inc_size_calc} ||= $row->{inc_size}; @@ -828,8 +830,8 @@ EOF3 } . sort_header($param, 'Date', 'date', 'center') . sort_header($param, 'Age/days', 'age', 'center') . - sort_header($param, 'Size/Mb', 'size', 'center') . - sort_header($param, 'gzip size/Kb', 'incsize', 'center') . + sort_header($param, 'Size', 'size', 'center') . + sort_header($param, 'gzip size', 'incsize', 'center') . qq{ medias }; @@ -867,8 +869,8 @@ EOF3 '' . $backup->{'type'} . '' . '' . epoch_to_iso( $backup->{'date'} ) . '' . '' . $backup->{'age'} . '' . - '' . $backup->{'size'} . '' . - '' . sprintf("%0.1f", $backup->{'inc_size'} / 1024 ) . + '' . unit($backup->{'size'}) . '' . + '' . unit($backup->{'inc_size'}) . '' . '' . '' . '' . ( qq{media} x $backup->{volumes} ) . '' . @@ -1118,4 +1120,24 @@ sub displayGrid($) { return $retHTML; } +my @units = qw/b k M G/; +sub unit { + my $v = shift; + + my $o = 0; + + while ( ( $v / 10000 ) >= 1 ) { + $o++; + $v /= 1024; + } + + if ( $v >= 1 ) { + return sprintf("%d%s", $v, $units[$o]); + } elsif ( $v == 0 ) { + return 0; + } else { + return sprintf("%.1f%s", $v, $units[$o]); + } +} + 1;