diff options
author | lutter <lutter@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-03-09 00:52:47 +0000 |
---|---|---|
committer | lutter <lutter@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-03-09 00:52:47 +0000 |
commit | 0fa3c434b658fe432c306dc9e52e6b8c949ad3cf (patch) | |
tree | 21f012dd7ef63123f00cf5d207313177ed17d1aa /lib/puppet/modules.rb | |
parent | 38975de420bfd2f1350e7e55a996db40bc05d0b8 (diff) | |
download | puppet-0fa3c434b658fe432c306dc9e52e6b8c949ad3cf.tar.gz puppet-0fa3c434b658fe432c306dc9e52e6b8c949ad3cf.tar.xz puppet-0fa3c434b658fe432c306dc9e52e6b8c949ad3cf.zip |
Search manifests first within modules, and if no module is found, search in
the directory the current manifest is in.
Glob patterns can be used for the path, but the path only matches a module
if the first part of the path is not a glob.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2279 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/modules.rb')
-rw-r--r-- | lib/puppet/modules.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/puppet/modules.rb b/lib/puppet/modules.rb index 3d071b05a..b1b8804ea 100644 --- a/lib/puppet/modules.rb +++ b/lib/puppet/modules.rb @@ -3,6 +3,7 @@ class Puppet::Module TEMPLATES = "templates" FILES = "files" + MANIFESTS = "manifests" # Return an array of paths by splitting the +modulepath+ config # parameter. Only consider paths that are absolute and existing @@ -54,6 +55,26 @@ class Puppet::Module end end + # Return a list of manifests (as absolute filenames) that match +pat+ + # with the current directory set to +cwd+. If the first component of + # +pat+ does not contain any wildcards and is an existing module, return + # a list of manifests in that module matching the rest of +pat+ + # Otherwise, try to find manifests matching +pat+ relative to +cwd+ + def self.find_manifests(pat, cwd = nil) + cwd ||= Dir.getwd + mod = find(pat) + if mod + return mod.manifests(pat) + else + abspat = File::expand_path(pat, cwd) + files = Dir.glob(abspat) + if files.size == 0 + files = Dir.glob(abspat + ".pp") + end + return files + end + end + attr_reader :name, :path def initialize(name, path) @name = name @@ -62,6 +83,7 @@ class Puppet::Module def strip(file) n, rest = file.split(File::SEPARATOR, 2) + rest = nil if rest && rest.empty? return rest end @@ -73,5 +95,16 @@ class Puppet::Module return File::join(path, FILES) end + def manifests(pat) + rest = strip(pat) + rest ||= "init.pp" + p = File::join(path, MANIFESTS, rest) + files = Dir.glob(p) + if files.size == 0 + files = Dir.glob(p + ".pp") + end + return files + end + private :initialize end |