summaryrefslogtreecommitdiffstats
path: root/lib/puppet/provider/package/yum.rb
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
commit3180b9d9b2c844dade1d361326600f7001ec66dd (patch)
tree98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /lib/puppet/provider/package/yum.rb
parent543225970225de5697734bfaf0a6eee996802c04 (diff)
downloadpuppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.gz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.xz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.zip
Code smell: Two space indentation
Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
Diffstat (limited to 'lib/puppet/provider/package/yum.rb')
-rwxr-xr-xlib/puppet/provider/package/yum.rb178
1 files changed, 89 insertions, 89 deletions
diff --git a/lib/puppet/provider/package/yum.rb b/lib/puppet/provider/package/yum.rb
index 17981f03c..07f68ddb1 100755
--- a/lib/puppet/provider/package/yum.rb
+++ b/lib/puppet/provider/package/yum.rb
@@ -1,100 +1,100 @@
Puppet::Type.type(:package).provide :yum, :parent => :rpm, :source => :rpm do
- desc "Support via ``yum``."
-
- has_feature :versionable
-
- commands :yum => "yum", :rpm => "rpm", :python => "python"
-
- YUMHELPER = File::join(File::dirname(__FILE__), "yumhelper.py")
-
- attr_accessor :latest_info
-
- if command('rpm')
- confine :true => begin
- rpm('--version')
- rescue Puppet::ExecutionFailure
- false
- else
- true
- end
- end
-
- defaultfor :operatingsystem => [:fedora, :centos, :redhat]
-
- def self.prefetch(packages)
- raise Puppet::Error, "The yum provider can only be used as root" if Process.euid != 0
- super
- return unless packages.detect { |name, package| package.should(:ensure) == :latest }
-
- # collect our 'latest' info
- updates = {}
- python(YUMHELPER).each_line do |l|
- l.chomp!
- next if l.empty?
- if l[0,4] == "_pkg"
- hash = nevra_to_hash(l[5..-1])
- [hash[:name], "#{hash[:name]}.#{hash[:arch]}"].each do |n|
- updates[n] ||= []
- updates[n] << hash
- end
- end
- end
-
- # Add our 'latest' info to the providers.
- packages.each do |name, package|
- if info = updates[package[:name]]
- package.provider.latest_info = info[0]
- end
+ desc "Support via ``yum``."
+
+ has_feature :versionable
+
+ commands :yum => "yum", :rpm => "rpm", :python => "python"
+
+ YUMHELPER = File::join(File::dirname(__FILE__), "yumhelper.py")
+
+ attr_accessor :latest_info
+
+ if command('rpm')
+ confine :true => begin
+ rpm('--version')
+ rescue Puppet::ExecutionFailure
+ false
+ else
+ true
+ end
+ end
+
+ defaultfor :operatingsystem => [:fedora, :centos, :redhat]
+
+ def self.prefetch(packages)
+ raise Puppet::Error, "The yum provider can only be used as root" if Process.euid != 0
+ super
+ return unless packages.detect { |name, package| package.should(:ensure) == :latest }
+
+ # collect our 'latest' info
+ updates = {}
+ python(YUMHELPER).each_line do |l|
+ l.chomp!
+ next if l.empty?
+ if l[0,4] == "_pkg"
+ hash = nevra_to_hash(l[5..-1])
+ [hash[:name], "#{hash[:name]}.#{hash[:arch]}"].each do |n|
+ updates[n] ||= []
+ updates[n] << hash
end
+ end
end
- def install
- should = @resource.should(:ensure)
- self.debug "Ensuring => #{should}"
- wanted = @resource[:name]
-
- # XXX: We don't actually deal with epochs here.
- case should
- when true, false, Symbol
- # pass
- should = nil
- else
- # Add the package version
- wanted += "-#{should}"
- end
-
- output = yum "-d", "0", "-e", "0", "-y", :install, wanted
-
- is = self.query
- raise Puppet::Error, "Could not find package #{self.name}" unless is
-
- # FIXME: Should we raise an exception even if should == :latest
- # and yum updated us to a version other than @param_hash[:ensure] ?
- raise Puppet::Error, "Failed to update to version #{should}, got version #{is[:ensure]} instead" if should && should != is[:ensure]
+ # Add our 'latest' info to the providers.
+ packages.each do |name, package|
+ if info = updates[package[:name]]
+ package.provider.latest_info = info[0]
+ end
end
-
- # What's the latest package version available?
- def latest
- upd = latest_info
- unless upd.nil?
- # FIXME: there could be more than one update for a package
- # because of multiarch
- return "#{upd[:version]}-#{upd[:release]}"
- else
- # Yum didn't find updates, pretend the current
- # version is the latest
- raise Puppet::DevError, "Tried to get latest on a missing package" if properties[:ensure] == :absent
- return properties[:ensure]
- end
+ end
+
+ def install
+ should = @resource.should(:ensure)
+ self.debug "Ensuring => #{should}"
+ wanted = @resource[:name]
+
+ # XXX: We don't actually deal with epochs here.
+ case should
+ when true, false, Symbol
+ # pass
+ should = nil
+ else
+ # Add the package version
+ wanted += "-#{should}"
end
- def update
- # Install in yum can be used for update, too
- self.install
+ output = yum "-d", "0", "-e", "0", "-y", :install, wanted
+
+ is = self.query
+ raise Puppet::Error, "Could not find package #{self.name}" unless is
+
+ # FIXME: Should we raise an exception even if should == :latest
+ # and yum updated us to a version other than @param_hash[:ensure] ?
+ raise Puppet::Error, "Failed to update to version #{should}, got version #{is[:ensure]} instead" if should && should != is[:ensure]
+ end
+
+ # What's the latest package version available?
+ def latest
+ upd = latest_info
+ unless upd.nil?
+ # FIXME: there could be more than one update for a package
+ # because of multiarch
+ return "#{upd[:version]}-#{upd[:release]}"
+ else
+ # Yum didn't find updates, pretend the current
+ # version is the latest
+ raise Puppet::DevError, "Tried to get latest on a missing package" if properties[:ensure] == :absent
+ return properties[:ensure]
end
+ end
- def purge
- yum "-y", :erase, @resource[:name]
- end
+ def update
+ # Install in yum can be used for update, too
+ self.install
+ end
+
+ def purge
+ yum "-y", :erase, @resource[:name]
+ end
end