summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet.rb1
-rw-r--r--lib/puppet/configuration.rb5
-rw-r--r--lib/puppet/modules.rb42
3 files changed, 47 insertions, 1 deletions
diff --git a/lib/puppet.rb b/lib/puppet.rb
index b0c6ee9f8..4d2b31fc5 100644
--- a/lib/puppet.rb
+++ b/lib/puppet.rb
@@ -383,6 +383,7 @@ module Puppet
end
require 'puppet/type'
+require 'puppet/modules'
require 'puppet/util/storage'
require 'puppet/parser/interpreter'
if Puppet[:storeconfigs]
diff --git a/lib/puppet/configuration.rb b/lib/puppet/configuration.rb
index 7c66cc11e..dfa716d42 100644
--- a/lib/puppet/configuration.rb
+++ b/lib/puppet/configuration.rb
@@ -163,7 +163,10 @@ module Puppet
:group => "$group",
:desc => "Where FileBucket files are stored."
},
- :ca => [true, "Wether the master should function as a certificate authority."]
+ :ca => [true, "Wether the master should function as a certificate authority."],
+ :modulepath => [ "$confdir/modules:/usr/share/puppet/modules",
+ "The search path for modules as a colon-separated list of
+ directories." ]
)
self.setdefaults("puppetd",
diff --git a/lib/puppet/modules.rb b/lib/puppet/modules.rb
new file mode 100644
index 000000000..cf611b82c
--- /dev/null
+++ b/lib/puppet/modules.rb
@@ -0,0 +1,42 @@
+# Support for modules
+class Puppet::Module
+
+ # Return an array of paths by splitting the +modulepath+ config
+ # parameter. Only consider paths that are absolute and existing
+ # directories
+ def self.modulepath
+ dirs = ENV["PUPPETLIB"].split(":") + Puppet[:modulepath].split(":")
+ dirs.select do |p|
+ p =~ /^#{File::SEPARATOR}/ && File::directory?(p)
+ end
+ end
+
+ # Find and return the +module+ that +path+ belongs to. If +path+ is
+ # absolute, or if there is no module whose name is the first component
+ # of +path+, return +nil+
+ def self.find(path)
+ if path =~ %r/^#{File::SEPARATOR}/
+ return nil
+ end
+
+ modname, rest = path.split(File::SEPARATOR, 2)
+ return nil if modname.nil? || modname.empty?
+
+ modpath = modulepath.collect { |p|
+ File::join(p, modname)
+ }.find { |f| File::directory?(f) }
+ return nil unless modpath
+
+ return self.new(modname, modpath)
+ end
+
+ # Instance methods
+
+ attr_reader :name, :path
+ def initialize(name, path)
+ @name = name
+ @path = path
+ end
+
+ private :initialize
+end