summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-04-05 08:08:00 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-04-05 08:08:00 +0000
commit013cfd22f9148f9ba980455e81bad6c8373fea92 (patch)
tree84af0e4d3e40e91444efbe8ffafaa045675be0ce
parent9697354e81d72027519119753598bd3c5271bbcf (diff)
downloadpuppet-013cfd22f9148f9ba980455e81bad6c8373fea92.tar.gz
puppet-013cfd22f9148f9ba980455e81bad6c8373fea92.tar.xz
puppet-013cfd22f9148f9ba980455e81bad6c8373fea92.zip
Adding darwinport type.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1080 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/type/package.rb14
-rwxr-xr-xlib/puppet/type/package/darwinport.rb97
-rw-r--r--test/types/package.rb28
3 files changed, 113 insertions, 26 deletions
diff --git a/lib/puppet/type/package.rb b/lib/puppet/type/package.rb
index 387a3c451..c10dd72ec 100644
--- a/lib/puppet/type/package.rb
+++ b/lib/puppet/type/package.rb
@@ -33,12 +33,12 @@ module Puppet
# Add our parent, if it exists
if parent
- unless @pkgtypes.include?(parent)
+ unless parenttype = pkgtype(parent)
raise Puppet::DevError,
"No parent type %s for package type %s" %
[parent, name]
end
- mod.send(:include, @pkgtypes[parent])
+ mod.send(:include, parenttype)
end
# And now define the support methods
@@ -578,14 +578,4 @@ module Puppet
}
end
-# The order these are loaded is important.
-require 'puppet/type/package/dpkg'
-require 'puppet/type/package/apt'
-require 'puppet/type/package/rpm'
-require 'puppet/type/package/yum'
-require 'puppet/type/package/sun'
-require 'puppet/type/package/openbsd'
-require 'puppet/type/package/freebsd'
-require 'puppet/type/package/apple'
-
# $Id$
diff --git a/lib/puppet/type/package/darwinport.rb b/lib/puppet/type/package/darwinport.rb
new file mode 100755
index 000000000..0d8fc288d
--- /dev/null
+++ b/lib/puppet/type/package/darwinport.rb
@@ -0,0 +1,97 @@
+module Puppet
+ Puppet.type(:package).newpkgtype(:darwinport) do
+ def port
+ "/opt/local/bin/port"
+ end
+
+ def eachpkgashash
+ # list out all of the packages
+ open("| #{port} list installed") { |process|
+ regex = %r{(\S+)\s+@(\S+)\s+(\S+)}
+ fields = [:name, :version, :location]
+ hash = {}
+
+ # now turn each returned line into a package object
+ process.each { |line|
+ hash.clear
+
+ if match = regex.match(line)
+ fields.zip(match.captures) { |field,value|
+ hash[field] = value
+ }
+
+ hash.delete :location
+ hash[:ensure] = hash[:version]
+ yield hash.dup
+ else
+ raise Puppet::DevError,
+ "Failed to match dpkg line %s" % line
+ end
+ }
+ }
+ end
+
+ def install
+ should = self.should(:ensure)
+
+ # Seems like you can always say 'upgrade'
+ cmd = "#{port()} upgrade #{self[:name]}"
+
+ self.info "Executing %s" % cmd.inspect
+ output = %x{#{cmd} 2>&1}
+
+ unless $? == 0
+ raise Puppet::PackageError.new(output)
+ end
+ end
+
+ def list
+ packages = []
+
+ eachpkgashash do |hash|
+ pkg = Puppet.type(:package).installedpkg(hash)
+ packages << pkg
+ end
+
+ return packages
+ end
+
+ def query
+ version = nil
+ eachpkgashash do |hash|
+ if hash[:name] == self[:name]
+ return hash
+ end
+ end
+
+ return nil
+ end
+
+ def latest
+ info = %x{#{port()} search '^#{self[:name]}$' 2>/dev/null}
+
+ if $? != 0 or info =~ /^Error/
+ return nil
+ end
+
+ ary = info.split(/\s+/)
+ version = ary[2].sub(/^@/, '')
+
+ return version
+ end
+
+ def uninstall
+ cmd = "#{port()} uninstall #{self[:name]}"
+ output = %x{#{cmd} 2>&1}
+ if $? != 0
+ raise Puppet::PackageError.new(output)
+ end
+ end
+
+ def update
+ return install()
+ end
+ end
+end
+
+# $Id$
diff --git a/test/types/package.rb b/test/types/package.rb
index a2e2d6f5c..9ada675e6 100644
--- a/test/types/package.rb
+++ b/test/types/package.rb
@@ -43,8 +43,9 @@ class TestPackages < Test::Unit::TestCase
pkgs = %w{SMCossh}
when "Debian": pkgs = %w{ssh openssl}
when "Fedora": pkgs = %w{openssh}
- when "OpenBSD": pkgs = %{vim}
- when "FreeBSD": pkgs = %{sudo}
+ when "OpenBSD": pkgs = %w{vim}
+ when "FreeBSD": pkgs = %w{sudo}
+ when "Darwin": pkgs = %w{gettext}
else
Puppet.notice "No test package for %s" % $platform
return []
@@ -60,13 +61,17 @@ class TestPackages < Test::Unit::TestCase
end
end
- def mkpkgs
- tstpkgs().each { |pkg, source|
+ def mkpkgs(list = nil)
+ list ||= tstpkgs()
+ list.each { |pkg, source|
hash = {:name => pkg, :ensure => "latest"}
if source
source = source[0] if source.is_a? Array
hash[:source] = source
end
+ if Facter["operatingsystem"].value == "Darwin"
+ hash[:type] = "darwinport"
+ end
obj = Puppet.type(:package).create(hash)
modpkg(obj)
@@ -102,6 +107,8 @@ class TestPackages < Test::Unit::TestCase
"/home/luke/rpm/RPMS/noarch/enhost-1.0.1-1.noarch.rpm",
"/home/luke/rpm/RPMS/noarch/enhost-1.0.2-1.noarch.rpm"
]}
+ when "Darwin":
+ retval = {"aop" => nil}
else
Puppet.notice "No test packages for %s" % $platform
end
@@ -123,13 +130,7 @@ class TestPackages < Test::Unit::TestCase
end
def test_retrievepkg
- installedpkgs().each { |pkg|
- obj = nil
- assert_nothing_raised {
- obj = Puppet.type(:package).create(
- :name => pkg
- )
- }
+ mkpkgs(installedpkgs()) { |obj|
assert(obj, "could not create package")
@@ -208,8 +209,6 @@ class TestPackages < Test::Unit::TestCase
assert_events([:package_removed], comp, "package")
# and now set install to 'latest' and verify it installs
- # FIXME this isn't really a very good test -- we should install
- # a low version, and then upgrade using this. But, eh.
if pkg.respond_to?(:latest)
assert_nothing_raised {
pkg[:ensure] = "latest"
@@ -288,7 +287,8 @@ class TestPackages < Test::Unit::TestCase
end
# Stupid darwin, not supporting package uninstallation
- if Facter["operatingsystem"].value == "Darwin"
+ if Facter["operatingsystem"].value == "Darwin" and
+ FileTest.exists? "/Users/luke/Documents/Puppet/pkgtesting.pkg"
def test_darwinpkgs
pkg = nil
assert_nothing_raised {