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

Renamed common resource type parameter 'not_on' to 'skip'.

This was originally commit 5be54fe20939 in nsc-puppet-utils.
parent 35c46403
No related branches found
No related tags found
No related merge requests found
...@@ -69,7 +69,7 @@ Puppet::Type.newtype(:delete_lines) do ...@@ -69,7 +69,7 @@ Puppet::Type.newtype(:delete_lines) do
end end
end end
newparam(:not_on) do newparam(:skip) do
desc "Don't delete lines looking like this regexp (implicitly desc "Don't delete lines looking like this regexp (implicitly
anchored at the beginning and end of the line). anchored at the beginning and end of the line).
" "
......
...@@ -4,7 +4,7 @@ require 'nsc_utils' ...@@ -4,7 +4,7 @@ require 'nsc_utils'
Puppet::Type.newtype(:regexp_replace_lines) do Puppet::Type.newtype(:regexp_replace_lines) do
@doc = "Replace lines in the file :file matching regexp :pattern with @doc = "Replace lines in the file :file matching regexp :pattern with
:replacement, unless they also match the regexp :not_on. The :replacement, unless they also match the regexp :skip. The
pattern is implicitly anchored at the start and end of the line. pattern is implicitly anchored at the start and end of the line.
The replacement text can use the standard Ruby regexp replacement The replacement text can use the standard Ruby regexp replacement
back-references. back-references.
...@@ -93,7 +93,7 @@ Puppet::Type.newtype(:regexp_replace_lines) do ...@@ -93,7 +93,7 @@ Puppet::Type.newtype(:regexp_replace_lines) do
end end
end end
newparam(:not_on) do newparam(:skip) do
desc "Don't replace lines looking like this regexp (implicitly desc "Don't replace lines looking like this regexp (implicitly
anchored at the beginning and end of the line). anchored at the beginning and end of the line).
" "
...@@ -128,14 +128,14 @@ Puppet::Type.newtype(:regexp_replace_lines) do ...@@ -128,14 +128,14 @@ Puppet::Type.newtype(:regexp_replace_lines) do
def sync def sync
lines = @saves[:lines] lines = @saves[:lines]
pattern = @saves[:pattern] pattern = @saves[:pattern]
not_on = @saves[:not_on] skip = @saves[:skip]
replacement = self.value replacement = self.value
for i in @to_replace for i in @to_replace
l = lines[i] l = lines[i]
l2 = l.chomp l2 = l.chomp
r = l2.sub(pattern, replacement) r = l2.sub(pattern, replacement)
##puts "--DEBUG: #{i+1}: <#{l2}> => <#{r}>" ##puts "--DEBUG: #{i+1}: <#{l2}> => <#{r}>"
if pattern.match(r) and not (not_on and not_on.match(r)) if pattern.match(r) and not (skip and skip.match(r))
msg = "Result of replacement still matches on line #{i+1}" msg = "Result of replacement still matches on line #{i+1}"
self.fail(msg) self.fail(msg)
end end
......
...@@ -66,9 +66,9 @@ module NSC_Utils ...@@ -66,9 +66,9 @@ module NSC_Utils
section_end, include_section_end = section_end, include_section_end =
NSC_Utils::boundary(resources, :end) NSC_Utils::boundary(resources, :end)
saves[:pattern] = Regexp.new('^' + resources[:pattern] + '$') saves[:pattern] = Regexp.new('^' + resources[:pattern] + '$')
saves[:not_on] = resources[:not_on] saves[:skip] = resources[:skip]
if saves[:not_on] if saves[:skip]
saves[:not_on] = Regexp.new('^' + saves[:not_on] + '$') saves[:skip] = Regexp.new('^' + saves[:skip] + '$')
end end
saves[:lines] = File.readlines(resources[:file]) saves[:lines] = File.readlines(resources[:file])
...@@ -86,7 +86,7 @@ module NSC_Utils ...@@ -86,7 +86,7 @@ module NSC_Utils
for sect in sections for sect in sections
for l,i in sect for l,i in sect
if saves[:pattern].match(l) if saves[:pattern].match(l)
unless saves[:not_on] and saves[:not_on].match(l) unless saves[:skip] and saves[:skip].match(l)
yield [l,i] yield [l,i]
end end
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment