summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlutter <lutter@980ebf18-57e1-0310-9a29-db15c13687c0>2007-03-09 00:47:27 +0000
committerlutter <lutter@980ebf18-57e1-0310-9a29-db15c13687c0>2007-03-09 00:47:27 +0000
commitba6257c02ef5e4bd32d58d40087f84dda95141c3 (patch)
treeb5f4556465f7b48a2cf0858dc3c3510cf9943a33
parent10d68915c513ca9aa69862d17111acbf9ff87164 (diff)
downloadpuppet-ba6257c02ef5e4bd32d58d40087f84dda95141c3.tar.gz
puppet-ba6257c02ef5e4bd32d58d40087f84dda95141c3.tar.xz
puppet-ba6257c02ef5e4bd32d58d40087f84dda95141c3.zip
The basic plumbing for modules: a modulepath config parameter, and a new
class Puppet::Module that will contain the module-related functionality. The modulepath can be extended by setting the environment variable PUPPETLIB git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2276 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet.rb1
-rw-r--r--lib/puppet/configuration.rb5
-rw-r--r--lib/puppet/modules.rb42
-rw-r--r--test/puppet/modules.rb41
4 files changed, 88 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
diff --git a/test/puppet/modules.rb b/test/puppet/modules.rb
new file mode 100644
index 000000000..f3cf3b73c
--- /dev/null
+++ b/test/puppet/modules.rb
@@ -0,0 +1,41 @@
+#!/usr/bin/env ruby
+
+$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
+
+require 'puppet'
+require 'puppettest'
+
+class TestModules < Test::Unit::TestCase
+ include PuppetTest
+
+ def setup
+ super
+ @varmods = File::join(Puppet[:vardir], "modules")
+ FileUtils::mkdir_p(@varmods)
+ end
+
+ def test_modulepath
+ Puppet[:modulepath] = "$vardir/modules:/no/such/path/anywhere:.::"
+ assert_equal([ @varmods ], Puppet::Module.modulepath)
+ end
+
+ def test_find
+ assert_nil(Puppet::Module::find("/tmp"))
+
+ file = "testmod/something"
+ assert_nil(Puppet::Module::find(file))
+
+ path = File::join(@varmods, "testmod")
+ FileUtils::mkdir_p(path)
+
+ mod = Puppet::Module::find("testmod")
+ assert_not_nil(mod)
+ assert_equal("testmod", mod.name)
+ assert_equal(path, mod.path)
+
+ mod = Puppet::Module::find(file)
+ assert_not_nil(mod)
+ assert_equal("testmod", mod.name)
+ assert_equal(path, mod.path)
+ end
+end