[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

test branch puppet-dev at googlegroups.com
Wed Jul 14 10:31:42 UTC 2010


The following commit has been merged in the upstream branch:
commit b41d53596cdcb6d7220b93926f6eedf171c09c46
Author: Luke Kanies <luke at madstop.com>
Date:   Mon Mar 23 13:43:38 2009 -0500

    Adding filename extension support to formats.
    
    This is toward fixing #1943 - we need the ability
    to easily convert between file extensions and file
    formats.
    
    Signed-off-by: Luke Kanies <luke at madstop.com>

diff --git a/lib/puppet/network/format.rb b/lib/puppet/network/format.rb
index d781242..7c3cc7b 100644
--- a/lib/puppet/network/format.rb
+++ b/lib/puppet/network/format.rb
@@ -7,7 +7,7 @@ class Puppet::Network::Format
     include Puppet::Provider::Confiner
 
     attr_reader :name, :mime
-    attr_accessor :intern_method, :render_method, :intern_multiple_method, :render_multiple_method, :weight, :required_methods
+    attr_accessor :intern_method, :render_method, :intern_multiple_method, :render_multiple_method, :weight, :required_methods, :extension
 
     def init_attribute(name, default)
         if value = @options[name]
@@ -36,6 +36,7 @@ class Puppet::Network::Format
         init_attribute(:mime, "text/%s" % name)
         init_attribute(:weight, 5)
         init_attribute(:required_methods, method_list.keys)
+        init_attribute(:extension, name.to_s)
 
         method_list.each do |method, value|
             init_attribute(method, value)
diff --git a/lib/puppet/network/format_handler.rb b/lib/puppet/network/format_handler.rb
index ea8cf35..a637f8b 100644
--- a/lib/puppet/network/format_handler.rb
+++ b/lib/puppet/network/format_handler.rb
@@ -51,6 +51,13 @@ module Puppet::Network::FormatHandler
         @formats[name.to_s.downcase.intern]
     end
 
+    def self.format_by_extension(ext)
+        @formats.each do |name, format|
+            return format if format.extension == ext
+        end
+        return nil
+    end
+
     # Provide a list of all formats.
     def self.formats
         @formats.keys
diff --git a/lib/puppet/network/formats.rb b/lib/puppet/network/formats.rb
index a98dcbc..62569d4 100644
--- a/lib/puppet/network/formats.rb
+++ b/lib/puppet/network/formats.rb
@@ -131,7 +131,7 @@ Puppet::Network::FormatHandler.create(:marshal, :mime => "text/marshal") do
     end
 end
 
-Puppet::Network::FormatHandler.create(:s, :mime => "text/plain")
+Puppet::Network::FormatHandler.create(:s, :mime => "text/plain", :extension => "txt")
 
 # A very low-weight format so it'll never get chosen automatically.
 Puppet::Network::FormatHandler.create(:raw, :mime => "application/x-raw", :weight => 1) do
diff --git a/spec/unit/network/format.rb b/spec/unit/network/format.rb
index e5a6b59..73530b9 100755
--- a/spec/unit/network/format.rb
+++ b/spec/unit/network/format.rb
@@ -123,6 +123,13 @@ describe Puppet::Network::Format do
             Puppet::Network::Format.new(:foo, :weight => 1).weight.should == 1
         end
 
+        it "should default to its extension being equal to its name" do
+            Puppet::Network::Format.new(:foo).extension.should == "foo"
+        end
+
+        it "should support overriding the extension" do
+            Puppet::Network::Format.new(:foo, :extension => "bar").extension.should == "bar"
+        end
         [:intern_method, :intern_multiple_method, :render_multiple_method, :render_method].each do |method|
             it "should allow assignment of the #{method}" do
                 Puppet::Network::Format.new(:foo, method => :foo).send(method).should == :foo
diff --git a/spec/unit/network/format_handler.rb b/spec/unit/network/format_handler.rb
index 110effe..f379e5c 100755
--- a/spec/unit/network/format_handler.rb
+++ b/spec/unit/network/format_handler.rb
@@ -204,6 +204,15 @@ describe Puppet::Network::FormatHandler do
             Puppet::Network::FormatHandler.format(:by_name).should equal(format)
         end
 
+        it "should be able to retrieve a format by extension" do
+            format = Puppet::Network::FormatHandler.create(:by_extension, :extension => "foo")
+            Puppet::Network::FormatHandler.format_by_extension("foo").should equal(format)
+        end
+
+        it "should return nil if asked to return a format by an unknown extension" do
+            Puppet::Network::FormatHandler.format_by_extension("yayness").should be_nil
+        end
+
         it "should be able to retrieve formats by name irrespective of case and class" do
             format = Puppet::Network::FormatHandler.create(:by_name)
             Puppet::Network::FormatHandler.format(:By_Name).should equal(format)
diff --git a/spec/unit/network/formats.rb b/spec/unit/network/formats.rb
index a241306..7b0c0ad 100755
--- a/spec/unit/network/formats.rb
+++ b/spec/unit/network/formats.rb
@@ -257,6 +257,10 @@ describe "Puppet Network Format" do
         it "should have its mimetype set to text/plain" do
             @text.mime.should == "text/plain"
         end
+
+        it "should use 'txt' as its extension" do
+            @text.extension.should == "txt"
+        end
     end
 
     describe Puppet::Network::FormatHandler.format(:raw) do

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list