From: Dominic Cleal <dcl...@redhat.com>
Signed-off-by: Juerg Walz <jw...@pobox.com> --- Local-branch: tickets/master/4258-dev lib/puppet/provider/package/pkgutil.rb | 212 ++++++++++++++++---------------- 1 files changed, 106 insertions(+), 106 deletions(-) diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb index b80cf74..4e2c0d9 100755 --- a/lib/puppet/provider/package/pkgutil.rb +++ b/lib/puppet/provider/package/pkgutil.rb @@ -1,129 +1,129 @@ # Packaging using Peter Bonivart's pkgutil program. Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun do - desc "Package management using Peter Bonivart's ``pkgutil`` command on Solaris." - pkguti = "pkgutil" - if FileTest.executable?("/opt/csw/bin/pkgutil") - pkguti = "/opt/csw/bin/pkgutil" - end + desc "Package management using Peter Bonivart's ``pkgutil`` command on Solaris." + pkguti = "pkgutil" + if FileTest.executable?("/opt/csw/bin/pkgutil") + pkguti = "/opt/csw/bin/pkgutil" + end - confine :operatingsystem => :solaris + confine :operatingsystem => :solaris - commands :pkguti => pkguti + commands :pkguti => pkguti - # This is so stupid, but then, so is blastwave. - ENV["PAGER"] = "/usr/bin/cat" + # This is so stupid, but then, so is blastwave. + ENV["PAGER"] = "/usr/bin/cat" - def self.extended(mod) - unless command(:pkguti) != "pkgutil" - raise Puppet::Error, - "The pkgutil command is missing; pkgutil packaging unavailable" - end + def self.extended(mod) + unless command(:pkguti) != "pkgutil" + raise Puppet::Error, + "The pkgutil command is missing; pkgutil packaging unavailable" + end - unless FileTest.exists?("/var/opt/csw/pkgutil/admin") - Puppet.notice "It is highly recommended you create '/var/opt/csw/pkgutil/admin'." - Puppet.notice "See /var/opt/csw/pkgutil" - end + unless FileTest.exists?("/var/opt/csw/pkgutil/admin") + Puppet.notice "It is highly recommended you create '/var/opt/csw/pkgutil/admin'." + Puppet.notice "See /var/opt/csw/pkgutil" end + end - def self.instances(hash = {}) - blastlist(hash).collect do |bhash| - bhash.delete(:avail) - new(bhash) - end + def self.instances(hash = {}) + blastlist(hash).collect do |bhash| + bhash.delete(:avail) + new(bhash) end + end - # Turn our blastwave listing into a bunch of hashes. - def self.blastlist(hash) - command = ["-c"] - - if hash[:justme] - # The --single option speeds up the execution, because it queries - # the package managament system for one package only. - command << ["--single"] - command << hash[:justme] - end - - output = pkguti command - - list = output.split("\n").collect do |line| - next if line =~ /^#/ - next if line =~ /installed\s+catalog/ # header of package list - next if line =~ /^Checking integrity / # use_gpg - next if line =~ /^gpg: / # gpg verification - next if line =~ /^=+> / # catalog fetch - next if line =~ /\d+:\d+:\d+ URL:/ # wget without -q - - parsed = blastsplit(line) - - # When finding one package, ensure we picked up the package line - # itself, not any pkgutil noise. - next if hash[:justme] and parsed[:name] != hash[:justme] - - parsed - end.reject { |h| h.nil? } - - if hash[:justme] - return list[-1] - else - list.reject! { |h| - h[:ensure] == :absent - } - return list - end + # Turn our blastwave listing into a bunch of hashes. + def self.blastlist(hash) + command = ["-c"] + if hash[:justme] + # The --single option speeds up the execution, because it queries + # the package managament system for one package only. + command << ["--single"] + command << hash[:justme] end - # Split the different lines into hashes. - def self.blastsplit(line) - if line =~ /\s*(\S+)\s+(\S+)\s+(.*)/ - hash = {} - hash[:name] = $1 - hash[:ensure] = if $2 == "notinst" - :absent - else - $2 - end - hash[:avail] = $3 - - if hash[:avail] == "SAME" - hash[:avail] = hash[:ensure] - end - - # Use the name method, so it works with subclasses. - hash[:provider] = self.name - - return hash - else - Puppet.warning "Cannot match %s" % line - return nil - end - end + output = pkguti command - def install - pkguti "-y", "-i", @resource[:name] - end + list = output.split("\n").collect do |line| + next if line =~ /^#/ + next if line =~ /installed\s+catalog/ # header of package list + next if line =~ /^Checking integrity / # use_gpg + next if line =~ /^gpg: / # gpg verification + next if line =~ /^=+> / # catalog fetch + next if line =~ /\d+:\d+:\d+ URL:/ # wget without -q - # Retrieve the version from the current package file. - def latest - hash = self.class.blastlist(:justme => @resource[:name]) - hash[:avail] - end + parsed = blastsplit(line) - def query - if hash = self.class.blastlist(:justme => @resource[:name]) - hash - else - {:ensure => :absent} - end - end + # When finding one package, ensure we picked up the package line + # itself, not any pkgutil noise. + next if hash[:justme] and parsed[:name] != hash[:justme] + + parsed + end.reject { |h| h.nil? } - # Remove the old package, and install the new one - def update - pkguti "-y", "-i", @resource[:name] + if hash[:justme] + return list[-1] + else + list.reject! { |h| + h[:ensure] == :absent + } + return list end - def uninstall - pkguti "-y", "-r", @resource[:name] + end + + # Split the different lines into hashes. + def self.blastsplit(line) + if line =~ /\s*(\S+)\s+(\S+)\s+(.*)/ + hash = {} + hash[:name] = $1 + hash[:ensure] = if $2 == "notinst" + :absent + else + $2 + end + hash[:avail] = $3 + + if hash[:avail] == "SAME" + hash[:avail] = hash[:ensure] + end + + # Use the name method, so it works with subclasses. + hash[:provider] = self.name + + return hash + else + Puppet.warning "Cannot match %s" % line + return nil + end + end + + def install + pkguti "-y", "-i", @resource[:name] + end + + # Retrieve the version from the current package file. + def latest + hash = self.class.blastlist(:justme => @resource[:name]) + hash[:avail] + end + + def query + if hash = self.class.blastlist(:justme => @resource[:name]) + hash + else + {:ensure => :absent} end + end + + # Remove the old package, and install the new one + def update + pkguti "-y", "-i", @resource[:name] + end + + def uninstall + pkguti "-y", "-r", @resource[:name] + end end -- 1.7.3.2 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to puppet-dev@googlegroups.com. To unsubscribe from this group, send email to puppet-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.