Skip to content

Commit

Permalink
Use correct keyboard file
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Feb 28, 2019
1 parent 0a5f4bd commit fb7d941
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
20 changes: 15 additions & 5 deletions keyboard/src/modules/Keyboard.rb
Expand Up @@ -1416,10 +1416,10 @@ def enable_autorepeat

# Keyboards map
#
# The map can be read from two different files:
# The map can be read from two different files, see {#keyboard_file}:
#
# * `keyboard_raw_ID.ycp` where ID is the distribution identifier (as
# specified in /etc/os-release). For example, `keyboard_raw_opensuse.ycp`.
# * `keyboard_raw_opensuse.ycp` when it is an opensuse distribution (according
# to the distribution id specified in /etc/os-release).
# * `keyboard_raw.ycp` as a fallback.
#
# @example Keyboards map format
Expand All @@ -1442,13 +1442,23 @@ def enable_autorepeat
#
# @return [Hash] Keyboards map. See the example for content details.
def all_keyboards
content = SCR.Read(path(".target.yast2"), "keyboard_raw_#{OSRelease.id}.ycp")
content ||= SCR.Read(path(".target.yast2"), "keyboard_raw.ycp")
content = SCR.Read(path(".target.yast2"), keyboard_file)

# eval is necessary for translating the texts needed to be translated
content ? Builtins.eval(content) : {}
end

# Keyboard file to use depending on the distribution
#
# @return [String]
def keyboard_file
if OSRelease.id.match?(/opensuse/i)
"keyboard_raw_opensuse.ycp"
else
"keyboard_raw.ycp"
end
end

# String to specify all the relevant devices in a loadkeys command
#
# It includes all tty devices (bsc#1010938) except those representing
Expand Down
25 changes: 14 additions & 11 deletions keyboard/test/keyboard_test.rb
Expand Up @@ -26,7 +26,7 @@ module Yast

describe "Keyboard" do
let(:udev_file) { "/usr/lib/udev/rules.d/70-installation-keyboard.rules" }
let(:os_release_id) { "opensuse" }
let(:os_release_id) { "opensuse-leap" }
let(:mode) { "normal" }
let(:stage) { "normal" }

Expand Down Expand Up @@ -76,7 +76,7 @@ module Yast
let(:new_lang) { "spanish" }

it "writes the configuration" do
expect(WFM).to receive(:Execute).with(path(".local.bash_output"),
expect(WFM).to receive(:Execute).with(path(".local.bash_output"),
"/usr/bin/systemd-firstboot --root /mnt --keymap es").and_return("exit" => 0)
expect(AsciiFile).to receive(:AppendLine).with(anything, ["Keytable:", "es.map.gz"])

Expand Down Expand Up @@ -638,7 +638,6 @@ module Yast
let(:chroot) { "spanish" }
let(:mode) { "normal" }
let(:stage) { "normal" }
let(:os_release_id) { "sles" }
let(:kb_model) { "macintosh" }

before { allow(Yast::OSRelease).to receive(:id).and_return(os_release_id) }
Expand All @@ -650,19 +649,23 @@ module Yast
Keyboard.kb_model = old_kb_model
end

it "returns generic version of the keyboard map" do
reduced_db = Keyboard.get_reduced_keyboard_db
expect(reduced_db["russian"].last["ncurses"])
.to eq("mac-us.map.gz")
context "when using an opensuse product" do
let(:os_release_id) { "opensuse-leap" }

it "returns the opensuse version of the keyboard map" do
reduced_db = Keyboard.get_reduced_keyboard_db
expect(reduced_db["russian"].last["ncurses"])
.to eq("us-mac.map.gz")
end
end

context "when using a product with an specific keyboard map" do
let(:os_release_id) { "opensuse" }
context "when not using an opensuse product" do
let(:os_release_id) { "sles" }

it "returns the specific version of the keyboard map" do
it "returns generic version of the keyboard map" do
reduced_db = Keyboard.get_reduced_keyboard_db
expect(reduced_db["russian"].last["ncurses"])
.to eq("us-mac.map.gz")
.to eq("mac-us.map.gz")
end
end
end
Expand Down

0 comments on commit fb7d941

Please sign in to comment.