summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-09-27 19:59:36 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-09-27 19:59:36 +0000
commit9464224df2045bee3dbcf27706c4262c964e4106 (patch)
tree4a09adb07853acbe1e6540e4983ec4e4b7686225 /lib
parentf48f14ab4df7c2d3e327b3317503a181cbe13ecb (diff)
downloadpuppet-9464224df2045bee3dbcf27706c4262c964e4106.tar.gz
puppet-9464224df2045bee3dbcf27706c4262c964e4106.tar.xz
puppet-9464224df2045bee3dbcf27706c4262c964e4106.zip
moving specific packaging support into separate files
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@707 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/type/package.rb322
-rwxr-xr-xlib/puppet/type/package/apt.rb22
-rwxr-xr-xlib/puppet/type/package/dpkg.rb108
-rwxr-xr-xlib/puppet/type/package/rpm.rb82
-rwxr-xr-xlib/puppet/type/package/sun.rb117
5 files changed, 333 insertions, 318 deletions
diff --git a/lib/puppet/type/package.rb b/lib/puppet/type/package.rb
index 3306b38b7..f08410912 100644
--- a/lib/puppet/type/package.rb
+++ b/lib/puppet/type/package.rb
@@ -4,327 +4,13 @@
# systems.
require 'puppet/type/state'
+require 'puppet/type/package/dpkg.rb'
+require 'puppet/type/package/apt.rb'
+require 'puppet/type/package/rpm.rb'
+require 'puppet/type/package/sun.rb'
module Puppet
class PackageError < Puppet::Error; end
-
- module PackagingType
- # The packaging system for Debian systems.
- module DPKG
- 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, :version, :description]
-
- hash = {}
- # list out our specific package
- open("| dpkg -l %s 2>/dev/null" % self.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
-
- line = lines[-1]
-
- 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
- end
- }
- ENV["COLUMNS"] = oldcol
-
- if hash[:error] != " "
- raise Puppet::PackageError.new(
- "Package %s, version %s is in error state: %s" %
- [hash[:name], hash[:install], hash[:error]]
- )
- end
-
- if hash[:status] == "i"
- hash[:install] = hash[:version]
- else
- hash[:install] = :notinstalled
- end
-
- return hash
- end
-
- def 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("| dpkg -l") { |process|
- # our regex for matching dpkg output
- regex = %r{^(\S+)\s+(\S+)\s+(\S+)\s+(.+)$}
- fields = [:status, :name, :install, :description]
- 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)
- hash.clear
-
- 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
- end
- }
- }
- ENV["COLUMNS"] = oldcol
-
- return packages
- end
-
- def remove
- cmd = "dpkg -r %s" % self.name
- output = %x{#{cmd} 2>&1}
- if $? != 0
- raise Puppet::PackageError.new(output)
- end
- end
- end
-
- # A derivative of DPKG; this is how most people actually manage
- # Debian boxes, and the only thing that differs is that it can
- # install packages from remote sites.
- module APT
- include DPKG
-
- # Install a package using 'apt-get'.
- def install
- cmd = "apt-get install %s" % self.name
-
- Puppet.info "Executing %s" % cmd.inspect
- output = %x{#{cmd} 2>&1}
-
- unless $? == 0
- raise Puppet::PackageError.new(output)
- end
- end
- end
-
- module RPM
- def query
- fields = {
- :name => "NAME",
- :install => "VERSION",
- :description => "DESCRIPTION"
- }
-
- cmd = "rpm -q --qf '%s\n'" %
- %w{NAME VERSION DESCRIPTION}.collect { |str|
- "%{#{str}}"
- }.join(" ")
-
- # list out all of the packages
- str = %x{#{cmd} 2>/dev/null}.chomp
-
- if $? != 0
- return nil
- end
-
- regex = %r{^(\S+)\s+(\S+)\s+(.+)}
- fields = [:name, :install, :description]
- hash = {}
- if match = regex.match(str)
- fields.zip(match.captures) { |field,value|
- hash[field] = value
- }
- else
- raise Puppet::DevError,
- "Failed to match rpm output '%s'" %
- str
- end
-
- return hash
- end
-
- def list
- packages = []
-
- # list out all of the packages
- open("| rpm -q -a --qf '%{NAME} %{VERSION}\n'") { |process|
- # our regex for matching dpkg output
- regex = %r{^(\S+)\s+(\S+)}
- fields = [:name, :install]
- hash = {}
-
- # now turn each returned line into a package object
- process.each { |line|
- if match = regex.match(line)
- hash.clear
-
- fields.zip(match.captures) { |field,value|
- hash[field] = value
- }
- packages.push Puppet::Type::Package.installedpkg(hash)
- else
- raise "failed to match rpm line %s" % line
- end
- }
- }
-
- return packages
- end
-
- # we need package retrieval mechanisms before we can have package
- # installation mechanisms...
- #type.install = proc { |pkg|
- # raise "installation not implemented yet"
- #}
-
- def remove
- cmd = "rpm -e %s" % self.name
- output = %x{#{cmd}}
- if $? != 0
- raise output
- end
- end
- end
-
- module Sun
- def query
- names = {
- "PKGINST" => :name,
- "NAME" => nil,
- "CATEGORY" => :category,
- "ARCH" => :platform,
- "VERSION" => :install,
- "BASEDIR" => :root,
- "HOTLINE" => nil,
- "EMAIL" => nil,
- "VENDOR" => :vendor,
- "DESC" => :description,
- "PSTAMP" => nil,
- "INSTDATE" => nil,
- "STATUS" => nil,
- "FILES" => nil
- }
-
- hash = {}
-
- # list out all of the packages
- open("| pkginfo -l %s 2>/dev/null" % self.name) { |process|
- # we're using the long listing, so each line is a separate
- # piece of information
- process.each { |line|
- case line
- when /^$/: # ignore
- when /\s*([A-Z]+):\s+(.+)/:
- name = $1
- value = $2
- if names.include?(name)
- unless names[name].nil?
- hash[names[name]] = value
- end
- else
- Puppet.err "'pkginfo' returned invalid name %s" %
- name
- end
- when /\s+\d+.+/:
- # nothing; we're ignoring the FILES info
- end
- }
- }
-
- if hash.empty?
- return nil
- else
- return hash
- end
- end
-
- def list
- packages = []
- hash = {}
- names = {
- "PKGINST" => :name,
- "NAME" => nil,
- "CATEGORY" => :category,
- "ARCH" => :platform,
- "VERSION" => :install,
- "BASEDIR" => :root,
- "HOTLINE" => nil,
- "EMAIL" => nil,
- "VENDOR" => :vendor,
- "DESC" => :description,
- "PSTAMP" => nil,
- "INSTDATE" => nil,
- "STATUS" => nil,
- "FILES" => nil
- }
-
- # list out all of the packages
- open("| pkginfo -l") { |process|
- # we're using the long listing, so each line is a separate
- # piece of information
- process.each { |line|
- case line
- when /^$/:
- packages.push Puppet::Type::Package.installedpkg(hash)
- hash.clear
- when /\s*(\w+):\s+(.+)/:
- name = $1
- value = $2
- if names.include?(name)
- unless names[name].nil?
- hash[names[name]] = value
- end
- else
- raise "Could not find %s" % name
- end
- when /\s+\d+.+/:
- # nothing; we're ignoring the FILES info
- end
- }
- }
- return packages
- end
-
- # we need package retrieval mechanisms before we can have package
- # installation mechanisms...
- #type.install = proc { |pkg|
- # raise "installation not implemented yet"
- #}
-
- def remove
- cmd = "pkgrm -n %s" % self.name
- output = %x{#{cmd}}
- if $? != 0
- raise output
- end
- end
- end
- end
-
class State
class PackageInstalled < Puppet::State
@name = :install
diff --git a/lib/puppet/type/package/apt.rb b/lib/puppet/type/package/apt.rb
new file mode 100755
index 000000000..dd4e69d50
--- /dev/null
+++ b/lib/puppet/type/package/apt.rb
@@ -0,0 +1,22 @@
+module Puppet
+ module PackagingType
+ # A derivative of DPKG; this is how most people actually manage
+ # Debian boxes, and the only thing that differs is that it can
+ # install packages from remote sites.
+ module APT
+ include DPKG
+
+ # Install a package using 'apt-get'.
+ def install
+ cmd = "apt-get install %s" % self.name
+
+ Puppet.info "Executing %s" % cmd.inspect
+ output = %x{#{cmd} 2>&1}
+
+ unless $? == 0
+ raise Puppet::PackageError.new(output)
+ end
+ end
+ end
+ end
+end
diff --git a/lib/puppet/type/package/dpkg.rb b/lib/puppet/type/package/dpkg.rb
new file mode 100755
index 000000000..1d9b54aaf
--- /dev/null
+++ b/lib/puppet/type/package/dpkg.rb
@@ -0,0 +1,108 @@
+module Puppet
+ module PackagingType
+ # The packaging system for Debian systems.
+ module DPKG
+ 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, :version, :description]
+
+ hash = {}
+ # list out our specific package
+ open("| dpkg -l %s 2>/dev/null" % self.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
+
+ line = lines[-1]
+
+ 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
+ end
+ }
+ ENV["COLUMNS"] = oldcol
+
+ if hash[:error] != " "
+ raise Puppet::PackageError.new(
+ "Package %s, version %s is in error state: %s" %
+ [hash[:name], hash[:install], hash[:error]]
+ )
+ end
+
+ if hash[:status] == "i"
+ hash[:install] = hash[:version]
+ else
+ hash[:install] = :notinstalled
+ end
+
+ return hash
+ end
+
+ def 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("| dpkg -l") { |process|
+ # our regex for matching dpkg output
+ regex = %r{^(\S+)\s+(\S+)\s+(\S+)\s+(.+)$}
+ fields = [:status, :name, :install, :description]
+ 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)
+ hash.clear
+
+ 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
+ end
+ }
+ }
+ ENV["COLUMNS"] = oldcol
+
+ return packages
+ end
+
+ def remove
+ cmd = "dpkg -r %s" % self.name
+ output = %x{#{cmd} 2>&1}
+ if $? != 0
+ raise Puppet::PackageError.new(output)
+ end
+ end
+ end
+ end
+end
+
+# $Id$
diff --git a/lib/puppet/type/package/rpm.rb b/lib/puppet/type/package/rpm.rb
new file mode 100755
index 000000000..3b195dcbc
--- /dev/null
+++ b/lib/puppet/type/package/rpm.rb
@@ -0,0 +1,82 @@
+module Puppet
+ module PackagingType
+ module RPM
+ def query
+ fields = {
+ :name => "NAME",
+ :install => "VERSION",
+ :description => "DESCRIPTION"
+ }
+
+ cmd = "rpm -q --qf '%s\n'" %
+ %w{NAME VERSION DESCRIPTION}.collect { |str|
+ "%{#{str}}"
+ }.join(" ")
+
+ # list out all of the packages
+ str = %x{#{cmd} 2>/dev/null}.chomp
+
+ if $? != 0
+ return nil
+ end
+
+ regex = %r{^(\S+)\s+(\S+)\s+(.+)}
+ fields = [:name, :install, :description]
+ hash = {}
+ if match = regex.match(str)
+ fields.zip(match.captures) { |field,value|
+ hash[field] = value
+ }
+ else
+ raise Puppet::DevError,
+ "Failed to match rpm output '%s'" %
+ str
+ end
+
+ return hash
+ end
+
+ def list
+ packages = []
+
+ # list out all of the packages
+ open("| rpm -q -a --qf '%{NAME} %{VERSION}\n'") { |process|
+ # our regex for matching dpkg output
+ regex = %r{^(\S+)\s+(\S+)}
+ fields = [:name, :install]
+ hash = {}
+
+ # now turn each returned line into a package object
+ process.each { |line|
+ if match = regex.match(line)
+ hash.clear
+
+ fields.zip(match.captures) { |field,value|
+ hash[field] = value
+ }
+ packages.push Puppet::Type::Package.installedpkg(hash)
+ else
+ raise "failed to match rpm line %s" % line
+ end
+ }
+ }
+
+ return packages
+ end
+
+ # we need package retrieval mechanisms before we can have package
+ # installation mechanisms...
+ #type.install = proc { |pkg|
+ # raise "installation not implemented yet"
+ #}
+
+ def remove
+ cmd = "rpm -e %s" % self.name
+ output = %x{#{cmd}}
+ if $? != 0
+ raise output
+ end
+ end
+ end
+ end
+end
diff --git a/lib/puppet/type/package/sun.rb b/lib/puppet/type/package/sun.rb
new file mode 100755
index 000000000..c3190995b
--- /dev/null
+++ b/lib/puppet/type/package/sun.rb
@@ -0,0 +1,117 @@
+module Puppet
+ module PackagingType
+ module Sun
+ def query
+ names = {
+ "PKGINST" => :name,
+ "NAME" => nil,
+ "CATEGORY" => :category,
+ "ARCH" => :platform,
+ "VERSION" => :install,
+ "BASEDIR" => :root,
+ "HOTLINE" => nil,
+ "EMAIL" => nil,
+ "VENDOR" => :vendor,
+ "DESC" => :description,
+ "PSTAMP" => nil,
+ "INSTDATE" => nil,
+ "STATUS" => nil,
+ "FILES" => nil
+ }
+
+ hash = {}
+
+ # list out all of the packages
+ open("| pkginfo -l %s 2>/dev/null" % self.name) { |process|
+ # we're using the long listing, so each line is a separate
+ # piece of information
+ process.each { |line|
+ case line
+ when /^$/: # ignore
+ when /\s*([A-Z]+):\s+(.+)/:
+ name = $1
+ value = $2
+ if names.include?(name)
+ unless names[name].nil?
+ hash[names[name]] = value
+ end
+ else
+ Puppet.err "'pkginfo' returned invalid name %s" %
+ name
+ end
+ when /\s+\d+.+/:
+ # nothing; we're ignoring the FILES info
+ end
+ }
+ }
+
+ if hash.empty?
+ return nil
+ else
+ return hash
+ end
+ end
+
+ def list
+ packages = []
+ hash = {}
+ names = {
+ "PKGINST" => :name,
+ "NAME" => nil,
+ "CATEGORY" => :category,
+ "ARCH" => :platform,
+ "VERSION" => :install,
+ "BASEDIR" => :root,
+ "HOTLINE" => nil,
+ "EMAIL" => nil,
+ "VENDOR" => :vendor,
+ "DESC" => :description,
+ "PSTAMP" => nil,
+ "INSTDATE" => nil,
+ "STATUS" => nil,
+ "FILES" => nil
+ }
+
+ # list out all of the packages
+ open("| pkginfo -l") { |process|
+ # we're using the long listing, so each line is a separate
+ # piece of information
+ process.each { |line|
+ case line
+ when /^$/:
+ packages.push Puppet::Type::Package.installedpkg(hash)
+ hash.clear
+ when /\s*(\w+):\s+(.+)/:
+ name = $1
+ value = $2
+ if names.include?(name)
+ unless names[name].nil?
+ hash[names[name]] = value
+ end
+ else
+ raise "Could not find %s" % name
+ end
+ when /\s+\d+.+/:
+ # nothing; we're ignoring the FILES info
+ end
+ }
+ }
+ return packages
+ end
+
+ # we need package retrieval mechanisms before we can have package
+ # installation mechanisms...
+ #type.install = proc { |pkg|
+ # raise "installation not implemented yet"
+ #}
+
+ def remove
+ cmd = "pkgrm -n %s" % self.name
+ output = %x{#{cmd}}
+ if $? != 0
+ raise output
+ end
+ end
+ end
+ end
+end