Skip to content

Commit

Permalink
remove unused sysconfig related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Feb 4, 2015
1 parent 3166fb7 commit 465e508
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 219 deletions.
136 changes: 0 additions & 136 deletions library/types/src/modules/String.rb
Original file line number Diff line number Diff line change
Expand Up @@ -876,139 +876,6 @@ def UnderlinedHeader(header_line, left_padding)
)
end

# ////////////////////////////////////////
# sysconfig metadata related functions //
# ////////////////////////////////////////

# Get metadata lines from input string
# @param [String] input Input string - complete comment of a sysconfig variable
# @return [Array<String>] Metadata lines in list
def GetMetaDataLines(input)
return [] if input.nil? || input == ""

lines = Builtins.splitstring(input, "\n")
Builtins.filter(lines) { |line| Builtins.regexpmatch(line, "^##.*") }
end

# Get comment without metadata
# @param [String] input Input string - complete comment of a sysconfig variable
# @return [String] Comment used as variable description
def GetCommentLines(input)
return "" if input.nil? || input == ""

lines = Builtins.splitstring(input, "\n")

ret = ""

Builtins.foreach(lines) do |line|
com_line = Builtins.regexpsub(line, "^#([^#].*)", "\\1")
if com_line.nil?
# add empty lines
if Builtins.regexpmatch(line, "^#[ \t]*$") == true
ret = Ops.add(ret, "\n")
end
else
ret = Ops.add(Ops.add(ret, com_line), "\n")
end
end

ret
end

# Parse metadata from a sysconfig comment
# @param [String] comment comment of a sysconfig variable (single line or multiline string)
# @return [Hash] parsed metadata
def ParseSysconfigComment(comment)
ret = {}

# get metadata part of comment
metalines = GetMetaDataLines(comment)
joined_multilines = []
multiline = ""

Builtins.y2debug("metadata: %1", metalines)

# join multi line metadata lines
Builtins.foreach(metalines) do |metaline|
if Builtins.substring(
metaline,
Ops.subtract(Builtins.size(metaline), 1),
1
) != "\\"
if multiline != ""
# this not first multiline so remove comment mark
without_comment = Builtins.regexpsub(metaline, "^##(.*)", "\\1")

metaline = without_comment if !without_comment.nil?
end
joined_multilines = Builtins.add(
joined_multilines,
Ops.add(multiline, metaline)
)
multiline = ""
else
part = Builtins.substring(
metaline,
0,
Ops.subtract(Builtins.size(metaline), 1)
)

if multiline != ""
# this not first multiline so remove comment mark
without_comment = Builtins.regexpsub(part, "^##(.*)", "\\1")

part = without_comment if !without_comment.nil?
end

# add line to the previous lines
multiline = Ops.add(multiline, part)
end
end

Builtins.y2debug(
"metadata after multiline joining: %1",
joined_multilines
)

# parse each metadata line
Builtins.foreach(joined_multilines) do |metaline|
# Ignore lines with ### -- general comments
next if Builtins.regexpmatch(metaline, "^###")
meta = Builtins.regexpsub(metaline, "^##[ \t]*(.*)", "\\1")
# split sting to the tag and value part
colon_pos = Builtins.findfirstof(meta, ":")
tag = ""
val = ""
if colon_pos.nil?
# colon is missing
tag = meta
else
tag = Builtins.substring(meta, 0, colon_pos)

if Ops.greater_than(Builtins.size(meta), Ops.add(colon_pos, 1))
val = Builtins.substring(meta, Ops.add(colon_pos, 1))
end
end
# remove whitespaces from parts
tag = CutBlanks(tag)
val = CutBlanks(val)
Builtins.y2debug("tag: %1 val: '%2'", tag, val)
# add tag and value to map if they are present in comment
if tag != ""
ret = Builtins.add(ret, tag, val)
else
# ignore separator lines
if !Builtins.regexpmatch(metaline, "^#*$")
Builtins.y2warning("Unknown metadata line: %1", metaline)
end
end
end

Builtins.y2debug("parsed sysconfig comment: %1", ret)

deep_copy(ret)
end

# Replace substring in a string. All substrings source are replaced by string target.
# @param [String] s input string
# @param [String] source the string which will be replaced
Expand Down Expand Up @@ -1302,9 +1169,6 @@ def ReplaceWith(str, chars, glue)
publish function: :ValidCharsFilename, type: "string ()"
publish function: :TextTable, type: "string (list <string>, list <list <string>>, map <string, any>)"
publish function: :UnderlinedHeader, type: "string (string, integer)"
publish function: :GetMetaDataLines, type: "list <string> (string)"
publish function: :GetCommentLines, type: "string (string)"
publish function: :ParseSysconfigComment, type: "map <string, string> (string)"
publish function: :Replace, type: "string (string, string, string)"
publish function: :WrapAt, type: "string (string, integer, string)"
publish function: :Random, type: "string (integer)"
Expand Down
83 changes: 0 additions & 83 deletions library/types/test/string_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -571,89 +571,6 @@
end
end

describe ".GetMetaDataLines" do
it "returns list of lines with metadata of sysconfig" do
sysconfig_lines = "## Path: System/Bootloader\n" \
"## Description: Bootloader configuration\n" \
"## Type: yesno\n" \
"## Default: no\n" \
"#\n" \
"# Should the boot cycle detection be used to\n" \
"# avoid unconditional reboot cycles of not\n" \
"# supervised system.\n" \
"#\n" \
"CYCLE_DETECTION=\"no\"\n"
expected_output = [
"## Path: System/Bootloader",
"## Description: Bootloader configuration",
"## Type: yesno",
"## Default: no"
]

expect(subject.GetMetaDataLines(sysconfig_lines)).to eq expected_output
end

it "returns empty array when nil passed" do
expect(subject.GetMetaDataLines(nil)).to eq []
end
end

describe ".GetCommentLines" do
it "returns string with sysconfig comment without leading # and without metadata" do
sysconfig_lines = "## Path: System/Bootloader\n" \
"## Description: Bootloader configuration\n" \
"## Type: yesno\n" \
"## Default: no\n" \
"#\n" \
"# Should the boot cycle detection be used to\n" \
"# avoid unconditional reboot cycles of not\n" \
"# supervised system.\n" \
"#\n" \
"CYCLE_DETECTION=\"no\"\n"
expected_output = "\n" \
" Should the boot cycle detection be used to\n" \
" avoid unconditional reboot cycles of not\n" \
" supervised system.\n" \
"\n"

expect(subject.GetCommentLines(sysconfig_lines)).to eq expected_output
end

it "returns empty string if nil passed" do
expect(subject.GetCommentLines(nil)).to eq ""
end
end

describe ".ParseSysconfigComment" do
it "returns hash with parsed sysconfig metadata" do
comment = "## Path: System/Bootloader\n" \
"## Description: Bootloader configuration\n" \
"## Type: yesno\n" \
"## Default: no\n" \
"#\n" \
"# Should the boot cycle detection be used to\n" \
"# avoid unconditional reboot cycles of not\n" \
"# supervised system.\n" \
"#\n" \
"CYCLE_DETECTION=\"no\"\n"

expected_output = { "Path" => "System/Bootloader",
"Description" => "Bootloader configuration",
"Type" => "yesno",
"Default" => "no"
}
expect(subject.ParseSysconfigComment(comment)).to eq expected_output
end

it "supports multiline metadata" do
line = "## Type: a,b,\\\n" \
"##c,d"

expected_output = { "Type" => "a,b,c,d" }
expect(subject.ParseSysconfigComment(line)).to eq expected_output
end
end

describe ".Replace" do
it "returns string with all source substring replaced by target" do
arg = "abcdabcdab"
Expand Down

0 comments on commit 465e508

Please sign in to comment.