2009/6/8 James Turnbull <[email protected]>:
>
> From: Felix Schäfer <[email protected]>
Needs more work.
If we're doing complex conditionals we really should have some tests,
which would have picked up the logic issues below:
> ---
> lib/facter/uptime.rb | 30 ++++++++++++++++++++----------
> lib/facter/util/uptime.rb | 6 +++---
> 2 files changed, 23 insertions(+), 13 deletions(-)
>
> diff --git a/lib/facter/uptime.rb b/lib/facter/uptime.rb
> index 3a3bc86..54e6692 100644
> --- a/lib/facter/uptime.rb
> +++ b/lib/facter/uptime.rb
> @@ -1,12 +1,5 @@
> require 'facter/util/uptime'
>
> -Facter.add(:uptime) do
> - confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE
> SLES Debian Ubuntu Gentoo AIX}
> - setcode do
> - Facter::Util::Uptime.get_uptime_simple
> - end
> -end
> -
> if FileTest.exists?("/proc/uptime")
> uptime = Facter::Util::Uptime.get_uptime
>
> @@ -14,7 +7,24 @@ if FileTest.exists?("/proc/uptime")
> Facter.add("uptime_" + label) do
> setcode do
> Facter::Util::Uptime.get_uptime_period(uptime, label)
> - end
> - end
> - end
> + end
> + end
> + end
> end
> +
> +Facter.add(:uptime) do
> + confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE
> SLES Debian Ubuntu Gentoo AIX}
> + uptime_human_readable = ""
> + if uptime_seconds = Facter.value(:uptime_seconds)
Assignment not comparison
> + if uptime_days = Facter.value(:uptime_days)
Assignment not comparison
> + uptime_human_readable = uptime_days + " days"
> + else
> + uptime_human_readable = Facter.value(:uptime_hours) + ":" +
> (uptime_seconds/60%60).to_s + " hours"
> + end
> + else
> + uptime_human_readable = Facter::Util::Uptime.get_uptime_simple
> + end
> + setcode do
> + uptime_human_readable
> + end
> +end
> \ No newline at end of file
> diff --git a/lib/facter/util/uptime.rb b/lib/facter/util/uptime.rb
> index c1e339b..92cdfaa 100644
> --- a/lib/facter/util/uptime.rb
> +++ b/lib/facter/util/uptime.rb
> @@ -14,7 +14,7 @@ module Facter::Util::Uptime
>
> def self.get_uptime
> r = IO.popen("/bin/cat /proc/uptime")
> - uptime, idletime = r.readline.split(" ")
> + uptime, idletime = r.readline.split(" ")
White space noise pollution.
> r.close
> uptime_seconds = uptime.to_i
> end
> @@ -27,6 +27,6 @@ module Facter::Util::Uptime
> value = seconds / 3600
> when 'seconds'
> seconds
> - end
> + end
> end
> -end
> +end
White space noise polution
Paul
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---