Skip to content

Commit

Permalink
Merge pull request #363 from kobliha/install_inf_reader
Browse files Browse the repository at this point in the history
Added Linuxrc.value_for
  • Loading branch information
kobliha committed Jun 2, 2015
2 parents 5eb76e9 + 7db8ab5 commit bc3c448
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
34 changes: 34 additions & 0 deletions library/general/src/modules/Linuxrc.rb
Expand Up @@ -211,6 +211,29 @@ def SaveInstallInf(root)
true
end

# Returns value of a given Linxurc key/feature defined on commandline
# and written into install.inf
#
# @param [String] key
# @return [String, nil] value of a given key or `nil` if not found
def value_for(feature_key)
ReadInstallInf()
feature_key = polish(feature_key)

# at first check the keys in install.inf
install_inf_key, install_inf_val = @install_inf.find { |k, _v| polish(k) == feature_key }
return install_inf_val if install_inf_key

# then check the command line
ret = nil
@install_inf.fetch("Cmdline", "").split.each do |cmdline_entry|
key, val = cmdline_entry.split("=", 2)
ret = val if polish(key) == feature_key
end

ret
end

publish function: :ResetInstallInf, type: "void ()"
publish function: :InstallInf, type: "string (string)"
publish function: :manual, type: "boolean ()"
Expand All @@ -224,6 +247,17 @@ def SaveInstallInf(root)
publish function: :WriteYaSTInf, type: "void (map <string, string>)"
publish function: :SaveInstallInf, type: "boolean (string)"
publish function: :keys, type: "list <string> ()"
publish function: :value_for, type: "string (string)"

private

# Removes characters ignored by Linuxrc and turns all to downcase
#
# @param [String]
# @return [String]
def polish(key)
key.downcase.tr("-_\\.", "")
end
end

Linuxrc = LinuxrcClass.new
Expand Down
43 changes: 43 additions & 0 deletions library/general/test/linuxrc_test.rb
Expand Up @@ -187,4 +187,47 @@ def load_install_inf(defaults_replacement = {})
expect(subject.keys.sort).to eq(DEFAULT_INSTALL_INF.keys.sort)
end
end

describe "#value_for" do
context "when key is defined in install.inf (Linuxrc commandline)" do
it "returns value for given key" do
load_install_inf(
"test_1" => "123",
"T-E-S-T-2" => "456",
"TeSt3" => "678",
"Cmdline" => "test4=890 test5=10,11,12"
)

expect(subject.value_for("test_1")).to eq("123")
expect(subject.value_for("TEsT2")).to eq("456")
expect(subject.value_for("T_e_St_3")).to eq("678")
expect(subject.value_for("T.e.s.t-4")).to eq("890")
expect(subject.value_for("test5")).to eq("10,11,12")
end

it "parses commandline with '=' in the value" do
url = "http://example.com?bar=42"
load_install_inf(
"Cmdline" => "test6=#{url}"
)

expect(subject.value_for("test_6")).to eq(url)
end

it "returns the last matching value from command line" do
load_install_inf(
"Cmdline" => "test7=foo test.7=bar test__7=baz"
)

expect(subject.value_for("test_7")).to eq("baz")
end
end

context "when key is not defined in install.inf (Linuxrc commandline)" do
it "returns nil" do
load_install_inf
expect(subject.value_for("this-key-is-not-defined")).to eq(nil)
end
end
end
end
6 changes: 6 additions & 0 deletions package/yast2.changes
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Mon Jun 1 16:23:37 CEST 2015 - locilka@suse.com

- Added Linuxrc.value_for (fate#317973)
- 3.1.127

-------------------------------------------------------------------
Wed May 27 14:36:47 UTC 2015 - jreidinger@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2
Version: 3.1.126
Version: 3.1.127
Release: 0
URL: https://github.com/yast/yast-yast2

Expand Down

0 comments on commit bc3c448

Please sign in to comment.