~ubuntu-branches/ubuntu/lucid/puppet/lucid-security

« back to all changes in this revision

Viewing changes to lib/puppet/util/feature.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
            end
27
27
            @results[name] = result
28
28
        end
29
 
        
 
29
 
30
30
        meta_def(method) do
31
31
            unless @results.include?(name)
32
32
                @results[name] = test(name, options)
34
34
            @results[name]
35
35
        end
36
36
    end
37
 
    
 
37
 
38
38
    # Create a new feature collection.
39
39
    def initialize(path)
40
40
        @path = path
41
41
        @results = {}
42
42
        @loader = Puppet::Util::Autoload.new(self, @path)
43
43
    end
44
 
    
 
44
 
45
45
    def load
46
46
        @loader.loadall
47
47
    end
63
63
    # someone asks for the feature, so we don't unnecessarily load
64
64
    # files.
65
65
    def test(name, options)
66
 
        result = true
67
 
        if ary = options[:libs]
68
 
            ary = [ary] unless ary.is_a?(Array)
69
 
            
70
 
            ary.each do |lib|
71
 
                unless lib.is_a?(String)
72
 
                    raise ArgumentError, "Libraries must be passed as strings not %s" % lib.class
73
 
                end
74
 
            
75
 
                begin
76
 
                    require lib
77
 
                rescue Exception
78
 
                    Puppet.debug "Failed to load library '%s' for feature '%s'" % [lib, name]
79
 
                    result = false
80
 
                end
81
 
            end
82
 
        end
83
 
        result
 
66
        return true unless ary = options[:libs]
 
67
        ary = [ary] unless ary.is_a?(Array)
 
68
 
 
69
        ary.each do |lib|
 
70
            return false unless load_library(lib, name)
 
71
        end
 
72
 
 
73
        # We loaded all of the required libraries
 
74
        return true
 
75
    end
 
76
 
 
77
    private
 
78
 
 
79
    def load_library(lib, name)
 
80
        unless lib.is_a?(String)
 
81
            raise ArgumentError, "Libraries must be passed as strings not %s" % lib.class
 
82
        end
 
83
 
 
84
        begin
 
85
            require lib
 
86
        rescue Exception
 
87
            Puppet.debug "Failed to load library '%s' for feature '%s'" % [lib, name]
 
88
            return false
 
89
        end
 
90
        return true
84
91
    end
85
92
end