From b4db4836478c856d7f88f6aff1834c420307d88c Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Fri, 21 Jun 2013 14:58:53 +0200 Subject: [PATCH] thin_metadata_size: avoid unit_chars variable and adjust estimated output message --- thin-provisioning/thin_metadata_size | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/thin-provisioning/thin_metadata_size b/thin-provisioning/thin_metadata_size index e2932f1..d2136ff 100755 --- a/thin-provisioning/thin_metadata_size +++ b/thin-provisioning/thin_metadata_size @@ -42,20 +42,17 @@ def check_opts(opts) end def to_sectors(size, units) - unit_chars = units[:chars] - - a = size.split(/[#{unit_chars}]/) + a = size.split(/[#{units[:chars]}]/) s = size.to_i.to_s abort "#{$prg} - only one unit character allowed!" if a.length > 1 || size.length - s.length > 1 abort "#{$prg} - invalid unit specifier!" if s != a[0] - idx = unit_chars.index(size[a[0].length]) + idx = units[:chars].index(size[a[0].length]) r = size.to_i * units[:factors][idx] / units[:factors][0] r end def parse_command_line(argv, units) opts = {} - unit_chars = units[:chars] os = OptionParser.new do |o| o.banner = "Thin Provisioning Metadata Size Calculator.\nUsage: #{$prg} [opts]" @@ -70,7 +67,7 @@ def parse_command_line(argv, units) opts[:maxthins] = mt end o.on("-u", "--unit [#{units[:chars]}]", String, "Output unit specifier.") do |u| - abort "#{$prg} - output unit specifier invalid." if u.length > 1 || !(u =~ /[#{unit_chars}]/) + abort "#{$prg} - output unit specifier invalid." if u.length > 1 || !(u =~ /[#{units[:chars]}]/) opts[:units] = u end o.on("-n", "--numeric-only", "Output numeric value only.") do @@ -108,7 +105,7 @@ def estimated_result(opts, units) else r = "%.2e" % r end - r = "#{$prg} estimated metadata area size is #{r} #{units[:strings][idx]}." if !opts[:numeric] + r = "#{$prg} - estimated metadata area size is #{r} #{units[:strings][idx]}." if !opts[:numeric] r end