lib/mcollective/util.rb in mcollective-client-2.2.3 vs lib/mcollective/util.rb in mcollective-client-2.2.4

- old
+ new

@@ -133,24 +133,38 @@ "agent" => [], "identity" => [], "compound" => []} end + # Returns the PuppetLabs mcollective path for windows + def self.windows_prefix + require 'win32/dir' + prefix = File.join(Dir::COMMON_APPDATA, "PuppetLabs", "mcollective") + end + # Picks a config file defaults to ~/.mcollective # else /etc/mcollective/client.cfg def self.config_file_for_user # expand_path is pretty lame, it relies on HOME environment # which isnt't always there so just handling all exceptions # here as cant find reverting to default begin config = File.expand_path("~/.mcollective") unless File.readable?(config) && File.file?(config) - config = "/etc/mcollective/client.cfg" + if self.windows? + config = File.join(self.windows_prefix, "etc", "client.cfg") + else + config = "/etc/mcollective/client.cfg" + end end rescue Exception => e - config = "/etc/mcollective/client.cfg" + if self.windows? + config = File.join(self.windows_prefix, "etc", "client.cfg") + else + config = "/etc/mcollective/client.cfg" + end end return config end @@ -411,35 +425,36 @@ # # returns 0 if a == b # returns -1 if a < b # returns 1 if a > b # - # Code originally from Puppet but refactored to a more - # ruby style that fits in better with this code base + # Code originally from Puppet def self.versioncmp(version_a, version_b) vre = /[-.]|\d+|[^-.\d]+/ - ax = version_a.scan(vre) + ax = version_a.scan(vre) bx = version_b.scan(vre) - until ax.empty? || bx.empty? + while (ax.length>0 && bx.length>0) a = ax.shift b = bx.shift - next if a == b - next if a == '-' && b == '-' - return -1 if a == '-' - return 1 if b == '-' - next if a == '.' && b == '.' - return -1 if a == '.' - return 1 if b == '.' - - if a =~ /^[^0]\d+$/ && b =~ /^[^0]\d+$/ - return Integer(a) <=> Integer(b) + if( a == b ) then next + elsif (a == '-' && b == '-') then next + elsif (a == '-') then return -1 + elsif (b == '-') then return 1 + elsif (a == '.' && b == '.') then next + elsif (a == '.' ) then return -1 + elsif (b == '.' ) then return 1 + elsif (a =~ /^\d+$/ && b =~ /^\d+$/) then + if( a =~ /^0/ or b =~ /^0/ ) then + return a.to_s.upcase <=> b.to_s.upcase + end + return a.to_i <=> b.to_i else return a.upcase <=> b.upcase end end - version_a <=> version_b + version_a <=> version_b; end end end