Skip to content
Snippets Groups Projects
Commit aee8915c authored by Thomas Bellman's avatar Thomas Bellman Committed by Thomas Bellman
Browse files

Added internal helper functions for code common to several resource types.

This was originally commit da9cbf1486e1 in nsc-puppet-utils.
parent 414c4bba
No related branches found
No related tags found
No related merge requests found
module NSC_Utils
def boundary(typ, name)
include_boundary = 0
boundary = typ.resource[name]
if boundary
if boundary[0,1] == "+"
include_boundary = true
boundary = boundary[1..boundary.length]
else
include_boundary = false
end
boundary = Regexp.new('^' + boundary)
end
return [boundary, include_boundary]
end
module_function :boundary
def enumerate(lines)
result = []
lines.each_with_index do |l,i|
result.push([l,i])
end
return result
end
module_function :enumerate
def extract_sections(lines, startp, include_start, endp, include_end,
cancel_unclosed)
include_start = (include_start ? 0 : 1)
extracted = [[]]
inside = startp ? false : -1
for l,i in lines
l = l.chomp
if not inside and startp and startp.match(l)
inside = i
extracted.push([])
end
if inside and i >= inside + include_start
extracted[-1].push([l,i])
end
if inside and endp and endp.match(l)
if not include_end
extracted[-1].pop()
end
inside = false
end
end
if inside and endp and cancel_unclosed
extracted.pop()
end
extracted.delete([])
return extracted
end
module_function :extract_sections
if false
_l1 = [ 'foo', 'bar', 'gazonk', 'del',
'apelsin', 'citron', 'fromage',
'choklad', 'pudding',
]
_l2 = File.readlines('/tmp/trh/grub.conf')
_nl1 = enumerate(_l1)
_nl2 = enumerate(_l2)
_sp1 = /^bar|^citron/
_ep1 = /^del|^pudding/
_ep2 = /^del|^choklad/
_ep3 = /^del|^fromage/
_ep4 = /^del|^gurksallad/
_ep5 = /^gurksallad/
end
X = 17
Y = 23
Z = 69
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment