From: Andrew Ruthven Date: Thu, 6 Dec 2018 22:02:37 +0000 (+1300) Subject: Optionally strip off anything after the decimal point once we've converted the size X-Git-Tag: 1.0.0~47 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc2fabd7813db35f3802057649d28d81f1f5ef7d;p=mythtv-status.git Optionally strip off anything after the decimal point once we've converted the size --- diff --git a/bin/mythtv-status b/bin/mythtv-status index 8270b7d..5b2ac7c 100755 --- a/bin/mythtv-status +++ b/bin/mythtv-status @@ -72,18 +72,32 @@ $c->{'xml_file'} ||= undef; # Load the BE XML from this file. # it believes it is a bulleted list and leaves it alone. $c->{'oneliner_bullets'} ||= 0; -# What units we have available for converting diskspaces. -# The threshold is at what level we switch to using that unit. +# What units we have available for converting diskspaces. The order is +# important, the largest unit should come first. +# +# Allowed keys: +# unit - SI unit to use +# threshold - Any value greater than threshold uses this unit +# make_integer - Strip off anything after the decimal point +# make_integer_threshold - Anything over this value will have the +# decimal point removed if make_integer is set to 1. This test is applied +# after the size has been converted, so the value should be in the 'new' +# unit. +# my @size_thresholds = ( { 'unit' => 'TB', 'threshold' => 1024 * 1024, 'conversion' => 1024 * 1024, + 'make_integer' => 1, + 'make_integer_threshold' => 500, }, { 'unit' => 'GB', 'threshold' => 50 * 1024, # 50GB seems like a good threshold. 'conversion' => 1024, + 'make_integer' => 1, + 'make_integer_threshold' => 500, }, { 'unit' => 'MB', @@ -1031,6 +1045,12 @@ sub substitute_vars { $vars->{"si_$key"} =~ s/\.0//; $vars->{"si_${key}_unit"} = $unit->{'unit'}; + if ($unit->{'make_integer'} && + (! defined $unit->{'make_integer_threshold'} + || $vars->{"si_$key"} > $unit->{'make_integer_threshold'})) { + $vars->{"si_$key"} =~ s/\.[0-9]+//; + } + last; } } else {