Manually posting code from his branch in the ticket to the list for comment
/ review.

-- M
-----------------------------------------------------------
The power of accurate observation is
commonly called cynicism by those
who have not got it.  ~George Bernard Shaw
------------------------------------------------------------

commit 303cc8165db4fa7058a352a30e868eb714fee7f7
Merge: 9bab0cb 93baac5
Author: Russell Jackson <[email protected]>
Date:   Wed Oct 13 17:09:55 2010 -0700

    Merge branch '2.6.x' of git://github.com/reductivelabs/puppet into
freebsd/2.6.x/package_origin

commit 9bab0cb6f87d5a7c99913f5521bcecc0cac27771
Author: Russell Jackson <[email protected]>
Date:   Wed Oct 13 17:05:38 2010 -0700

    Use uri library.
    Refactor.

diff --git a/lib/puppet/provider/package/freebsd.rb
b/lib/puppet/provider/package/freebsd.rb
index 5f6f1c2..4825222 100755
--- a/lib/puppet/provider/package/freebsd.rb
+++ b/lib/puppet/provider/package/freebsd.rb
@@ -17,7 +17,7 @@ Puppet::Type.type(:package).provide :freebsd, :parent =>
:openbsd do
     output = pkginfo "-aoQ"
     output.split("\n").each do |data|
       lhs, pkg_origin = data.split(":")
-      pkg_name = lhs.split("-")[0..-2].join("-")
+      pkg_name = lhs.split("-").slice(0..-2).join("-")
       pkg_version = lhs.split("-")[-1]

       packages << new({
@@ -27,7 +27,7 @@ Puppet::Type.type(:package).provide :freebsd, :parent =>
:openbsd do
       })
     end

-    return packages
+    packages
   end

   def install
@@ -35,25 +35,44 @@ Puppet::Type.type(:package).provide :freebsd, :parent =>
:openbsd do

     origin = {}
     [:category, :name].zip(@resource[:name].split("/")).each { |a,b|
origin[a] = b }
+    Puppet.debug "origin => #{origin.inspect}"
     if origin[:name] == nil
       raise Puppet::Error.new "package name must be in origin format:
<category>/<name>"
     end
-
-    if @resource[:source] =~ /^(ftp|https?):/
-      if @resource[:source] =~ /\/$/
-        # set PACKAGESITE to URL specified in source parameter
-        withenv :PACKAGESITE => @resource[:source] do
-          pkgadd "-r", origin[:name]
+
+    # source parameter is set
+    if @resource[:source]
+      source = URI.parse(@resource[:source])
+      Puppet.debug "source => #{source.inspect}"
+
+      # URI is for local file path.
+      if (source.scheme == "file" || source.scheme == nil) && source.path
+        # Pass pkg_add only the URI path.
+        pkgadd source.path
+
+      # URI scheme is something other than 'file'.
+      elsif source.scheme && source.host && source.path
+        if source.path.end_with?(".tbz") # URI references a package.
+          # Pass pkg_add the entire URI.
+          pkgadd source.to_s
+        else # Assume URI references a directory.
+          # Set PACKAGESITE in execution environment to source URI.
+          # Pass pkg_add the origin name.
+          withenv :PACKAGESITE => source.path.end_with?("/") ? source.to_s
: source.to_s << "/" do
+            Puppet.debug "ENV['PACKAGESITE'] => #{ENV['PACKAGESITE']}"
+            pkgadd "-r", origin[:name]
+          end
         end
+
+      # URI is not usable by pkg_add
       else
-        # fetch using fully qualified URL to package file
-        pkgadd "-r", @resource[:source]
+        raise Puppet::Error.new "source URI is inappropriate:
#{source.inspect}"
       end
-    elsif @resource[:source] != nil
-      # use local package file path specified in source parameter
-      pkgadd @resource[:source]
+
+    # source parameter is not set.
     else
-      # fetch using default PACKAGESITE and origin name
+      # fetch package using default PACKAGESITE directory logic.
+      # Pass pkg_add the origin name.
       pkgadd "-r", origin[:name]
     end
   end

commit 585e93e1ff05add8c8fbb0ff4870c3593b286d01
Author: Russell Jackson <[email protected]>
Date:   Tue Oct 12 15:55:54 2010 -0700

    Modify freebsd package provider to use port origin as resource name

diff --git a/lib/puppet/provider/package/freebsd.rb
b/lib/puppet/provider/package/freebsd.rb
index 2f012a4..5f6f1c2 100755
--- a/lib/puppet/provider/package/freebsd.rb
+++ b/lib/puppet/provider/package/freebsd.rb
@@ -1,36 +1,60 @@
 Puppet::Type.type(:package).provide :freebsd, :parent => :openbsd do
-  desc "The specific form of package management on FreeBSD.  This is an
-    extremely quirky packaging system, in that it freely mixes between
-    ports and packages.  Apparently all of the tools are written in Ruby,
-    so there are plans to rewrite this support to directly use those
-    libraries."
+  include Puppet::Util::Execution

-  commands :pkginfo => "/usr/sbin/pkg_info",
-    :pkgadd => "/usr/sbin/pkg_add",
-    :pkgdelete => "/usr/sbin/pkg_delete"
+  desc "The specific form of package management on FreeBSD. Resource names
must be
+  specified as the port origin: <port_category>/<port_name>."
+
+  commands :pkginfo    => "/usr/sbin/pkg_info",
+           :pkgadd     => "/usr/sbin/pkg_add",
+           :pkgdelete  => "/usr/sbin/pkg_delete"

   confine :operatingsystem => :freebsd
+  defaultfor :operatingsystem => :freebsd
+
+  def self.instances
+    packages = []
+
+    output = pkginfo "-aoQ"
+    output.split("\n").each do |data|
+      lhs, pkg_origin = data.split(":")
+      pkg_name = lhs.split("-")[0..-2].join("-")
+      pkg_version = lhs.split("-")[-1]
+
+      packages << new({
+        :provider => self.name,
+        :name     => pkg_origin,
+        :ensure   => pkg_version,
+      })
+    end

-  def self.listcmd
-    command(:pkginfo)
+    return packages
   end

   def install
     should = @resource.should(:ensure)
-
-    if @resource[:source] =~ /\/$/
-      if @resource[:source] =~ /^(ftp|https?):/
+
+    origin = {}
+    [:category, :name].zip(@resource[:name].split("/")).each { |a,b|
origin[a] = b }
+    if origin[:name] == nil
+      raise Puppet::Error.new "package name must be in origin format:
<category>/<name>"
+    end
+
+    if @resource[:source] =~ /^(ftp|https?):/
+      if @resource[:source] =~ /\/$/
+        # set PACKAGESITE to URL specified in source parameter
         withenv :PACKAGESITE => @resource[:source] do
-          pkgadd "-r", @resource[:name]
+          pkgadd "-r", origin[:name]
         end
       else
-        withenv :PKG_PATH => @resource[:source] do
-          pkgadd @resource[:name]
-        end
+        # fetch using fully qualified URL to package file
+        pkgadd "-r", @resource[:source]
       end
+    elsif @resource[:source] != nil
+      # use local package file path specified in source parameter
+      pkgadd @resource[:source]
     else
-      Puppet.warning "source is defined but does not have trailing slash,
ignoring #...@resource[:source]}" if @resource[:source]
-      pkgadd "-r", @resource[:name]
+      # fetch using default PACKAGESITE and origin name
+      pkgadd "-r", origin[:name]
     end
   end

@@ -44,7 +68,7 @@ Puppet::Type.type(:package).provide :freebsd, :parent =>
:openbsd do
   end

   def uninstall
-    pkgdelete "#...@resource[:name]}[email protected](:ensure)}"
+    output = pkginfo "-qO", @resource[:name]
+    output.split("\n").each { |pkg_name| pkgdelete([pkg_name]) }
   end
 end
-

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to