lint utils

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2015-09-10 03:39:43 +02:00
parent 753e7775ef
commit f1cc7cbf9b
2 changed files with 34 additions and 32 deletions

View file

@ -3,7 +3,6 @@
# license: All rights reserved
class FindFiles
TYPES = {
block: 'b',
character: 'c',
@ -12,7 +11,7 @@ class FindFiles
file: 'f',
link: 'l',
socket: 's',
door: 'D'
door: 'D',
}
attr_reader :error, :files
@ -27,7 +26,8 @@ class FindFiles
@result = Specinfra::Runner.run_command(cmd)
exit_status = @result.exit_status.to_i
if exit_status == 0
@files = @result.stdout.split("\n").map{ |x| x.strip }.find_all { |x| !x.empty? }
@files = @result.stdout.split("\n").
map(&:strip).find_all { |x| !x.empty? }
else
@files = []
end

View file

@ -28,45 +28,42 @@ class SimpleConfig
start_idx = 2
i = 0
count = values - 1
if (values == 1)
return match[start_idx]
else
# iterate over expected parameters
values = []
begin
values.push(match[start_idx + i])
i += 1
end until i > count
return values
return match[start_idx] if (values == 1)
# iterate over expected parameters
values = []
loop do
values.push(match[start_idx + i])
i += 1
break if i > count
end
values
end
def parse_rest(rest, opts)
def parse_comment_line(rest, opts)
idx_nl = rest.index("\n")
idx_comment = rest.index(opts[:comment_char])
idx_nl = rest.length if idx_nl.nil?
idx_comment = idx_nl + 1 if idx_comment.nil?
line = ''
# is a comment inside this line
if idx_comment < idx_nl
if idx_comment == 0
line = ''
else
line = rest[0..(idx_comment - 1)]
# in case we don't allow comments at the end
# of an assignment/statement, ignore it and fall
# back to treating this as a regular line
if opts[:standalone_comments] && !is_empty_line(line)
line = rest[0..(idx_nl - 1)]
end
end
# if there is no comment in this line
else
if idx_nl == 0
line = ''
else
if idx_comment < idx_nl && idx_comment != 0
line = rest[0..(idx_comment - 1)]
# in case we don't allow comments at the end
# of an assignment/statement, ignore it and fall
# back to treating this as a regular line
if opts[:standalone_comments] && !is_empty_line(line)
line = rest[0..(idx_nl - 1)]
end
# if there is no comment in this line
elsif idx_comment > idx_nl && idx_nl != 0
line = rest[0..(idx_nl - 1)]
end
[line, idx_nl]
end
def parse_line_params(line, opts)
# now line contains what we are interested in parsing
# check if it is an assignment
m = opts[:assignment_re].match(line)
@ -84,6 +81,11 @@ class SimpleConfig
@params[line.strip] = ''
end
end
end
def parse_rest(rest, opts)
line, idx_nl = parse_comment_line(rest, opts)
parse_line_params(line, opts)
# return whatever is left
rest[(idx_nl + 1)..-1] || ''
@ -101,7 +103,7 @@ class SimpleConfig
assignment_re: /^\s*([^=]*?)\s*=\s*(.*?)\s*$/,
key_vals: 1, # default for key=value, may require for 'key val1 val2 val3'
standalone_comments: false,
multiple_values: false
multiple_values: false,
}
end
end