From dc2fabd7813db35f3802057649d28d81f1f5ef7d Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Fri, 7 Dec 2018 11:02:37 +1300 Subject: [PATCH] Optionally strip off anything after the decimal point once we've converted the size --- bin/mythtv-status | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) 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 { -- 2.30.2