dirs_between.rb
| 1 |
module Puppet::Parser::Functions |
|---|---|
| 2 |
newfunction(:dirs_between, :type => :rvalue, :doc => "\ |
| 3 |
Generate a list of pathnames. Bla, bla, bla.
|
| 4 |
") \
|
| 5 |
do |args|
|
| 6 |
if args.length != 2 |
| 7 |
self.fail("dirs_between(): wrong number of arguments" + |
| 8 |
" (#{args.length} for 2)")
|
| 9 |
end
|
| 10 |
topdir = args[0]
|
| 11 |
subbottom = args[1]
|
| 12 |
subdirs = [] |
| 13 |
while subbottom != "." |
| 14 |
subbottom, component = File.split(subbottom)
|
| 15 |
subdirs.unshift(component) |
| 16 |
end
|
| 17 |
dir = topdir |
| 18 |
paths = [ dir ] |
| 19 |
while subdirs.length > 0 |
| 20 |
component = subdirs.shift() |
| 21 |
dir = File.join(dir, component)
|
| 22 |
paths.push(dir) |
| 23 |
end
|
| 24 |
return paths
|
| 25 |
end
|
| 26 |
end
|