~nvalcarcel/ubuntu/lucid/puppet/fix-546677

« back to all changes in this revision

Viewing changes to lib/puppet/node/environment.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:
 
1
require 'puppet/util/cacher'
 
2
 
 
3
# Just define it, so this class has fewer load dependencies.
 
4
class Puppet::Node
 
5
end
 
6
 
1
7
# Model the environment that a node can operate in.  This class just
2
8
# provides a simple wrapper for the functionality around environments.
3
9
class Puppet::Node::Environment
 
10
    include Puppet::Util::Cacher
 
11
 
4
12
    @seen = {}
5
13
 
6
14
    # Return an existing environment instance, or create a new one.
18
26
        @seen[symbol] = obj
19
27
    end
20
28
 
 
29
    # This is only used for testing.
 
30
    def self.clear
 
31
        @seen.clear
 
32
    end
 
33
 
21
34
    attr_reader :name
22
35
 
23
36
    # Return an environment-specific setting.
28
41
    def initialize(name)
29
42
        @name = name
30
43
    end
 
44
 
 
45
    def module(name)
 
46
        mod = Puppet::Module.new(name, self)
 
47
        return nil unless mod.exist?
 
48
        return mod
 
49
    end
 
50
 
 
51
    # Cache the modulepath, so that we aren't searching through
 
52
    # all known directories all the time.
 
53
    cached_attr(:modulepath, :ttl => Puppet[:filetimeout]) do
 
54
        dirs = self[:modulepath].split(File::PATH_SEPARATOR)
 
55
        if ENV["PUPPETLIB"]
 
56
            dirs = ENV["PUPPETLIB"].split(File::PATH_SEPARATOR) + dirs
 
57
        end
 
58
        dirs.collect do |dir|
 
59
            if dir !~ /^#{File::SEPARATOR}/
 
60
                File.join(Dir.getwd, dir)
 
61
            else
 
62
                dir
 
63
            end
 
64
        end.find_all do |p|
 
65
            p =~ /^#{File::SEPARATOR}/ && FileTest.directory?(p)
 
66
        end
 
67
    end
 
68
 
 
69
    # Return all modules from this environment.
 
70
    # Cache the list, because it can be expensive to create.
 
71
    cached_attr(:modules, :ttl => Puppet[:filetimeout]) do
 
72
        module_names = modulepath.collect { |path| Dir.entries(path) }.flatten.uniq
 
73
        module_names.collect { |path| Puppet::Module.new(path, self) rescue nil }.compact
 
74
    end
 
75
 
 
76
    def to_s
 
77
        name.to_s
 
78
    end
31
79
end