summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-09-15 16:54:50 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-09-15 16:54:50 +0000
commitcda7253b2da3b6980f5cf2846f631597ef249000 (patch)
tree1baff996588ac9a66cea1cf3efe3c27081778bed /lib
parent521920592a526f4dee720daf1de0a55748ac5648 (diff)
downloadpuppet-cda7253b2da3b6980f5cf2846f631597ef249000.tar.gz
puppet-cda7253b2da3b6980f5cf2846f631597ef249000.tar.xz
puppet-cda7253b2da3b6980f5cf2846f631597ef249000.zip
Adding patch from #235
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1612 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rwxr-xr-xlib/puppet/provider/package/dpkg.rb54
-rw-r--r--lib/puppet/type/state.rb2
2 files changed, 17 insertions, 39 deletions
diff --git a/lib/puppet/provider/package/dpkg.rb b/lib/puppet/provider/package/dpkg.rb
index 56ffe95f5..84fba92e8 100755
--- a/lib/puppet/provider/package/dpkg.rb
+++ b/lib/puppet/provider/package/dpkg.rb
@@ -4,25 +4,18 @@ Puppet::Type.type(:package).provide :dpkg do
to manage."
commands :dpkg => "/usr/bin/dpkg"
-
+ commands :dpkgquery => "/usr/bin/dpkg-query"
+
def self.list
packages = []
- # dpkg only prints as many columns as you have available
- # which means we don't get all of the info
- # stupid stupid
- oldcol = ENV["COLUMNS"]
- ENV["COLUMNS"] = "500"
-
# list out all of the packages
- open("| #{command(:dpkg)} -l") { |process|
+ open("| #{command(:dpkgquery)} -W --showformat '${Status} ${Package} ${Version}\\n'") { |process|
# our regex for matching dpkg output
- regex = %r{^(\S+)\s+(\S+)\s+(\S+)\s+(.+)$}
- fields = [:status, :name, :ensure, :description]
+ regex = %r{^(\S+ +\S+ +\S+) (\S+) (\S+)$}
+ fields = [:status, :name, :ensure]
hash = {}
- 5.times { process.gets } # throw away the header
-
# now turn each returned line into a package object
process.each { |line|
if match = regex.match(line)
@@ -37,11 +30,10 @@ Puppet::Type.type(:package).provide :dpkg do
packages.push Puppet.type(:package).installedpkg(hash)
else
raise Puppet::DevError,
- "Failed to match dpkg line %s" % line
+ "Failed to match dpkg-query line %s" % line
end
}
}
- ENV["COLUMNS"] = oldcol
return packages
end
@@ -49,42 +41,28 @@ Puppet::Type.type(:package).provide :dpkg do
def query
packages = []
- # dpkg only prints as many columns as you have available
- # which means we don't get all of the info
- # stupid stupid
- oldcol = ENV["COLUMNS"]
- ENV["COLUMNS"] = "500"
- fields = [:desired, :status, :error, :name, :ensure, :description]
+ fields = [:desired, :error, :status, :name, :ensure]
hash = {}
# list out our specific package
- open("| #{command(:dpkg)} -l %s 2>/dev/null" % @model[:name]) { |process|
- # our regex for matching dpkg output
- regex = %r{^(.)(.)(.)\s(\S+)\s+(\S+)\s+(.+)$}
-
- # we only want the last line
- lines = process.readlines
- # we've got four header lines, so we should expect all of those
- # plus our output
- if lines.length < 5
- return nil
- end
+ open("| #{command(:dpkgquery)} -W --showformat '${Status} ${Package} ${Version}\\n' %s" % @model[:name]) { |process|
+ # our regex for matching dpkg-query output
+ regex = %r{^(\S+) (\S+) (\S+) (\S+) (\S+)$}
- line = lines[-1]
+ lines = process.readlines.collect {|l| l.chomp }
+ line = lines[0]
+
if match = regex.match(line)
fields.zip(match.captures) { |field,value|
hash[field] = value
}
- #packages.push Puppet.type(:package).installedpkg(hash)
else
- raise Puppet::DevError,
- "failed to match dpkg line %s" % line
+ hash = {:ensure => :absent, :status => 'missing', :name => @model[:name], :error => 'ok'}
end
}
- ENV["COLUMNS"] = oldcol
- if hash[:error] != " "
+ if hash[:error] != "ok"
raise Puppet::PackageError.new(
"Package %s, version %s is in error state: %s" %
[hash[:name], hash[:ensure], hash[:error]]
@@ -92,7 +70,7 @@ Puppet::Type.type(:package).provide :dpkg do
end
# DPKG can discuss packages that are no longer installed, so allow that.
- if hash[:status] != "i"
+ if hash[:status] != "installed"
hash[:ensure] = :absent
end
diff --git a/lib/puppet/type/state.rb b/lib/puppet/type/state.rb
index de0cfeb00..e372db6db 100644
--- a/lib/puppet/type/state.rb
+++ b/lib/puppet/type/state.rb
@@ -257,7 +257,7 @@ class State < Puppet::Parameter
rescue Puppet::Error
raise
rescue => detail
- if Puppet[:debug]
+ if Puppet[:trace]
puts detail.backtrace
end
self.fail "Could not set %s on %s: %s" %