From fb7d941162f7851c4da8dd2e1480e9cfb20502b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Thu, 28 Feb 2019 09:24:44 +0000 Subject: [PATCH] Use correct keyboard file --- keyboard/src/modules/Keyboard.rb | 20 +++++++++++++++----- keyboard/test/keyboard_test.rb | 25 ++++++++++++++----------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/keyboard/src/modules/Keyboard.rb b/keyboard/src/modules/Keyboard.rb index 6d0fec0d..98b4aabb 100644 --- a/keyboard/src/modules/Keyboard.rb +++ b/keyboard/src/modules/Keyboard.rb @@ -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 @@ -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 diff --git a/keyboard/test/keyboard_test.rb b/keyboard/test/keyboard_test.rb index 16fafa68..1e0635f9 100755 --- a/keyboard/test/keyboard_test.rb +++ b/keyboard/test/keyboard_test.rb @@ -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" } @@ -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"]) @@ -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) } @@ -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