diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-04-05 08:08:00 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-04-05 08:08:00 +0000 |
| commit | 013cfd22f9148f9ba980455e81bad6c8373fea92 (patch) | |
| tree | 84af0e4d3e40e91444efbe8ffafaa045675be0ce /lib/puppet | |
| parent | 9697354e81d72027519119753598bd3c5271bbcf (diff) | |
| download | puppet-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
Diffstat (limited to 'lib/puppet')
| -rw-r--r-- | lib/puppet/type/package.rb | 14 | ||||
| -rwxr-xr-x | lib/puppet/type/package/darwinport.rb | 97 |
2 files changed, 99 insertions, 12 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$ |
