diff --git a/.rubocop.yml b/.rubocop.yml index bfcd33da7..b75c7ebd7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,6 @@ # use the shared Yast defaults inherit_from: - /usr/share/YaST2/data/devtools/data/rubocop-0.71.0_yast_style.yml + /usr/share/YaST2/data/devtools/data/rubocop-1.24.1_yast_style.yml Metrics/AbcSize: Max: 446 @@ -17,7 +17,7 @@ Metrics/ModuleLength: Metrics/CyclomaticComplexity: Max: 59 -Metrics/LineLength: +Layout/LineLength: Max: 274 Metrics/MethodLength: @@ -99,3 +99,7 @@ Naming/VariableName: - "library/network/src/lib/network/susefirewalld.rb" - "library/network/src/lib/network/susefirewall2.rb" - "library/network/src/lib/network/susefirewall2services.rb" + +# this module provides API for others, so do not change existing API +Style/OptionalBooleanParameter: + Enabled: false diff --git a/doc/examples/ask_resize_windows_partition.rb b/doc/examples/ask_resize_windows_partition.rb index 31827da7b..c6c78ecc3 100644 --- a/doc/examples/ask_resize_windows_partition.rb +++ b/doc/examples/ask_resize_windows_partition.rb @@ -30,14 +30,14 @@ def main Yast.import "Popup" @long_text = "Resizing the windows partition works well in most cases,\n" \ - "but there are pathological cases where this might fail.\n" \ - "\n" \ - "You might lose all data on that disk. So please make sure\n" \ - "you have an up-to-date backup of all relevant data\n" \ - "for disaster recovery.\n" \ - "\n" \ - "If you are unsure, it might be a good idea to abort the installation\n" \ - "right now and make a backup." + "but there are pathological cases where this might fail.\n" \ + "\n" \ + "You might lose all data on that disk. So please make sure\n" \ + "you have an up-to-date backup of all relevant data\n" \ + "for disaster recovery.\n" \ + "\n" \ + "If you are unsure, it might be a good idea to abort the installation\n" \ + "right now and make a backup." @answer = Popup.YesNoHeadline("Resize Windows Partition?", @long_text) diff --git a/doc/examples/popups2.rb b/doc/examples/popups2.rb index dd1e91cd9..bee802eb7 100644 --- a/doc/examples/popups2.rb +++ b/doc/examples/popups2.rb @@ -55,32 +55,32 @@ def main Popup.YesNoHeadline( "Really delete world?", "You in your infinite wisdom have chosen to delete this only world of ours.\n" \ - "This will mean the end to all of mankind and all life in the only known planet\n" \ - "known to be inhabited by intelligent or other life in the entire universe.\n" \ - "\n" \ - "Even though it is well known that mankind and human character are far from perfect,\n" \ - "we urgently request you to reconsider that decision.\n" \ - "\n" \ - "Are you absolutely sure you wish to delete this world?" + "This will mean the end to all of mankind and all life in the only known planet\n" \ + "known to be inhabited by intelligent or other life in the entire universe.\n" \ + "\n" \ + "Even though it is well known that mankind and human character are far from perfect,\n" \ + "we urgently request you to reconsider that decision.\n" \ + "\n" \ + "Are you absolutely sure you wish to delete this world?" ) when :generic2 Popup.AnyQuestion( "Great Dilemma", "You must now decide how to save the world.\n" \ - "\n" \ - "\n" \ - "\n" \ - "If you make the wrong decision, creatures from outer space may choose\n" \ - "\n" \ - "to get rid of this planet of ours to make room for some interstellar\n" \ - "\n" \ - "hyper expressway.\n" \ - "\n" \ - "\n" \ - "\n" \ - "So: Do you fail to recognize that your inability to confront\n" \ - "\n" \ - "this kind of indecision may destroy all of mankind?", + "\n" \ + "\n" \ + "\n" \ + "If you make the wrong decision, creatures from outer space may choose\n" \ + "\n" \ + "to get rid of this planet of ours to make room for some interstellar\n" \ + "\n" \ + "hyper expressway.\n" \ + "\n" \ + "\n" \ + "\n" \ + "So: Do you fail to recognize that your inability to confront\n" \ + "\n" \ + "this kind of indecision may destroy all of mankind?", "&Everything you say", "I'll &buy one of it", :focus_no @@ -89,20 +89,20 @@ def main Popup.AnyQuestion3( "Greatest Dilemma of the Millennium", "You must now decide how to save the world.\n" \ - "\n" \ - "\n" \ - "\n" \ - "If you make the wrong decision, creatures from outer space may choose\n" \ - "\n" \ - "to get rid of this planet of ours to make room for some interstellar\n" \ - "\n" \ - "hyper expressway.\n" \ - "\n" \ - "\n" \ - "\n" \ - "So: Do you fail to recognize that your inability to confront\n" \ - "\n" \ - "this kind of indecision may destroy all of mankind?", + "\n" \ + "\n" \ + "\n" \ + "If you make the wrong decision, creatures from outer space may choose\n" \ + "\n" \ + "to get rid of this planet of ours to make room for some interstellar\n" \ + "\n" \ + "hyper expressway.\n" \ + "\n" \ + "\n" \ + "\n" \ + "So: Do you fail to recognize that your inability to confront\n" \ + "\n" \ + "this kind of indecision may destroy all of mankind?", "&Everything you say", "I'll &buy one of it", "But I don't have a &car", @@ -113,10 +113,10 @@ def main "Bad News", RichText( "

Due to unforeseen circumstances it is necessary to format your hard disk.

\n" \ - "

This may sound bad enough, but we must format your brain, too.

\n" \ - "

And once this is done, you will fail to notice that in the process\n" \ - "the entire planet will undergo substantial rearranging of the continental shelves:\n" \ - "The continents will all be lowered to eight feet below sea level.

\n" + "

This may sound bad enough, but we must format your brain, too.

\n" \ + "

And once this is done, you will fail to notice that in the process\n" \ + "the entire planet will undergo substantial rearranging of the continental shelves:\n" \ + "The continents will all be lowered to eight feet below sea level.

\n" ), 50, # width 10 diff --git a/library/commandline/src/clients/other_tools_warning.rb b/library/commandline/src/clients/other_tools_warning.rb index 2dfceb836..4d0f4c961 100644 --- a/library/commandline/src/clients/other_tools_warning.rb +++ b/library/commandline/src/clients/other_tools_warning.rb @@ -40,8 +40,8 @@ def main # Opscode Chef is a different way to configure the system. message = _( "Chef Client is running. The changes that you make\n" \ - "may be overridden by Chef later.\n" \ - "Continue configuration with YaST?" + "may be overridden by Chef later.\n" \ + "Continue configuration with YaST?" ) return Popup.ContinueCancel(message) end diff --git a/library/commandline/src/modules/CommandLine.rb b/library/commandline/src/modules/CommandLine.rb index d7777483e..f1fd5fefd 100644 --- a/library/commandline/src/modules/CommandLine.rb +++ b/library/commandline/src/modules/CommandLine.rb @@ -391,13 +391,14 @@ def Parse(arguments) os = Convert.to_string(aos) o = Builtins.regexptokenize(os, "([^=]+)=(.+)") Builtins.y2debug("o=%1", o) - if Builtins.size(o) == 2 + case Builtins.size(o) + when 2 givenoptions = Builtins.add( givenoptions, Ops.get(o, 0, ""), Ops.get(o, 1, "") ) - elsif Builtins.size(o) == 0 + when 0 # check, if the last character is "=" # FIXME: consider whitespace if Builtins.substring(os, Ops.subtract(Builtins.size(os), 1)) == "=" @@ -455,7 +456,8 @@ def Parse(arguments) if opttype != "" # need to check the type - if opttype == "regex" + case opttype + when "regex" opttypespec = Ops.get_string(cmdoptions, [o, "typespec"], "") ret = TypeRepository.regex_validator(opttypespec, v) if ret != true @@ -465,7 +467,7 @@ def Parse(arguments) ) @aborted = true if !@interactive end - elsif opttype == "enum" + when "enum" ret = TypeRepository.enum_validator( Ops.get_list(cmdoptions, [o, "typespec"], []), v @@ -477,18 +479,18 @@ def Parse(arguments) ) @aborted = true if !@interactive end - elsif opttype == "integer" + when "integer" i = Builtins.tointeger(v) ret = !i.nil? - if ret != true + if ret == true + # update value of the option to integer + Ops.set(givenoptions, o, i) + else # translators: error message, %2 is the value given Print( Builtins.sformat(_("Invalid value for option '%1': %2"), o, v) ) @aborted = true if !@interactive - else - # update value of the option to integer - Ops.set(givenoptions, o, i) end else ret = (v == "") ? false : TypeRepository.is_a(v, opttype) @@ -735,7 +737,21 @@ def PrintGeneralHelp # translators: short help title for command line Print(_("Basic Syntax:")) - if !@interactive + if @interactive + # translators: module command line help + # translate and [options] only! + Print(_(" [options]")) + # translators: module command line help + # translate only! + Print(_(" help")) + # translators: module command line help + Print(" help") + Print(" longhelp") + Print(" xmlhelp") + Print("") + Print(" exit") + Print(" abort") + else # translators: module command line help, %1 is the module name Print( Builtins.sformat( @@ -779,20 +795,6 @@ def PrintGeneralHelp Ops.get_string(@modulecommands, "id", "") ) ) - else - # translators: module command line help - # translate and [options] only! - Print(_(" [options]")) - # translators: module command line help - # translate only! - Print(_(" help")) - # translators: module command line help - Print(" help") - Print(" longhelp") - Print(" xmlhelp") - Print("") - Print(" exit") - Print(" abort") end Print("") @@ -1247,13 +1249,13 @@ def Init(cmdlineinfo, args) @commandcache = {} @done = !@interactive @aborted = false - return @interactive + @interactive else # we cannot handle this on our own, return true if there is some command to be processed # i.e, there is no parsing error @done = Builtins.size(@commandcache) == 0 @aborted = @done - return !@done + !@done end end @@ -1275,9 +1277,10 @@ def GetInput(prompt, type) # set the required prompt SCR.Write(path(".dev.tty.prompt"), prompt) - res = if type == :nohistory + res = case type + when :nohistory Convert.to_string(SCR.Read(path(".dev.tty.nohistory"))) - elsif type == :noecho + when :noecho Convert.to_string(SCR.Read(path(".dev.tty.noecho"))) else Convert.to_string(SCR.Read(path(".dev.tty"))) @@ -1324,7 +1327,7 @@ def Command result = deep_copy(@commandcache) @commandcache = {} @done = !@interactive - return deep_copy(result) + deep_copy(result) # if in interactive mode, ask user for input elsif @interactive loop do @@ -1348,11 +1351,11 @@ def Command result = deep_copy(@commandcache) @commandcache = {} - return deep_copy(result) + deep_copy(result) else # there is no further commands left @done = true - return { "command" => "exit" } + { "command" => "exit" } end end @@ -1590,20 +1593,16 @@ def Run(commandline) options = Ops.get_map(m, "options", {}) # start initialization code if it wasn't already used - if !initialized - # check whether command is defined in the map (i.e. it is not predefined command or invalid command) - # and start initialization if it's defined - if Builtins.haskey(Ops.get_map(commandline, "actions", {}), command) && - Ops.get(commandline, "initialize") - # non-GUI handling - PrintVerbose(_("Initializing")) - ret2 = commandline["initialize"].call - if !ret2 - Builtins.y2milestone("Module initialization failed") - return false - else - initialized = true - end + if !initialized && (Builtins.haskey(Ops.get_map(commandline, "actions", {}), command) && + Ops.get(commandline, "initialize")) + # non-GUI handling + PrintVerbose(_("Initializing")) + ret2 = commandline["initialize"].call + if ret2 + initialized = true + else + Builtins.y2milestone("Module initialization failed") + return false end end diff --git a/library/commandline/test/test_helper.rb b/library/commandline/test/test_helper.rb index 08dc933d5..6affe9fe9 100644 --- a/library/commandline/test/test_helper.rb +++ b/library/commandline/test/test_helper.rb @@ -1 +1 @@ -require_relative "../../../test/test_helper.rb" +require_relative "../../../test/test_helper" diff --git a/library/control/src/modules/InstError.rb b/library/control/src/modules/InstError.rb index 1e2d5cfb6..5a10d6b17 100644 --- a/library/control/src/modules/InstError.rb +++ b/library/control/src/modules/InstError.rb @@ -76,7 +76,10 @@ def SaveLogs ) dialog_ret = nil - if Ops.get_integer(cmd, "exit", -1) != 0 + if Ops.get_integer(cmd, "exit", -1) == 0 + Builtins.y2milestone("Logs have been saved to: %1", savelogsto) + dialog_ret = true + else Builtins.y2error("Unable to save logs to %1", savelogsto) Report.Error( @@ -90,9 +93,6 @@ def SaveLogs ) dialog_ret = false - else - Builtins.y2milestone("Logs have been saved to: %1", savelogsto) - dialog_ret = true end UI.CloseDialog @@ -146,8 +146,8 @@ def ShowErrorPopUp(heading, error_text, details) # %3 - link to the Yast Bug Reporting HOWTO Web page _( "This is worth reporting a bug at %1.\n" \ - "Please, attach also all YaST logs stored in the '%2' directory.\n" \ - "See %3 for more information about YaST logs." + "Please, attach also all YaST logs stored in the '%2' directory.\n" \ + "See %3 for more information about YaST logs." ), bugzilla_url, "/var/log/YaST2/", diff --git a/library/control/src/modules/InstExtensionImage.rb b/library/control/src/modules/InstExtensionImage.rb index 7295536d6..3520c73d8 100644 --- a/library/control/src/modules/InstExtensionImage.rb +++ b/library/control/src/modules/InstExtensionImage.rb @@ -377,11 +377,11 @@ def LoadExtension(package, message) Builtins.y2milestone("Returned: %1", cmd_out) ret = true - if Ops.get_integer(cmd_out, "exit", -1) != 0 + if Ops.get_integer(cmd_out, "exit", -1) == 0 + @integrated_extensions = Builtins.add(@integrated_extensions, package) + else Builtins.y2error("'extend' failed!") ret = false - else - @integrated_extensions = Builtins.add(@integrated_extensions, package) end Popup.ClearFeedback if message != "" && !message.nil? @@ -414,13 +414,13 @@ def UnLoadExtension(package, message) Builtins.y2milestone("Returned: %1", cmd_out) ret = true - if Ops.get_integer(cmd_out, "exit", -1) != 0 - Builtins.y2error("'extend' failed!") - ret = false - else + if Ops.get_integer(cmd_out, "exit", -1) == 0 @integrated_extensions = Builtins.filter(@integrated_extensions) do |p| p != package end + else + Builtins.y2error("'extend' failed!") + ret = false end Popup.ClearFeedback if message != "" && !message.nil? diff --git a/library/control/src/modules/Installation.rb b/library/control/src/modules/Installation.rb index ef8a12222..94b132a23 100644 --- a/library/control/src/modules/Installation.rb +++ b/library/control/src/modules/Installation.rb @@ -227,9 +227,10 @@ def Initialize while Ops.less_than(arg_no, arg_count) Builtins.y2debug("option #%1: %2", arg_no, WFM.Args(arg_no)) - if WFM.Args(arg_no) == "text_fallback" + case WFM.Args(arg_no) + when "text_fallback" @_text_fallback = true - elsif WFM.Args(arg_no) == "no_x11" + when "no_x11" @_no_x11 = true else Builtins.y2milestone("skipping unknown option %1", WFM.Args(arg_no)) diff --git a/library/control/src/modules/ProductControl.rb b/library/control/src/modules/ProductControl.rb index 58d260f3f..5a839435c 100644 --- a/library/control/src/modules/ProductControl.rb +++ b/library/control/src/modules/ProductControl.rb @@ -557,40 +557,6 @@ def PrepareScripts(workflow) nil end - # Get list of required files for the workflow. - # @return [Array] Required files list. - # FIXME: this function seems to be unused, remove it? - def RequiredFiles(stage, mode) - # Files needed during installation. - needed_client_files = [] - - workflow = FindMatchingWorkflow(stage, mode) - - modules = Ops.get_list(workflow, "modules", []) - modules = Builtins.filter(modules) do |m| - Ops.get_boolean(m, "enabled", true) - end - - Builtins.foreach(modules) do |m| - client = if Stage.firstboot - Ops.get_string(m, "name", "dummy") - elsif Builtins.issubstring(Ops.get_string(m, "name", "dummy"), "inst_") - Ops.get_string(m, "name", "dummy") - else - Ops.add("inst_", Ops.get_string(m, "name", "dummy")) - end - # FIXME: what about the ruby files? - client = Ops.add( - Ops.add(Ops.add(Directory.clientdir, "/"), client), - ".ycp" - ) - needed_client_files = Builtins.add(needed_client_files, client) - end - - needed_client_files = Builtins.toset(needed_client_files) - deep_copy(needed_client_files) - end - # Get Workflow # @param [String] stage Stage # @param [String] mode Mode @@ -653,15 +619,11 @@ def RunRequired(stage, mode) end modules = Builtins.filter(modules) do |one_module| - # modules - if !Ops.get_string(one_module, "name").nil? && - Ops.get_string(one_module, "name", "") != "" - next true - # proposals - elsif !Ops.get_string(one_module, "proposal").nil? && - Ops.get_string(one_module, "proposal", "") != "" - next true - end + name = one_module["name"] + proposal = one_module["proposal"] + + next true if name && !name.empty? + next true if proposal && !proposal.empty? # the rest false @@ -761,7 +723,7 @@ def UnDisableAllModulesAndProposals(mode, stage) one_workflow != this_workflow end - # Note: This might be done by a simple reverting with 'X = localX' + # NOTE: This might be done by a simple reverting with 'X = localX' # but some of these modules don't need to be in a defined mode and stage Builtins.foreach(getModules(stage, mode, :all)) do |m| @@ -907,11 +869,11 @@ def AddWizardSteps(stagemode) first_id = Ops.get_string(m, "id", "") if first_id == "" if last_label != "" - if last_domain != "" + if last_domain == "" + label = Builtins.dgettext(wizard_textdomain, last_label) + else label = Builtins.dgettext(last_domain, last_label) id = Ops.get_string(m, "id", "") - else - label = Builtins.dgettext(wizard_textdomain, last_label) end id = Ops.get_string(m, "id", "") end @@ -1082,23 +1044,23 @@ def getProposals(stage, mode, proptype) proposal_name ) # All proposal file names end with _proposal - if !is_disabled - final_proposals = if !Builtins.issubstring(proposal_name, "_proposal") + if is_disabled + Builtins.y2milestone( + "Proposal module %1 found among disabled subproposals", + proposal_name + ) + else + final_proposals = if Builtins.issubstring(proposal_name, "_proposal") Builtins.add( final_proposals, - [Ops.add(proposal_name, "_proposal"), order_value] + [proposal_name, order_value] ) else Builtins.add( final_proposals, - [proposal_name, order_value] + [Ops.add(proposal_name, "_proposal"), order_value] ) end - else - Builtins.y2milestone( - "Proposal module %1 found among disabled subproposals", - proposal_name - ) end end @@ -1276,18 +1238,14 @@ def RunFrom(from, allow_back) retranslate = Ops.get_boolean(step, "retranslate", false) # The very first dialog has back button disabled - if Ops.less_or_equal(@current_step, minimum_step) - # Don't mark back button disabled when back button status - # is forced in the control file - if !Builtins.haskey(step, "enable_back") - Ops.set(step, "enable_back", "no") - Builtins.y2milestone( - "Disabling back: %1 %2 %3", - @current_step, - minimum_step, - Ops.get(step, "enable_back") - ) - end + if Ops.less_or_equal(@current_step, minimum_step) && !Builtins.haskey(step, "enable_back") + Ops.set(step, "enable_back", "no") + Builtins.y2milestone( + "Disabling back: %1 %2 %3", + @current_step, + minimum_step, + Ops.get(step, "enable_back") + ) end do_continue = false @@ -1327,14 +1285,12 @@ def RunFrom(from, allow_back) @CurrentWizardStep = step_id # Register what step we are going to run - if !Stage.initial - if !SCR.Write( - path(".target.string"), - Installation.current_step, - step_id - ) - Builtins.y2error("Error writing step identifier") - end + if !Stage.initial && !SCR.Write( + path(".target.string"), + Installation.current_step, + step_id + ) + Builtins.y2error("Error writing step identifier") end client_name = getClientName(step_name, step_execute) @@ -1393,12 +1349,10 @@ def RunFrom(from, allow_back) # Remove file if step was run and returned (without a crash); if Ops.less_than(@current_step, Ops.subtract(Builtins.size(modules), 1)) && - !Stage.initial - if !Convert.to_boolean( + !Stage.initial && !Convert.to_boolean( SCR.Execute(path(".target.remove"), Installation.current_step) ) - Builtins.y2error("Error removing step identifier") - end + Builtins.y2error("Error removing step identifier") end if retranslate @@ -1432,11 +1386,11 @@ def RunFrom(from, allow_back) # %4 - directory where YaST logs are stored # %5 - link to the Yast Bug Reporting HOWTO Web page "Calling the YaST module %1 has failed.\n" \ - "More information can be found near the end of the '%2' file.\n" \ - "\n" \ - "This is worth reporting a bug at %3.\n" \ - "Please, attach also all YaST logs stored in the '%4' directory.\n" \ - "See %5 for more information about YaST logs.", + "More information can be found near the end of the '%2' file.\n" \ + "\n" \ + "This is worth reporting a bug at %3.\n" \ + "Please, attach also all YaST logs stored in the '%4' directory.\n" \ + "See %5 for more information about YaST logs.", Builtins.symbolof(argterm), "/var/log/YaST2/y2log", "http://bugzilla.suse.com/", @@ -1463,7 +1417,7 @@ def RunFrom(from, allow_back) # The very first dialog must not exit with `back # or `auto if @current_step == 0 && - (result == :back || result == :auto && former_result == :back) + (result == :back || (result == :auto && former_result == :back)) Builtins.y2warning( "Returned %1, Current step %2 (%3). The current step will be called again...", result, @@ -1479,15 +1433,13 @@ def RunFrom(from, allow_back) @current_step = Ops.add(@current_step, 1) when :back @current_step = Ops.subtract(@current_step, 1) - when :cancel + when :cancel, :finish break when :abort # handling when user aborts the workflow (FATE #300422, bnc #406401, bnc #247552) final_result = result Hooks.run("installation_aborted") - break - when :finish break when :again next # Show same dialog again @@ -1497,12 +1449,13 @@ def RunFrom(from, allow_back) break when :auto if !former_result.nil? - if former_result == :next + case former_result + when :next # if the first client just returns `auto, the back button # of the next client must be disabled minimum_step = Ops.add(minimum_step, 1) if Ops.less_or_equal(@current_step, minimum_step) && !allow_back @current_step = Ops.add(@current_step, 1) - elsif former_result == :back + when :back @current_step = Ops.subtract(@current_step, 1) end end diff --git a/library/control/src/modules/WorkflowManager.rb b/library/control/src/modules/WorkflowManager.rb index 493bec263..0e679c45c 100644 --- a/library/control/src/modules/WorkflowManager.rb +++ b/library/control/src/modules/WorkflowManager.rb @@ -380,8 +380,8 @@ def StoreWorkflowFile(file_from, file_to) path(".target.bash_output"), Builtins.sformat( "\n" \ - "/bin/mkdir -p '%1';\n" \ - "/bin/cp -v '%2' '%3';\n", + "/bin/mkdir -p '%1';\n" \ + "/bin/cp -v '%2' '%3';\n", String.Quote(GetWorkflowDirectory()), String.Quote(file_from), String.Quote(file_to) @@ -528,7 +528,7 @@ def GetCachedWorkflowFilename(type, src_id, name = "") # A cached copy exists if FileUtils.Exists(disk_filename) Builtins.y2milestone("Using cached file %1", disk_filename) - return disk_filename + disk_filename # Trying to get the file from source else Builtins.y2milestone("File %1 not cached", disk_filename) @@ -550,7 +550,7 @@ def GetCachedWorkflowFilename(type, src_id, name = "") end # File exists? - return use_filename.nil? ? nil : StoreWorkflowFile(use_filename, disk_filename) + use_filename.nil? ? nil : StoreWorkflowFile(use_filename, disk_filename) end ensure # release the media accessors (close server connections/unmount disks) @@ -635,14 +635,12 @@ def RemoveWorkflow(type, src_id, name) ) end - if !Stage.initial - if FileUtils.Exists(used_filename) - Builtins.y2milestone( - "Removing cached file '%1': %2", - used_filename, - SCR.Execute(path(".target.remove"), used_filename) - ) - end + if !Stage.initial && FileUtils.Exists(used_filename) + Builtins.y2milestone( + "Removing cached file '%1': %2", + used_filename, + SCR.Execute(path(".target.remove"), used_filename) + ) end end @@ -665,9 +663,9 @@ def CleanWorkflowsDirectory SCR.Execute( path(".target.bash_ouptut"), "\n" \ - "cd '%1';\n" \ - "/usr/bin/test -x /usr/bin/tar && /usr/bin/tar -zcf workflows_backup.tgz *.xml *.ycp *.rb;\n" \ - "/usr/bin/rm -rf *.xml *.ycp *.rb", + "cd '%1';\n" \ + "/usr/bin/test -x /usr/bin/tar && /usr/bin/tar -zcf workflows_backup.tgz *.xml *.ycp *.rb;\n" \ + "/usr/bin/rm -rf *.xml *.ycp *.rb", String.Quote(directory) ) ) @@ -690,9 +688,9 @@ def ReplaceProposalModule(proposal, old, new) found = false modules = Builtins.maplist(Ops.get_list(proposal, "proposal_modules", [])) do |m| - if Ops.is_string?(m) && Convert.to_string(m) == old || - Ops.is_map?(m) && - Ops.get_string(Convert.to_map(m), "name", "") == old + if (Ops.is_string?(m) && Convert.to_string(m) == old) || + (Ops.is_map?(m) && + Ops.get_string(Convert.to_map(m), "name", "") == old) found = true next deep_copy(new) unless Ops.is_map?(m) @@ -833,12 +831,12 @@ def UpdateProposals(proposals, prod_name, domain) new_proposals = Builtins.add(new_proposals, p) end if !found - if arch_all_prop != {} + if arch_all_prop == {} + Ops.set(proposal, "textdomain", domain) + else Ops.set(arch_all_prop, "archs", arch) proposal = MergeProposal(arch_all_prop, proposal, prod_name, domain) # completly new proposal - else - Ops.set(proposal, "textdomain", domain) end new_proposals = Builtins.add(new_proposals, proposal) @@ -983,11 +981,7 @@ def UpdateWorkflows(workflows, prod_name, domain) new_workflows = Builtins.add(new_workflows, w) end if !found - if arch_all_wf != {} - Ops.set(arch_all_wf, ["defaults", "archs"], arch) - workflow = MergeWorkflow(arch_all_wf, workflow, prod_name, domain) - # completly new workflow - else + if arch_all_wf == {} # If modules has not been defined we are trying to use the appended modules workflow["modules"] = workflow["append_modules"] unless workflow["modules"] @@ -1001,6 +995,10 @@ def UpdateWorkflows(workflows, prod_name, domain) deep_copy(mod) end ) + else + Ops.set(arch_all_wf, ["defaults", "archs"], arch) + workflow = MergeWorkflow(arch_all_wf, workflow, prod_name, domain) + # completly new workflow end new_workflows = Builtins.add(new_workflows, workflow) @@ -1108,7 +1106,12 @@ def AddNewProposals(proposals) forbidden = Builtins.toset(forbidden) Builtins.foreach(proposals) do |proposal| - if !Builtins.contains(forbidden, Ops.get_string(proposal, "name", "")) + if Builtins.contains(forbidden, Ops.get_string(proposal, "name", "")) + Builtins.y2warning( + "Proposal '%1' already exists, not adding", + Ops.get_string(proposal, "name", "") + ) + else Builtins.y2milestone( "Adding new proposal %1", Ops.get_string(proposal, "name", "") @@ -1117,11 +1120,6 @@ def AddNewProposals(proposals) ProductControl.proposals, proposal ) - else - Builtins.y2warning( - "Proposal '%1' already exists, not adding", - Ops.get_string(proposal, "name", "") - ) end end diff --git a/library/control/test/InstExtensionImage_test.rb b/library/control/test/InstExtensionImage_test.rb index 279aaabce..e18e493cd 100755 --- a/library/control/test/InstExtensionImage_test.rb +++ b/library/control/test/InstExtensionImage_test.rb @@ -116,7 +116,7 @@ .with(path(".local.bash_output"), "/bin/extend 'snapper'") .and_return("exit" => 1) - expect { subject.with_extension("snapper") {} }.to raise_error + expect { subject.with_extension("snapper") {} }.to raise_error # empty block is enough end it "unloads extension even if block raises exception" do diff --git a/library/control/test/test_helper.rb b/library/control/test/test_helper.rb index 08dc933d5..6affe9fe9 100644 --- a/library/control/test/test_helper.rb +++ b/library/control/test/test_helper.rb @@ -1 +1 @@ -require_relative "../../../test/test_helper.rb" +require_relative "../../../test/test_helper" diff --git a/library/control/test/workflow_manager_test.rb b/library/control/test/workflow_manager_test.rb index 185b49beb..5c62ab4df 100755 --- a/library/control/test/workflow_manager_test.rb +++ b/library/control/test/workflow_manager_test.rb @@ -299,7 +299,7 @@ let(:product_package) { "foo-release" } let(:product) do Y2Packager::Resolvable.new("kind" => :product, "name" => "foo", "source" => repo_id, - "version" => "1.0", "arch" => "x86_64", "product_package" => product_package) + "version" => "1.0", "arch" => "x86_64", "product_package" => product_package) end let(:ext_package) { "foo-installation" } let(:extension) do @@ -308,7 +308,7 @@ end let(:release) do Y2Packager::Resolvable.new("name" => product_package, "source" => repo_id, "version" => "1.0", "arch" => "x86_64", - "kind" => :package, "deps" => ["provides" => "installerextension(#{ext_package})"]) + "kind" => :package, "deps" => ["provides" => "installerextension(#{ext_package})"]) end before do diff --git a/library/cwm/examples/date_time.rb b/library/cwm/examples/date_time.rb index dd3ebdd79..3d96c277c 100644 --- a/library/cwm/examples/date_time.rb +++ b/library/cwm/examples/date_time.rb @@ -9,6 +9,8 @@ class Name < CWM::InputField def initialize + super + textdomain "example" end @@ -19,6 +21,8 @@ def label class EventDate < CWM::DateField def initialize + super + textdomain "example" end @@ -33,6 +37,8 @@ def label class EventTime < CWM::TimeField def initialize + super + textdomain "example" end @@ -47,6 +53,8 @@ def label class Event < ::CWM::Popup def initialize + super + textdomain "example" end diff --git a/library/cwm/examples/object_api.rb b/library/cwm/examples/object_api.rb index f8ced551d..17d005164 100644 --- a/library/cwm/examples/object_api.rb +++ b/library/cwm/examples/object_api.rb @@ -12,6 +12,8 @@ class LuckyNumberWidget < CWM::IntField attr_reader :result, :minimum, :maximum def initialize + super + @minimum = 0 @maximum = 1000 end @@ -27,6 +29,8 @@ def store class GenerateButton < CWM::PushButton def initialize(lucky_number_widget) + super() + @lucky_number_widget = lucky_number_widget end diff --git a/library/cwm/examples/object_api_all_events.rb b/library/cwm/examples/object_api_all_events.rb index 6ff4b4970..accf80f97 100644 --- a/library/cwm/examples/object_api_all_events.rb +++ b/library/cwm/examples/object_api_all_events.rb @@ -11,6 +11,8 @@ class DisplayWidget < CWM::InputField attr_reader :result def initialize + super + self.widget_id = "lucky_number_widget" self.handle_all_events = true disable @@ -43,6 +45,8 @@ def handle(event) class FirstButton < CWM::PushButton def initialize + super + self.widget_id = "first button" end @@ -53,6 +57,8 @@ def label class SecondButton < CWM::PushButton def initialize + super + self.widget_id = "second button" end diff --git a/library/cwm/examples/object_api_enabling.rb b/library/cwm/examples/object_api_enabling.rb index 9daa1bd15..29ee4c54b 100644 --- a/library/cwm/examples/object_api_enabling.rb +++ b/library/cwm/examples/object_api_enabling.rb @@ -11,6 +11,8 @@ class LuckyNumberWidget < CWM::IntField attr_reader :result, :minimum, :maximum def initialize + super + @minimum = 0 @maximum = 1000 end @@ -26,6 +28,8 @@ def store class EnableButton < CWM::PushButton def initialize(lucky_number_widget) + super() + @lucky_number_widget = lucky_number_widget end @@ -53,6 +57,8 @@ def handle class DisableButton < CWM::PushButton def initialize(lucky_number_widget) + super() + @lucky_number_widget = lucky_number_widget end diff --git a/library/cwm/examples/object_api_nested.rb b/library/cwm/examples/object_api_nested.rb index 5e3a66b07..2c43c07fd 100644 --- a/library/cwm/examples/object_api_nested.rb +++ b/library/cwm/examples/object_api_nested.rb @@ -12,6 +12,8 @@ class LuckyNumberWidget < CWM::IntField attr_reader :result, :minimum, :maximum def initialize + super + @minimum = 0 @maximum = 1000 end @@ -27,6 +29,8 @@ def store class GenerateButton < CWM::PushButton def initialize(lucky_number_widget) + super() + @lucky_number_widget = lucky_number_widget end diff --git a/library/cwm/examples/object_api_tabs.rb b/library/cwm/examples/object_api_tabs.rb index 6032fd6e2..98678734f 100644 --- a/library/cwm/examples/object_api_tabs.rb +++ b/library/cwm/examples/object_api_tabs.rb @@ -12,6 +12,8 @@ class LuckyNumberWidget < ::CWM::IntField attr_reader :result, :minimum, :maximum def initialize + super + @minimum = 0 @maximum = 1000 end @@ -31,6 +33,8 @@ def store class GenerateButton < ::CWM::PushButton def initialize(lucky_number_widget) + super() + @lucky_number_widget = lucky_number_widget end @@ -47,6 +51,8 @@ def handle class LuckyNumberTab < ::CWM::Tab def initialize + super + self.initial = true end @@ -78,6 +84,8 @@ def lucky_number_widget class TrueLoveSelector < ::CWM::RadioButtons def initialize + super + @chosen = nil end diff --git a/library/cwm/examples/object_api_tree.rb b/library/cwm/examples/object_api_tree.rb index db8c3ea7a..dc3215806 100644 --- a/library/cwm/examples/object_api_tree.rb +++ b/library/cwm/examples/object_api_tree.rb @@ -13,6 +13,8 @@ class LuckyNumberWidget < ::CWM::IntField attr_reader :result, :minimum, :maximum def initialize + super + @minimum = 0 @maximum = 1000 end @@ -32,6 +34,8 @@ def store class GenerateButton < ::CWM::PushButton def initialize(lucky_number_widget) + super() + @lucky_number_widget = lucky_number_widget end @@ -48,6 +52,7 @@ def handle class LuckyNumberTab < ::CWM::Tab def initialize + super self.initial = true end @@ -79,6 +84,8 @@ def lucky_number_widget class TrueLoveSelector < ::CWM::RadioButtons def initialize + super + @chosen = nil end @@ -139,7 +146,10 @@ def true_love_selector class ExampleTree < CWM::Tree attr_reader :items + def initialize(items) + super() + @items = items end diff --git a/library/cwm/examples/popup.rb b/library/cwm/examples/popup.rb index d86ed8f20..fa50224e0 100644 --- a/library/cwm/examples/popup.rb +++ b/library/cwm/examples/popup.rb @@ -9,6 +9,8 @@ class Goat < CWM::CheckBox def initialize + super + textdomain "example" end @@ -23,6 +25,8 @@ def help class Cabbage < CWM::CheckBox def initialize + super + textdomain "example" end @@ -37,6 +41,8 @@ def help class Wolf < CWM::CheckBox def initialize + super + textdomain "example" end @@ -51,6 +57,8 @@ def help class Ferryman < ::CWM::Popup def initialize + super + textdomain "example" end diff --git a/library/cwm/examples/replace_point_example.rb b/library/cwm/examples/replace_point_example.rb index 2a0dbc7e3..5a0b409ca 100644 --- a/library/cwm/examples/replace_point_example.rb +++ b/library/cwm/examples/replace_point_example.rb @@ -12,6 +12,8 @@ class SwitchWidget < CWM::PushButton def initialize(replace_point, widgets) + super() + @replace_point = replace_point @widgets = widgets end diff --git a/library/cwm/examples/replace_point_with_nested_custom.rb b/library/cwm/examples/replace_point_with_nested_custom.rb index 56645a031..47c0391f6 100644 --- a/library/cwm/examples/replace_point_with_nested_custom.rb +++ b/library/cwm/examples/replace_point_with_nested_custom.rb @@ -13,6 +13,8 @@ class SwitchWidget < CWM::PushButton def initialize(replace_point, widgets) + super() + @replace_point = replace_point @widgets = widgets end @@ -66,6 +68,8 @@ class LuckyNumberWidget < CWM::IntField attr_reader :result, :minimum, :maximum def initialize + super() + @minimum = 0 @maximum = 1000 end @@ -81,6 +85,8 @@ def store class GenerateButton < CWM::PushButton def initialize(lucky_number_widget) + super() + @lucky_number_widget = lucky_number_widget textdomain "example" end diff --git a/library/cwm/examples/replace_point_with_nested_replace_point.rb b/library/cwm/examples/replace_point_with_nested_replace_point.rb index e4f896161..1cce1c45d 100644 --- a/library/cwm/examples/replace_point_with_nested_replace_point.rb +++ b/library/cwm/examples/replace_point_with_nested_replace_point.rb @@ -13,6 +13,8 @@ class SwitchWidget < CWM::PushButton def initialize(replace_point, widgets) + super() + @replace_point = replace_point @widgets = widgets end @@ -70,6 +72,8 @@ class LuckyNumberWidget < CWM::IntField attr_reader :result, :minimum, :maximum def initialize + super() + @minimum = 0 @maximum = 1000 textdomain "example" @@ -86,6 +90,8 @@ def store class GenerateButton < CWM::PushButton def initialize(lucky_number_widget) + super() + @lucky_number_widget = lucky_number_widget textdomain "example" end diff --git a/library/cwm/examples/service_widget.rb b/library/cwm/examples/service_widget.rb index 6b6c68019..14a688ced 100644 --- a/library/cwm/examples/service_widget.rb +++ b/library/cwm/examples/service_widget.rb @@ -14,6 +14,8 @@ class LuckyNumberWidget < CWM::IntField attr_reader :result, :minimum, :maximum def initialize + super() + @minimum = 0 @maximum = 1000 end @@ -29,6 +31,8 @@ def store class GenerateButton < CWM::PushButton def initialize(lucky_number_widget) + super() + @lucky_number_widget = lucky_number_widget end diff --git a/library/cwm/src/lib/cwm/abstract_widget.rb b/library/cwm/src/lib/cwm/abstract_widget.rb index 8383d30e4..ec9e9d277 100644 --- a/library/cwm/src/lib/cwm/abstract_widget.rb +++ b/library/cwm/src/lib/cwm/abstract_widget.rb @@ -62,14 +62,13 @@ class AbstractWidget def handle_all_events @handle_all_events.nil? ? false : @handle_all_events end - attr_writer :handle_all_events + attr_writer :handle_all_events, :widget_id # @return [String] An ID, unique within a dialog, used for the widget. # By default, the class name is used. def widget_id @widget_id || self.class.to_s end - attr_writer :widget_id # Declare widget type for {Yast::CWMClass}. # Your derived widgets will not need to do this. diff --git a/library/cwm/src/lib/cwm/common_widgets.rb b/library/cwm/src/lib/cwm/common_widgets.rb index 645f51d30..358d4c13b 100644 --- a/library/cwm/src/lib/cwm/common_widgets.rb +++ b/library/cwm/src/lib/cwm/common_widgets.rb @@ -18,6 +18,8 @@ class Empty < AbstractWidget # @param id [String] widget ID def initialize(id) + super() + self.widget_id = id end end diff --git a/library/cwm/src/lib/cwm/dialog.rb b/library/cwm/src/lib/cwm/dialog.rb index 5e53b00b2..dfb465f0b 100644 --- a/library/cwm/src/lib/cwm/dialog.rb +++ b/library/cwm/src/lib/cwm/dialog.rb @@ -27,8 +27,7 @@ def title abstract_method :contents # Constructor (empty to just allow passing extra options) - def initialize(*args, **kws) - end + def initialize(*args, **kws); end # A shortcut for `.new(*args).run` def self.run(*args, **kws) @@ -123,6 +122,8 @@ def help # Empty widget which is first on the page and contain help for whole dialog class FakeHelp < Empty def initialize(text) + super("__fake_help_widget") + @text = text end diff --git a/library/cwm/src/lib/cwm/pager.rb b/library/cwm/src/lib/cwm/pager.rb index 6bbc2fa9c..22c847772 100644 --- a/library/cwm/src/lib/cwm/pager.rb +++ b/library/cwm/src/lib/cwm/pager.rb @@ -18,6 +18,8 @@ class Pager < CustomWidget # @param [Array] pages to be shown def initialize(*pages) + super() + @pages = pages @current_page = nil self.handle_all_events = true @@ -35,7 +37,7 @@ def handle(event) return nil unless page - # Note: don't rely on new_id being equal to page.widget_id + # NOTE: don't rely on new_id being equal to page.widget_id # This may not be true for subclasses redefining #page_for_id # (see bsc#1078212) return nil if @current_page.widget_id == page.widget_id diff --git a/library/cwm/src/lib/cwm/popup.rb b/library/cwm/src/lib/cwm/popup.rb index 074ac9110..60b0f3c22 100644 --- a/library/cwm/src/lib/cwm/popup.rb +++ b/library/cwm/src/lib/cwm/popup.rb @@ -26,11 +26,6 @@ module CWM # This class offers a CWM dialog which behaves as a pop-up. # @see {CWM::Dialog} for remaining configuration options. class Popup < Dialog - # Constructor (empty to just allow passing extra options) - def initialize(*args, **kws) - super - end - # Determines that a dialog should always be open # # @return [true] diff --git a/library/cwm/src/lib/cwm/replace_point.rb b/library/cwm/src/lib/cwm/replace_point.rb index 232428223..7f82a2d9d 100644 --- a/library/cwm/src/lib/cwm/replace_point.rb +++ b/library/cwm/src/lib/cwm/replace_point.rb @@ -12,7 +12,9 @@ class ReplacePoint < CustomWidget # placeholder needed to be in dialog. Parameter type is limited by component # system # @param widget [CWM::AbstractWidget] initial widget in placeholder - def initialize(id: "_placeholder", widget:) + def initialize(widget:, id: "_placeholder") + super() + self.handle_all_events = true self.widget_id = id @widget = widget diff --git a/library/cwm/src/lib/cwm/rspec.rb b/library/cwm/src/lib/cwm/rspec.rb index 3e898a2db..18cc3b016 100644 --- a/library/cwm/src/lib/cwm/rspec.rb +++ b/library/cwm/src/lib/cwm/rspec.rb @@ -148,6 +148,7 @@ end RSpec.shared_examples "CWM::ValueBasedWidget" do + # no specific test yet end RSpec.shared_examples "CWM::CheckBox" do diff --git a/library/cwm/src/lib/cwm/service_widget.rb b/library/cwm/src/lib/cwm/service_widget.rb index 106616c26..527d8938b 100644 --- a/library/cwm/src/lib/cwm/service_widget.rb +++ b/library/cwm/src/lib/cwm/service_widget.rb @@ -28,6 +28,8 @@ class ServiceWidget < CustomWidget # creates new widget instance for given service # @param service [Yast2::SystemService,Yast2::CompoundService] service to be configured def initialize(service) + super() + @service_widget = Yast2::ServiceWidget.new(service) self.handle_all_events = true end diff --git a/library/cwm/src/lib/cwm/ui_state.rb b/library/cwm/src/lib/cwm/ui_state.rb index e502e59e2..37f98be53 100644 --- a/library/cwm/src/lib/cwm/ui_state.rb +++ b/library/cwm/src/lib/cwm/ui_state.rb @@ -165,6 +165,7 @@ def find_tab(pages) # Concrete tab within the current node to show in the next redraw # @return [String, nil] attr_reader :tab + # @see #tab def tab=(tab) @tab = tab diff --git a/library/cwm/src/lib/cwm/wrapper_widget.rb b/library/cwm/src/lib/cwm/wrapper_widget.rb index 80973dd7f..aea2d5179 100644 --- a/library/cwm/src/lib/cwm/wrapper_widget.rb +++ b/library/cwm/src/lib/cwm/wrapper_widget.rb @@ -19,6 +19,8 @@ class WrapperWidget < AbstractWidget # If nil is used, it use default widget_id from class name. # @param content [CWM::WidgetHash] CWM hash definition def initialize(content, id: nil) + super() + self.widget_id = id if id @content = content end diff --git a/library/cwm/src/modules/CWM.rb b/library/cwm/src/modules/CWM.rb index 34aa4fd01..07f2c764f 100644 --- a/library/cwm/src/modules/CWM.rb +++ b/library/cwm/src/modules/CWM.rb @@ -206,10 +206,9 @@ def ValidateValueType(key, value, widget) success = if type.nil? case key when "widget_func" then Ops.is(value, "term ()") - when "init" then Ops.is(value, "void (string)") + when "init", "cleanup" then Ops.is(value, "void (string)") when "handle" then Ops.is(value, "symbol (string, map)") when "store" then Ops.is(value, "void (string, map)") - when "cleanup" then Ops.is(value, "void (string)") when "validate_function" then Ops.is(value, "boolean (string, map)") when "items" then Ops.is(value, "list >") when "_cwm_do_validate" then Ops.is(value, "boolean (string, map )") @@ -244,17 +243,18 @@ def ValidateValueType(key, value, widget) # @return [Boolean] true if validation succeeded def ValidateValueContents(key, value, widget) error = "" - if key == "label" + case key + when "label" s = Convert.to_string(value) if s.nil? || Builtins.size(s) == 0 error = "Empty label" elsif Builtins.size(Builtins.filterchars(s, "&")) != 1 error = "Label has no shortcut or more than 1 shortcuts" end - elsif key == "widget" + when "widget" s = Convert.to_symbol(value) error = "No widget specified" if s.nil? - elsif key == "custom_widget" + when "custom_widget" s = Convert.to_term(value) error = "No custom widget specified" if s.nil? end @@ -271,7 +271,7 @@ def GetLowestTimeout(widgets) minimum = 0 Builtins.foreach(widgets) do |w| timeout = Ops.get_integer(w, "ui_timeout", 0) - if Ops.less_than(timeout, minimum) && Ops.greater_than(timeout, 0) || + if (Ops.less_than(timeout, minimum) && Ops.greater_than(timeout, 0)) || minimum == 0 minimum = timeout end @@ -432,19 +432,20 @@ def ValidateMaps(widgets) Builtins.foreach(v) do |kk, vv| ret = ValidateValueType(kk, vv, k) && ret end - to_check = if Ops.get(v, "widget") == :custom + to_check = case Ops.get(v, "widget") + when :custom ["custom_widget"] - elsif Ops.get(v, "widget") == :empty + when :empty [] else ["label", "widget"] end Builtins.foreach(to_check) do |key| if key != "label" || - Ops.get(v, "widget") != :radio_buttons && + (Ops.get(v, "widget") != :radio_buttons && Ops.get(v, "widget") != :custom && Ops.get(v, "widget") != :rich_text && - Ops.get(v, "widget") != :func + Ops.get(v, "widget") != :func) ret = ValidateValueContents(key, Ops.get(v, key), k) && ret end end @@ -488,10 +489,10 @@ def prepareWidget(widget_descr) from: "any", to: "term ()" ) - if !toEval.nil? - Ops.set(w, "widget", toEval.call) - else + if toEval.nil? Ops.set(w, "widget", VBox()) + else + Ops.set(w, "widget", toEval.call) end else id_term = Id(Ops.get_string(w, "_cwm_key", "")) @@ -551,7 +552,7 @@ def prepareWidget(widget_descr) ) when :intfield min = Ops.get_integer(w, "minimum", 0) - max = Ops.get_integer(w, "maximum", 2**31 - 1) # libyui support only signed int + max = Ops.get_integer(w, "maximum", (2**31) - 1) # libyui support only signed int Ops.set( w, "widget", @@ -796,7 +797,7 @@ def Run(widgets, functions, skip_store_for: []) handleDebug if Ops.get_string(event_descr, "EventType", "") == "DebugEvent" handle_ret = handleWidgets(widgets, event_descr) if !handle_ret.nil? || - Ops.is_symbol?(ret) && Builtins.contains(save_exits, ret) + (Ops.is_symbol?(ret) && Builtins.contains(save_exits, ret)) save = true if !handle_ret.nil? ret = handle_ret @@ -853,22 +854,22 @@ def AdjustButtons(next_, back, abort, _help) next_ = "" if next_.nil? back = "" if back.nil? abort = "" if abort.nil? - if next_ != "" - Wizard.SetNextButton(:next, next_) - else + if next_ == "" Wizard.HideNextButton + else + Wizard.SetNextButton(:next, next_) end - if abort != "" - Wizard.SetAbortButton(:abort, abort) - else + if abort == "" Wizard.HideAbortButton + else + Wizard.SetAbortButton(:abort, abort) end - if back != "" - Wizard.SetBackButton(:back, back) - else + if back == "" Wizard.HideBackButton + else + Wizard.SetBackButton(:back, back) end nil @@ -914,7 +915,7 @@ def show(contents, caption: nil, back_button: nil, next_button: nil, abort_butto options = { "contents" => widgets_contents(contents), "widget_names" => widgets.map(&:widget_id), - "widget_descr" => Hash[widgets.map { |w| [w.widget_id, w.cwm_definition] }] + "widget_descr" => widgets.map { |w| [w.widget_id, w.cwm_definition] }.to_h } options["caption"] = caption if caption options["back_button"] = back_button if back_button @@ -941,7 +942,7 @@ def ShowAndRun(settings) settings["widget_names"] ||= [] settings["widget_names"] += widgets.map(&:widget_id) settings["widget_descr"] ||= {} - settings["widget_descr"] = Hash[widgets.map { |w| [w.widget_id, w.cwm_definition] }] + settings["widget_descr"] = widgets.map { |w| [w.widget_id, w.cwm_definition] }.to_h end widget_descr = Ops.get_map(settings, "widget_descr", {}) contents = Ops.get_term(settings, "contents", VBox()) diff --git a/library/cwm/src/modules/CWMServiceStart.rb b/library/cwm/src/modules/CWMServiceStart.rb index c33c59287..f4bf407c5 100644 --- a/library/cwm/src/modules/CWMServiceStart.rb +++ b/library/cwm/src/modules/CWMServiceStart.rb @@ -221,8 +221,8 @@ def AutoStartHelpTemplate # (both without quotes) _( "

Service Start
\n" \ - "To start the service every time your computer is booted, set\n" \ - "%1. Otherwise set %2.

" + "To start the service every time your computer is booted, set\n" \ + "%1. Otherwise set %2.

" ) end @@ -237,9 +237,9 @@ def AutoStartHelpSocketTemplate # (both without quotes) _( "

Service Start
\n" \ - "To start the service every time your computer is booted, set\n" \ - "%1. To start the service via systemd socket activation, " \ - "set %3.\nOtherwise set %2.

" + "To start the service every time your computer is booted, set\n" \ + "%1. To start the service via systemd socket activation, " \ + "set %3.\nOtherwise set %2.

" ) end @@ -414,7 +414,8 @@ def StartStopHandle(widget, _key, event) widget = deep_copy(widget) event = deep_copy(event) event_id = Ops.get(event, "ID") - if event_id == "_cwm_start_service_now" + case event_id + when "_cwm_start_service_now" if Builtins.haskey(widget, "start_now_action") start_now_func = Convert.convert( Ops.get(widget, "start_now_action"), @@ -426,7 +427,7 @@ def StartStopHandle(widget, _key, event) Service.Restart(Ops.get_string(widget, "service_id", "")) end Builtins.sleep(500) - elsif event_id == "_cwm_stop_service_now" + when "_cwm_stop_service_now" if Builtins.haskey(widget, "stop_now_action") stop_now_func = Convert.convert( Ops.get(widget, "stop_now_action"), @@ -438,7 +439,7 @@ def StartStopHandle(widget, _key, event) Service.Stop(Ops.get_string(widget, "service_id", "")) end Builtins.sleep(500) - elsif event_id == "_cwm_save_settings_now" + when "_cwm_save_settings_now" func = Convert.convert( Ops.get(widget, "save_now_action"), from: "any", @@ -500,8 +501,8 @@ def StartStopHelpTemplate(restart_displayed) # (both without quotes) help = _( "

Switch On or Off
\n" \ - "To start or stop the service immediately, use \n" \ - "%1 or %2.

" + "To start or stop the service immediately, use \n" \ + "%1 or %2.

" ) if restart_displayed # help text for service start widget 2/2, optional @@ -721,8 +722,8 @@ def EnableLdapHelpTemplate # %1 is button label, eg. "LDAP Support Active" (without quotes) _( "

LDAP Support
\n" \ - "To store the settings in LDAP instead of native configuration files,\n" \ - "set %1.

" + "To store the settings in LDAP instead of native configuration files,\n" \ + "set %1.

" ) end diff --git a/library/cwm/src/modules/CWMTable.rb b/library/cwm/src/modules/CWMTable.rb index ec862c13b..2e7f677b9 100644 --- a/library/cwm/src/modules/CWMTable.rb +++ b/library/cwm/src/modules/CWMTable.rb @@ -209,12 +209,10 @@ def TableHandle(descr, key, event_descr) index = counter if getItemId(t) == id counter = Ops.add(counter, 1) end - if event_id == :_tw_table - if Ops.get_string(event_descr, "EventReason", "") == "Activated" && + if event_id == :_tw_table && (Ops.get_string(event_descr, "EventReason", "") == "Activated" && Ops.get_string(event_descr, "EventType", "") == "WidgetEvent" && - UI.WidgetExists(Id(:_tw_edit)) - event_id = :_tw_edit - end + UI.WidgetExists(Id(:_tw_edit))) + event_id = :_tw_edit end case event_id when :_tw_edit diff --git a/library/cwm/src/modules/CWMTsigKeys.rb b/library/cwm/src/modules/CWMTsigKeys.rb index a7774adbb..e686cf16d 100644 --- a/library/cwm/src/modules/CWMTsigKeys.rb +++ b/library/cwm/src/modules/CWMTsigKeys.rb @@ -279,7 +279,8 @@ def Handle(widget, _key, event) new_filename = Convert.to_string( UI.QueryWidget(Id("_cwm_new_key_file"), :Value) ) - if ret == "_cwm_delete_key" + case ret + when "_cwm_delete_key" key2 = Convert.to_string( UI.QueryWidget(Id("_cwm_key_listing_table"), :CurrentItem) ) @@ -300,8 +301,8 @@ def Handle(widget, _key, event) # popup message message = _( "The selected TSIG key cannot be deleted,\n" \ - "because it is in use.\n" \ - "Stop using it in the configuration first." + "because it is in use.\n" \ + "Stop using it in the configuration first." ) # popup title Popup.AnyMessage(_("Cannot delete TSIG key."), message) @@ -309,7 +310,7 @@ def Handle(widget, _key, event) end end RemoveTSIGKeyFile(delete_filename) - elsif ret == "_cwm_browse_existing_key_file" + when "_cwm_browse_existing_key_file" existing_filename = UI.AskForExistingFile( existing_filename, "", @@ -324,7 +325,7 @@ def Handle(widget, _key, event) ) end return nil - elsif ret == "_cwm_browse_new_key_file" + when "_cwm_browse_new_key_file" new_filename = UI.AskForSaveFileName( new_filename, "", @@ -333,7 +334,7 @@ def Handle(widget, _key, event) ) UI.ChangeWidget(Id("_cwm_new_key_file"), :Value, new_filename) if !new_filename.nil? return nil - elsif ret == "_cwm_generate_key" + when "_cwm_generate_key" if !UI.WidgetExists(Id("_cwm_new_key_file")) Builtins.y2error("No such UI widget: %1", "_cwm_new_key_file") return nil @@ -366,14 +367,14 @@ def Handle(widget, _key, event) # specified key exists if Key2File(key2) != "" # yes-no popup - if !Popup.YesNo( + if Popup.YesNo( _("The key with the specified ID exists and is used.\nRemove it?") ) - return nil - else remove_file = Key2File(key2) DeleteTSIGKeyFromDisk(remove_file) RemoveTSIGKeyFile(remove_file) + else + return nil end end # specified key is present on the disk, but not used @@ -384,28 +385,25 @@ def Handle(widget, _key, event) "/usr/bin/ls /etc/named.d/K%1\\.*", Builtins.tolower(key2).shellescape ) - ) - # yes-no popup - if Popup.YesNo( + ) && Popup.YesNo( _( "A key with the specified ID was found\non your disk. Remove it?" ) ) - SCR.Execute( - path(".target.bash"), - Builtins.sformat( - "/usr/bin/rm -rf `/usr/bin/ls /etc/named.d/K%1\\.*`", - Builtins.tolower(key2).shellescape - ) - ) - files = Convert.convert( - SCR.Read(path(".target.dir"), "/etc/named.d"), - from: "any", - to: "list " + SCR.Execute( + path(".target.bash"), + Builtins.sformat( + "/usr/bin/rm -rf `/usr/bin/ls /etc/named.d/K%1\\.*`", + Builtins.tolower(key2).shellescape ) - Builtins.foreach(files) do |f| - DeleteTSIGKeyFromDisk(f) if Builtins.contains(AnalyzeTSIGKeyFile(f), key2) - end + ) + files = Convert.convert( + SCR.Read(path(".target.dir"), "/etc/named.d"), + from: "any", + to: "list " + ) + Builtins.foreach(files) do |f| + DeleteTSIGKeyFromDisk(f) if Builtins.contains(AnalyzeTSIGKeyFile(f), key2) end end @@ -452,16 +450,16 @@ def Handle(widget, _key, event) end if Ops.greater_than(Builtins.size(coliding_files), 0) # yes-no popup - if !Popup.YesNo( + if Popup.YesNo( _( "The specified file contains a TSIG key with the same\n" \ - "identifier as some of already present keys.\n" \ - "Old keys will be removed. Continue?" + "identifier as some of already present keys.\n" \ + "Old keys will be removed. Continue?" ) ) - return nil - else Builtins.foreach(coliding_files) { |f| RemoveTSIGKeyFile(f) } + else + return nil end end AddTSIGKeyFile(existing_filename) @@ -562,24 +560,24 @@ def CreateWidget(settings) # tsig keys management dialog help 2/4 _( "

Adding an Existing TSIG Key
\n" \ - "To add an already created TSIG key, select a Filename of the file\n" \ - "containing the key and click Add.

\n" + "To add an already created TSIG key, select a Filename of the file\n" \ + "containing the key and click Add.

\n" ) + # tsig keys management dialog help 3/4 _( "

Creating a New TSIG Key
\n" \ - "To create a new TSIG key, set the Filename of the file in which to\n" \ - "create the key and the Key ID to identify the key then click\n" \ - "Generate.

\n" + "To create a new TSIG key, set the Filename of the file in which to\n" \ + "create the key and the Key ID to identify the key then click\n" \ + "Generate.

\n" ) + # tsig keys management dialog help 4/4 _( "

Removing a TSIG Key
\n" \ - "To remove a configured TSIG key, select it and click Delete.\n" \ - "All keys in the same file are deleted.\n" \ - "If a TSIG key is in use in the configuration\n" \ - "of the server, it cannot be deleted. The server must stop using it\n" \ - "in the configuration first.

\n" + "To remove a configured TSIG key, select it and click Delete.\n" \ + "All keys in the same file are deleted.\n" \ + "If a TSIG key is in use in the configuration\n" \ + "of the server, it cannot be deleted. The server must stop using it\n" \ + "in the configuration first.

\n" ) add_existing = VSquash( diff --git a/library/cwm/src/modules/DialogTree.rb b/library/cwm/src/modules/DialogTree.rb index 84e6dc140..eae3dbdcf 100644 --- a/library/cwm/src/modules/DialogTree.rb +++ b/library/cwm/src/modules/DialogTree.rb @@ -313,9 +313,7 @@ def ShowAndRun(settings) to: "list ()" ) - if !tree_handler.nil? - ShowTree(tree_handler) - else + if tree_handler.nil? ShowFlat(ids_order, screens) if Ops.get_string(settings, "initial_screen", "") == "" Builtins.find(ids_order) do |s| @@ -323,6 +321,8 @@ def ShowAndRun(settings) true end end + else + ShowTree(tree_handler) end AdjustButtonsAny(settings) RunAndHide(settings) diff --git a/library/cwm/src/modules/TablePopup.rb b/library/cwm/src/modules/TablePopup.rb index f3bd328f9..60753d079 100644 --- a/library/cwm/src/modules/TablePopup.rb +++ b/library/cwm/src/modules/TablePopup.rb @@ -101,40 +101,31 @@ def ValidateValueType(key, value, widget, popup) value = deep_copy(value) success = true if popup - if key == "init" + case key + when "init", "store", "cleanup" success = Ops.is(value, "void (any, string)") - elsif key == "handle" + when "handle" success = Ops.is(value, "void (any, string, map)") || Ops.is_symbol?(value) - elsif key == "store" - success = Ops.is(value, "void (any, string)") - elsif key == "cleanup" - success = Ops.is(value, "void (any, string)") - elsif key == "validate_function" + when "validate_function" success = Ops.is(value, "boolean (any, string, map)") - elsif key == "optional" + when "optional" success = Ops.is_boolean?(value) - elsif key == "label_func" + when "label_func" success = Ops.is(value, "string (any, string)") else return CWM.ValidateValueType(key, value, widget) end - elsif key == "id2key" - success = Ops.is(value, "string (map, any)") - elsif key == "ids" - success = Ops.is(value, "list (map)") - elsif key == "option_delete" - success = Ops.is(value, "boolean (any, string)") - elsif key == "summary" - success = Ops.is(value, "string (any, string)") - elsif key == "label_func" - success = Ops.is(value, "string (any, string)") - elsif key == "option_move" - success = Ops.is(value, "any (any, string, symbol)") - elsif key == "options" - success = Ops.is(value, "map ") - elsif key == "add_items" - success = Ops.is_list?(value) + else + success = case key + when "id2key" then Ops.is(value, "string (map, any)") + when "ids" then Ops.is(value, "list (map)") + when "option_delete" then Ops.is(value, "boolean (any, string)") + when "summary", "label_func" then Ops.is(value, "string (any, string)") + when "option_move" then Ops.is(value, "any (any, string, symbol)") + when "options" then Ops.is(value, "map ") + when "add_items" then Ops.is_list?(value) + end end if !success @@ -589,9 +580,7 @@ def singleOptionEditPopup(option) from: "any", to: "boolean (any, string, map)" ) - if !toEval.nil? - ret = nil if !toEval.call(opt_id, opt_key, event_descr2) - end + ret = nil if !toEval.nil? && !toEval.call(opt_id, opt_key, event_descr2) elsif !CWM.validateWidget(popup_descr, event_descr2, opt_key) ret = nil end @@ -669,19 +658,18 @@ def TableHandle(descr, key, event_descr) event_descr = deep_copy(event_descr) event_id = Ops.get(event_descr, "ID") UI.SetFocus(Id(:_tp_table)) - if event_id == :_tp_table - if Ops.get_string(event_descr, "EventReason", "") == "Activated" && + if event_id == :_tp_table && (Ops.get_string(event_descr, "EventReason", "") == "Activated" && Ops.get_string(event_descr, "EventType", "") == "WidgetEvent" && - UI.WidgetExists(Id(:_tp_edit)) - event_id = :_tp_edit - end + UI.WidgetExists(Id(:_tp_edit))) + event_id = :_tp_edit end case event_id when :_tp_edit, :_tp_add opt_key = nil opt_id = nil - if event_id == :_tp_add + case event_id + when :_tp_add add_unlisted = Ops.get_boolean(descr, "add_unlisted", true) if !add_unlisted && Builtins.size(Ops.get_list(descr, "add_items", [])) == 1 @@ -715,7 +703,7 @@ def TableHandle(descr, key, event_descr) end end return nil if opt_key.nil? - elsif event_id == :_tp_edit + when :_tp_edit opt_id = UI.QueryWidget(Id(:_tp_table), :CurrentItem) opt_key = id2key(descr, opt_id) end @@ -723,10 +711,7 @@ def TableHandle(descr, key, event_descr) toEval = Ops.get(option_map, ["table", "handle"]) if !toEval.nil? # if (is (toEval, symbol)) - if !Ops.is(toEval, "symbol (any, string, map)") - ret2 = Convert.to_symbol(toEval) - return ret2 - else + if Ops.is(toEval, "symbol (any, string, map)") toEval_c = Convert.convert( Ops.get(option_map, ["table", "handle"]), from: "any", @@ -734,6 +719,9 @@ def TableHandle(descr, key, event_descr) ) ret2 = toEval_c.call(opt_id, opt_key, event_descr) return ret2 if ret2 != :_tp_normal + else + ret2 = Convert.to_symbol(toEval) + return ret2 end end Ops.set(option_map, "_cwm_id", opt_id) @@ -745,9 +733,10 @@ def TableHandle(descr, key, event_descr) ) ret = singleOptionEditPopup(option_map) if ret == :_tp_ok - if event_id == :_tp_add + case event_id + when :_tp_add TableInit(descr, key) - elsif event_id == :_tp_edit + when :_tp_edit column = descr.fetch("_cwm_attrib", {}).fetch("changed_column", false) ? 2 : 1 UI.ChangeWidget( Id(:_tp_table), @@ -791,6 +780,8 @@ def TableHandle(descr, key, event_descr) current_index = Ops.add(current_index, 1) e == opt_id end + # rubocop:disable Lint/DuplicateBranch + # rubocop here wrongly detect logic in if conditions to decide step direction step = if current_index == 0 1 elsif Ops.add(current_index, 1) == Builtins.size(id_list) @@ -800,6 +791,7 @@ def TableHandle(descr, key, event_descr) else -1 end + # rubocop:enable Lint/DuplicateBranch new_index = Ops.add(current_index, step) opt_id = Ops.get(id_list, new_index) UI.ChangeWidget(Id(:_tp_table), :CurrentItem, opt_id) @@ -891,8 +883,8 @@ def CreateTableDescr(attrib, widget_descr) # help 1/4 help = _( "

Editing the Settings
\n" \ - "To edit the settings, choose the appropriate\n" \ - "entry of the table then click Edit.

" + "To edit the settings, choose the appropriate\n" \ + "entry of the table then click Edit.

" ) if Ops.get_boolean(attrib, "add_delete_buttons", true) # help 2/4, optional @@ -920,8 +912,8 @@ def CreateTableDescr(attrib, widget_descr) help, _( "

To reorder the options, select an option\n" \ - "and use Up and Down to move it up or down\n" \ - "in the list.

" + "and use Up and Down to move it up or down\n" \ + "in the list.

" ) ) end diff --git a/library/cwm/src/modules/WizardHW.rb b/library/cwm/src/modules/WizardHW.rb index 2f253c69b..7acd0758d 100644 --- a/library/cwm/src/modules/WizardHW.rb +++ b/library/cwm/src/modules/WizardHW.rb @@ -110,15 +110,15 @@ def _SetSelectedItem(selected) # Used when using the callback interface # @param [String] key strnig the widget key def Init(_key) - if !@set_items_callback.nil? - @set_items_callback.call - else + if @set_items_callback.nil? Builtins.y2warning("No initialization callback") - end - if !@select_initial_item_callback.nil? - @select_initial_item_callback.call else + @set_items_callback.call + end + if @select_initial_item_callback.nil? _SetSelectedItem(Ops.get_string(@current_items, [0, "id"])) + else + @select_initial_item_callback.call end nil diff --git a/library/cwm/test/abstract_widget_test.rb b/library/cwm/test/abstract_widget_test.rb index 5010361fd..83a3c5487 100755 --- a/library/cwm/test/abstract_widget_test.rb +++ b/library/cwm/test/abstract_widget_test.rb @@ -13,6 +13,8 @@ describe "#widget_id" do class T1 < CWM::AbstractWidget def initialize(id: nil) + super() + self.widget_id = id end end @@ -41,6 +43,8 @@ class T2 < CWM::AbstractWidget describe "#handle_all_events" do class T3 < CWM::AbstractWidget def initialize(all: nil) + super() + self.handle_all_events = all end end @@ -118,6 +122,8 @@ class THandleEvents < CWM::AbstractWidget self.widget_type = :empty def initialize + super + self.widget_id = "test" self.handle_all_events = false end @@ -133,6 +139,8 @@ class TNotHandleEvents < CWM::AbstractWidget self.widget_type = :empty def initialize + super + self.handle_all_events = true end end @@ -193,6 +201,8 @@ class TFocus < CWM::AbstractWidget self.widget_type = :empty def initialize + super + self.widget_id = "test" end end @@ -211,6 +221,8 @@ class TPresent < CWM::AbstractWidget self.widget_type = :empty def initialize + super + self.widget_id = "test" end end diff --git a/library/cwm/test/custom_widget_test.rb b/library/cwm/test/custom_widget_test.rb index 48066f7ac..9e959b3c3 100755 --- a/library/cwm/test/custom_widget_test.rb +++ b/library/cwm/test/custom_widget_test.rb @@ -19,6 +19,8 @@ def contents context "handle_all_events is false" do class IsolationistTestWidget < CustomTestWidget def initialize + super + self.handle_all_events = false self.widget_id = "test_widget" end diff --git a/library/cwm/test/dialog_test.rb b/library/cwm/test/dialog_test.rb index 707527e07..b07477807 100755 --- a/library/cwm/test/dialog_test.rb +++ b/library/cwm/test/dialog_test.rb @@ -7,7 +7,10 @@ describe "CWM::Dialog" do class TestCWMDialog < CWM::Dialog attr_reader :title, :disable + def initialize(title = "test", disable: :abort) + super() + @title = title @disable = disable end diff --git a/library/cwm/test/pager_test.rb b/library/cwm/test/pager_test.rb index cce3323ce..0fd95ea9c 100755 --- a/library/cwm/test/pager_test.rb +++ b/library/cwm/test/pager_test.rb @@ -8,7 +8,10 @@ class TestPage < CWM::Page attr_reader :label, :contents + def initialize(number) + super() + self.widget_id = "page#{number}" @label = "Page #{number}" @contents = Yast::Term.new(:Empty, Yast::Term.new(:id, "empty#{number}")) diff --git a/library/cwm/test/test_helper.rb b/library/cwm/test/test_helper.rb index 08dc933d5..6affe9fe9 100755 --- a/library/cwm/test/test_helper.rb +++ b/library/cwm/test/test_helper.rb @@ -1 +1 @@ -require_relative "../../../test/test_helper.rb" +require_relative "../../../test/test_helper" diff --git a/library/cwm/test/tree_pager_test.rb b/library/cwm/test/tree_pager_test.rb index 1428b114f..888dde42a 100755 --- a/library/cwm/test/tree_pager_test.rb +++ b/library/cwm/test/tree_pager_test.rb @@ -10,7 +10,10 @@ describe CWM::TreePager do class TestPage < CWM::Page attr_reader :label, :contents + def initialize(number) + super() + self.widget_id = "page#{number}" @label = "Page #{number}" @contents = Yast::Term.new(:Empty, Yast::Term.new(:id, "empty#{number}")) diff --git a/library/cwm/test/tree_test.rb b/library/cwm/test/tree_test.rb index 0869e7810..ecc4044ca 100755 --- a/library/cwm/test/tree_test.rb +++ b/library/cwm/test/tree_test.rb @@ -26,11 +26,14 @@ def items include_examples "CWM::CustomWidget" describe "#items" do + # TODO: pending end describe "#items=" do + # TODO: pending end describe "change_items" do + # TODO: pending end end diff --git a/library/desktop/src/clients/menu.rb b/library/desktop/src/clients/menu.rb index f8028e0a5..c8feac5ff 100644 --- a/library/desktop/src/clients/menu.rb +++ b/library/desktop/src/clients/menu.rb @@ -326,10 +326,10 @@ def ShowNcursesHelp # NCurses Control Center help 1/ help = _( "

1) General
\n" \ - "Navigate through the dialog elements with [TAB] to go to\n" \ - "the next element and [SHIFT] (or [ALT]) + [TAB] to move backwards.\n" \ - "Select or activate elements with [SPACE] or [ENTER].\n" \ - "Some elements use arrow keys (e.g., to scroll in lists).

" + "Navigate through the dialog elements with [TAB] to go to\n" \ + "the next element and [SHIFT] (or [ALT]) + [TAB] to move backwards.\n" \ + "Select or activate elements with [SPACE] or [ENTER].\n" \ + "Some elements use arrow keys (e.g., to scroll in lists).

" ) + # NCurses Control Center help 2/10 _( @@ -349,38 +349,38 @@ def ShowNcursesHelp # NCurses Control Center help 5/10 _( "

2) Substitution of Keystrokes
\n" \ - "

Because the environment can affect the use of the keyboard,\n" \ - "there is more than one way to navigate the dialog pages.\n" \ - "If [TAB] and [SHIFT] (or [ALT]) + [TAB] do not work,\n" \ - "move focus forward with [CTRL] + [F] and backward with [CTRL] + [B].

" + "

Because the environment can affect the use of the keyboard,\n" \ + "there is more than one way to navigate the dialog pages.\n" \ + "If [TAB] and [SHIFT] (or [ALT]) + [TAB] do not work,\n" \ + "move focus forward with [CTRL] + [F] and backward with [CTRL] + [B].

" ) + # NCurses Control Center help 6/10 _( "

If [ALT] + [letter] does not work,\n" \ - "try [ESC] + [letter]. Example: [ESC] + [H] for [ALT] + [H].\n" \ - "[ESC] + [TAB] is also a substitute for [ALT] + [TAB].

" + "try [ESC] + [letter]. Example: [ESC] + [H] for [ALT] + [H].\n" \ + "[ESC] + [TAB] is also a substitute for [ALT] + [TAB].

" ) + # NCurses Control Center help 7/10 _( "

3) Function Keys
\n" \ - "F keys provide a quick access to main functions. " \ - "The function key bindings for the current dialog are " \ - "shown in the bottom line.

" + "F keys provide a quick access to main functions. " \ + "The function key bindings for the current dialog are " \ + "shown in the bottom line.

" ) + # NCurses Control Center help 8/10 _("

The F keys are usually connected to a certain action:

") + # NCurses Control Center help 9/10 _( "F1 = Help
\n" \ - "F2 = Info or Description
\n" \ - "F3 = Add
\n" \ - "F4 = Edit or Configure
\n" \ - "F5 = Delete
\n" \ - "F6 = Test
\n" \ - "F7 = Expert or Advanced
\n" \ - "F8 = Back
\n" \ - "F9 = Abort or Cancel
\n" \ - "F10 = OK, Next, Finish, or Accept
" + "F2 = Info or Description
\n" \ + "F3 = Add
\n" \ + "F4 = Edit or Configure
\n" \ + "F5 = Delete
\n" \ + "F6 = Test
\n" \ + "F7 = Expert or Advanced
\n" \ + "F8 = Back
\n" \ + "F9 = Abort or Cancel
\n" \ + "F10 = OK, Next, Finish, or Accept
" ) + # NCurses Control Center help 10/10 _("

In some environments, all or some\nF keys are not available.

") diff --git a/library/desktop/src/modules/Desktop.rb b/library/desktop/src/modules/Desktop.rb index dda60113a..811061300 100644 --- a/library/desktop/src/modules/Desktop.rb +++ b/library/desktop/src/modules/Desktop.rb @@ -105,7 +105,7 @@ def ReadLanguage # Do not use UI.GetLanguage. It would start an UI which is not # needed for it. - @Language = ENV["LANG"].split(/[\.,@]/).first if ENV["LANG"] + @Language = ENV["LANG"].split(/[.,@]/).first if ENV["LANG"] @LanguageFull = Builtins.regexpsub(@Language, "(.*_[^.]*)\\.?.*", "\\1") if Builtins.regexpmatch(@Language, "(.*_[^.]*)\\.?.*") # matches: ll_TT ll_TT.UTF-8 @Language = Builtins.regexpsub(@Language, "(.*)_", "\\1") if Builtins.regexpmatch(@Language, "(.*)_") @@ -408,7 +408,7 @@ def ParseSingleDesktopFile(file) private # @return [Regexp] Regular expression which matches the module name of a desktop file - FILE_REGEXP = /([^\.]+).desktop\Z/.freeze + FILE_REGEXP = /([^.]+).desktop\Z/.freeze # Converts the file name to the expected module name # diff --git a/library/desktop/test/test_helper.rb b/library/desktop/test/test_helper.rb index fbed98e04..645f3d31c 100644 --- a/library/desktop/test/test_helper.rb +++ b/library/desktop/test/test_helper.rb @@ -16,6 +16,6 @@ # # To contact SUSE LLC about this file by physical or electronic mail, you may # find current contact information at www.suse.com. -require_relative "../../../test/test_helper.rb" +require_relative "../../../test/test_helper" DESKTOP_DATA_PATH = File.join(__dir__, "data") diff --git a/library/general/example/popup_serie.rb b/library/general/example/popup_serie.rb index 88e8cf2c5..7bc70a5fb 100644 --- a/library/general/example/popup_serie.rb +++ b/library/general/example/popup_serie.rb @@ -4,7 +4,7 @@ Yast2::Popup.show("Simple text") -Yast2::Popup.show("First paragraph.\n\n" + "Long text without newlines. " * 50) +Yast2::Popup.show("First paragraph.\n\n" + ("Long text without newlines. " * 50)) Yast2::Popup.show("First paragraph.", details: "Long text without newlines. " * 50) diff --git a/library/general/src/lib/cfa/conflict_report.rb b/library/general/src/lib/cfa/conflict_report.rb index 03f747d7c..286020110 100644 --- a/library/general/src/lib/cfa/conflict_report.rb +++ b/library/general/src/lib/cfa/conflict_report.rb @@ -39,8 +39,8 @@ def self.report(conflicts) text = "" text << _("Changed values have conflicts with:

") conflicts.each do |filename, conflict| - text << _("File: %s
") % filename - text << _("Conflicting entries: %s
") % conflict.join(", ") + text << (_("File: %s
") % filename) + text << (_("Conflicting entries: %s
") % conflict.join(", ")) text << "
" end text << _("You will have to adapt these entries manually in order to set your changes.") diff --git a/library/general/src/lib/cfa/sysctl_config.rb b/library/general/src/lib/cfa/sysctl_config.rb index 48af3ee4f..477a83c27 100644 --- a/library/general/src/lib/cfa/sysctl_config.rb +++ b/library/general/src/lib/cfa/sysctl_config.rb @@ -170,10 +170,10 @@ def file_paths_in(path) def boot_config_path return @boot_config_path if @boot_config_path - @boot_config_path = if !kernel_version.empty? - "/boot/sysctl.conf-#{kernel_version}" - else + @boot_config_path = if kernel_version.empty? "" + else + "/boot/sysctl.conf-#{kernel_version}" end end diff --git a/library/general/src/lib/installation/autoinst_issues/invalid_value.rb b/library/general/src/lib/installation/autoinst_issues/invalid_value.rb index 75b6cecc8..c150bd78e 100644 --- a/library/general/src/lib/installation/autoinst_issues/invalid_value.rb +++ b/library/general/src/lib/installation/autoinst_issues/invalid_value.rb @@ -35,6 +35,8 @@ class InvalidValue < ::Installation::AutoinstIssues::Issue # @param description [String] additional explanation # @param severity [Symbol] :warn, :fatal = abort the installation def initialize(section, attribute, value, description, severity = :warn) + super() + textdomain "base" @section = section @attribute = attribute diff --git a/library/general/src/lib/installation/autoinst_issues/missing_value.rb b/library/general/src/lib/installation/autoinst_issues/missing_value.rb index ad735c4ed..8159858d0 100644 --- a/library/general/src/lib/installation/autoinst_issues/missing_value.rb +++ b/library/general/src/lib/installation/autoinst_issues/missing_value.rb @@ -26,14 +26,15 @@ module AutoinstIssues # @example Missing value for attribute 'bar' in 'foo' section. # problem = AyMissingValue.new("foo","bar") class MissingValue < ::Installation::AutoinstIssues::Issue - attr_reader :section, :attribute - attr_reader :description, :severity + attr_reader :section, :attribute, :description, :severity # @param section [String] Section where it was detected # @param attribute [String] Name of the missing attribute # @param description [String] additional explanation; optional # @param severity [Symbol] :warn, :error = abort the installation ; optional def initialize(section, attr, description = "", severity = :warn) + super() + textdomain "base" @section = section diff --git a/library/general/src/lib/ui/greasemonkey.rb b/library/general/src/lib/ui/greasemonkey.rb index 5f194b751..3660eb1af 100644 --- a/library/general/src/lib/ui/greasemonkey.rb +++ b/library/general/src/lib/ui/greasemonkey.rb @@ -148,7 +148,7 @@ def LeftRadioButton(old) end module_function :LeftRadioButton - # NOTE that it does not expand the nested + # NOTE: that it does not expand the nested # Greasemonkey term LeftRadioButton! {#transform} does that. # @param old [Yast::Term] # @return [Yast::Term] @@ -165,10 +165,10 @@ def LeftRadioButtonWithAttachment(old) tmp1 = Builtins.sublist(args, 0, Ops.subtract(Builtins.size(args), 1)) tmp2 = Ops.get(args, Ops.subtract(Builtins.size(args), 1)) - if tmp2 == Empty() # rubocop:disable Style/GuardClause - return VBox(Builtins.toterm(:LeftRadioButton, tmp1)) + if tmp2 == Empty() + VBox(Builtins.toterm(:LeftRadioButton, tmp1)) else - return VBox( + VBox( Builtins.toterm(:LeftRadioButton, tmp1), HBox(HSpacing(4), tmp2) ) @@ -187,7 +187,7 @@ def LeftCheckBox(old) end module_function :LeftCheckBox - # NOTE that it does not expand the nested + # NOTE: that it does not expand the nested # Greasemonkey term LeftCheckBox! {#transform} does that. # @param old [Yast::Term] # @return [Yast::Term] @@ -204,10 +204,10 @@ def LeftCheckBoxWithAttachment(old) tmp1 = Builtins.sublist(args, 0, Ops.subtract(Builtins.size(args), 1)) tmp2 = Ops.get(args, Ops.subtract(Builtins.size(args), 1)) - if tmp2 == Empty() # rubocop:disable Style/GuardClause - return VBox(Builtins.toterm(:LeftCheckBox, tmp1)) + if tmp2 == Empty() + VBox(Builtins.toterm(:LeftCheckBox, tmp1)) else - return VBox( + VBox( Builtins.toterm(:LeftCheckBox, tmp1), HBox(HSpacing(4), tmp2) ) @@ -245,11 +245,10 @@ def Transform(old) handler = Greasemonkey.method(s) if @handlers.include?(s) return Transform(handler.call(old)) if !handler.nil? - new = Builtins::List.reduce(Builtins.toterm(s), Builtins.argsof(old)) do |tmp, arg| + Builtins::List.reduce(Builtins.toterm(s), Builtins.argsof(old)) do |tmp, arg| arg = Transform(Convert.to_term(arg)) if Ops.is_term?(arg) Builtins.add(tmp, arg) end - new end module_function :Transform diff --git a/library/general/src/lib/ui/widgets.rb b/library/general/src/lib/ui/widgets.rb index 1d9d5fa5d..eaf867d4b 100644 --- a/library/general/src/lib/ui/widgets.rb +++ b/library/general/src/lib/ui/widgets.rb @@ -26,6 +26,8 @@ module Widgets # Its value is ignored and never used anywhere. class KeyboardLayoutTest < CWM::InputField def initialize + super + textdomain "base" end diff --git a/library/general/src/lib/y2issues/invalid_value.rb b/library/general/src/lib/y2issues/invalid_value.rb index ae2c9bf7d..190c6e45a 100644 --- a/library/general/src/lib/y2issues/invalid_value.rb +++ b/library/general/src/lib/y2issues/invalid_value.rb @@ -40,7 +40,7 @@ def build_message(value, fallback) _("A value is required.").dup end - msg << " " + format(_("Using '%{fallback}' instead."), fallback: fallback) if fallback + msg << (" " + format(_("Using '%{fallback}' instead."), fallback: fallback)) if fallback msg end end diff --git a/library/general/src/lib/yast2/equatable.rb b/library/general/src/lib/yast2/equatable.rb index bd35412a4..76c25f07b 100644 --- a/library/general/src/lib/yast2/equatable.rb +++ b/library/general/src/lib/yast2/equatable.rb @@ -63,6 +63,8 @@ def self.included(base) module ClassMethods # Inherited classes must remember the attributes for comparison from its parent class def inherited(subclass) + super + subclass.eql_attr(*eql_attrs) end diff --git a/library/general/src/lib/yast2/popup.rb b/library/general/src/lib/yast2/popup.rb index ccd39adcc..75d78a144 100644 --- a/library/general/src/lib/yast2/popup.rb +++ b/library/general/src/lib/yast2/popup.rb @@ -103,7 +103,7 @@ def check_arguments!(message, details, timeout, focus, buttons) if !buttons.key?(focus) raise ArgumentError, "Invalid value #{focus.inspect} for parameter focus. " \ - "Known buttons: #{buttons.keys}." + "Known buttons: #{buttons.keys}." end nil diff --git a/library/general/src/modules/Arch.rb b/library/general/src/modules/Arch.rb index b9ad7456e..a52aab4f7 100644 --- a/library/general/src/modules/Arch.rb +++ b/library/general/src/modules/Arch.rb @@ -29,6 +29,10 @@ require "yast" module Yast + # Representing architecture information yast have. + # + # rubocop:disable Naming/VariableNumber + # Reason for disable is that API is stable and some method names follows domain conventions class ArchClass < Module def main # local variables @@ -566,6 +570,7 @@ def rpm_arch publish function: :x11_setup_needed, type: "boolean ()" publish function: :is_wsl, type: "boolean ()" end + # rubocop:enable Naming/VariableNumber Arch = ArchClass.new Arch.main diff --git a/library/general/src/modules/Distro.rb b/library/general/src/modules/Distro.rb index 4f2368d16..6483b19a5 100644 --- a/library/general/src/modules/Distro.rb +++ b/library/general/src/modules/Distro.rb @@ -38,11 +38,9 @@ def main # Is it SUSE based? openSUSE, SLES, SLED, ... def suse - if @_distro.nil? - if SCR.Read(path(".target.size"), "/etc/SuSE-release") != -1 - @_distro = "suse" - Builtins.y2milestone("Found SUSE") - end + if @_distro.nil? && (SCR.Read(path(".target.size"), "/etc/SuSE-release") != -1) + @_distro = "suse" + Builtins.y2milestone("Found SUSE") end @_distro == "suse" @@ -50,11 +48,9 @@ def suse # Is it Fedora based? RHEL, Oracle, ... def fedora - if @_distro.nil? - if SCR.Read(path(".target.size"), "/etc/fedora-release") != -1 - @_distro = "fedora" - Builtins.y2milestone("Found Fedora") - end + if @_distro.nil? && (SCR.Read(path(".target.size"), "/etc/fedora-release") != -1) + @_distro = "fedora" + Builtins.y2milestone("Found Fedora") end @_distro == "fedora" @@ -62,14 +58,12 @@ def fedora # Is it Debian based? Ubuntu, ... def debian - if @_distro.nil? - if SCR.Execute( - path(".target.bash"), - "/usr/bin/grep DISTRIB_ID=Ubuntu /etc/lsb-release" - ) == 0 - @_distro = "debian" - Builtins.y2milestone("Found Debian/Ubuntu") - end + if @_distro.nil? && (SCR.Execute( + path(".target.bash"), + "/usr/bin/grep DISTRIB_ID=Ubuntu /etc/lsb-release" + ) == 0) + @_distro = "debian" + Builtins.y2milestone("Found Debian/Ubuntu") end @_distro == "debian" diff --git a/library/general/src/modules/DontShowAgain.rb b/library/general/src/modules/DontShowAgain.rb index 8f811528e..48f370f25 100644 --- a/library/general/src/modules/DontShowAgain.rb +++ b/library/general/src/modules/DontShowAgain.rb @@ -167,7 +167,7 @@ def GetShowQuestionAgain(params) return nil end - return Ops.get_boolean( + Ops.get_boolean( @current_configuration, [q_type, q_ident, q_url, "show_again"] ) @@ -176,7 +176,7 @@ def GetShowQuestionAgain(params) # Add another types here... else Builtins.y2error("'%1' is an unknown type", q_type) - return nil + nil end end @@ -262,7 +262,7 @@ def GetDefaultReturn(params) return nil end - return Ops.get( + Ops.get( @current_configuration, [q_type, q_ident, q_url, "return"] ) @@ -270,7 +270,7 @@ def GetDefaultReturn(params) # Add another types here... else Builtins.y2error("'%1' is an unknown type", q_type) - return nil + nil end # <--- repositories ---> end @@ -355,10 +355,10 @@ def RemoveShowQuestionAgain(params) SaveCurrentConfiguration() end - return Ops.get(@current_configuration, [q_type, q_ident, q_url]).nil? + Ops.get(@current_configuration, [q_type, q_ident, q_url]).nil? else Builtins.y2error("'%1' is an unknown type", q_type) - return false + false end end diff --git a/library/general/src/modules/FileUtils.rb b/library/general/src/modules/FileUtils.rb index 216a2daf7..e86f43caf 100644 --- a/library/general/src/modules/FileUtils.rb +++ b/library/general/src/modules/FileUtils.rb @@ -278,7 +278,7 @@ def CheckAndCreatePath(pathvalue) # Directory (path) is not a valid 'directory' Builtins.y2warning("Path %1 is not a directory", check_path) # Continue despite the error? - return Popup.ContinueCancel( + Popup.ContinueCancel( Builtins.sformat( # TRANSLATORS: popup question (with continue / cancel buttons) # %1 is the filesystem path @@ -305,12 +305,12 @@ def CheckAndCreatePath(pathvalue) "Directory %1 successfully created", check_path ) - return true + true # Failed to create the directory else Builtins.y2warning("Failed to create directory %1", check_path) # Continue despite the error? - return Popup.ContinueCancel( + Popup.ContinueCancel( Builtins.sformat( # TRANSLATORS: popup question (with continue / cancel buttons) # %1 is the name (path) of the directory @@ -327,7 +327,7 @@ def CheckAndCreatePath(pathvalue) "User doesn't want to create the directory %1", check_path ) - return true + true end end end diff --git a/library/general/src/modules/Hooks.rb b/library/general/src/modules/Hooks.rb index 91f5aab0f..46a48f15d 100644 --- a/library/general/src/modules/Hooks.rb +++ b/library/general/src/modules/Hooks.rb @@ -68,6 +68,8 @@ class HooksClass < Module private :hooks def initialize + super + textdomain "base" @hooks = {} @search_path = SearchPath.new @@ -191,7 +193,7 @@ def find_hook_files(hook_name) end unless hook_files.empty? log.info "Found #{hook_files.size} hook files: " \ - "#{hook_files.map { |f| f.basename.to_s }.join(", ")}" + "#{hook_files.map { |f| f.basename.to_s }.join(", ")}" end hook_files.sort end diff --git a/library/general/src/modules/Icon.rb b/library/general/src/modules/Icon.rb index 3d3d3a9b1..e17912def 100644 --- a/library/general/src/modules/Icon.rb +++ b/library/general/src/modules/Icon.rb @@ -110,10 +110,10 @@ def Image(icon_type, options) HSpacing(Ops.get_integer(options, "margin_right", 0)) ) - return deep_copy(ret) + deep_copy(ret) # no margin defined else - return deep_copy(this_image) + deep_copy(this_image) end end diff --git a/library/general/src/modules/Linuxrc.rb b/library/general/src/modules/Linuxrc.rb index b246aeb98..d977e3fa9 100644 --- a/library/general/src/modules/Linuxrc.rb +++ b/library/general/src/modules/Linuxrc.rb @@ -187,7 +187,12 @@ def SaveInstallInf(root) inst_if_file = "/etc/install.inf" if !root.nil? && root != "" && root != "/" - if WFM.Read(path(".local.size"), inst_if_file) != -1 + if WFM.Read(path(".local.size"), inst_if_file) == -1 + Builtins.y2error( + "Can't SaveInstallInf, file %1 doesn't exist", + inst_if_file + ) + else Builtins.y2milestone("Copying %1 to %2", inst_if_file, root) if Convert.to_integer( WFM.Execute( @@ -205,11 +210,6 @@ def SaveInstallInf(root) root ) end - else - Builtins.y2error( - "Can't SaveInstallInf, file %1 doesn't exist", - inst_if_file - ) end else Builtins.y2error("Can't SaveInstallInf, root is %1", root) diff --git a/library/general/src/modules/Message.rb b/library/general/src/modules/Message.rb index ba3291358..e5ece365b 100644 --- a/library/general/src/modules/Message.rb +++ b/library/general/src/modules/Message.rb @@ -93,8 +93,8 @@ def CannotWriteSettingsToBecause(destination, reason) Builtins.sformat( _( "Cannot write settings to '%1'.\n" \ - "\n" \ - "Reason: %2" + "\n" \ + "Reason: %2" ), destination, reason diff --git a/library/general/src/modules/Misc.rb b/library/general/src/modules/Misc.rb index 47c0949b0..1e934baff 100644 --- a/library/general/src/modules/Misc.rb +++ b/library/general/src/modules/Misc.rb @@ -177,10 +177,10 @@ def SysconfigRead(sysconfig_path, defaultv) "Failed reading '%1', using default value", sysconfig_path ) - return defaultv + defaultv else Builtins.y2milestone("%1: '%2'", sysconfig_path, local_ret) - return local_ret + local_ret end end diff --git a/library/general/src/modules/Mode.rb b/library/general/src/modules/Mode.rb index 4483d3b3a..32f48e962 100644 --- a/library/general/src/modules/Mode.rb +++ b/library/general/src/modules/Mode.rb @@ -110,14 +110,14 @@ def Initialize arg_no = 0 while Ops.less_than(arg_no, arg_count) # parsing for main mode - if WFM.Args(arg_no) == "initial" || WFM.Args(arg_no) == "continue" || - WFM.Args(arg_no) == "firstboot" + case WFM.Args(arg_no) + when "initial", "continue", "firstboot" @_mode = "installation" # parsing for test mode - elsif WFM.Args(arg_no) == "test" || WFM.Args(arg_no) == "demo" + when "test", "demo" @_test = "test" Builtins.y2warning("***** Test mode enabled *****") - elsif WFM.Args(arg_no) == "screenshots" + when "screenshots" @_test = "screenshot" Builtins.y2warning("***** Screen shot mode enabled *****") end diff --git a/library/general/src/modules/OSRelease.rb b/library/general/src/modules/OSRelease.rb index 74b603166..8b79cdc64 100644 --- a/library/general/src/modules/OSRelease.rb +++ b/library/general/src/modules/OSRelease.rb @@ -30,15 +30,14 @@ module Yast import "FileUtils" class OSReleaseFileMissingError < StandardError - def initialize(message) - super message - end end class OSReleaseClass < Module include Yast::Logger def initialize + super + textdomain "base" end @@ -114,7 +113,7 @@ def os_release_exists?(directory = "/") # @return [String] nice product name (to be displayed) def MakeNiceName(longname) # remove everything after first left parenthesis and spaces leading to it - longname.gsub(/[ ]*\(.*/, "") + longname.gsub(/ *\(.*/, "") end end diff --git a/library/general/src/modules/Popup.rb b/library/general/src/modules/Popup.rb index 654f0fa9b..6fbcec5c8 100644 --- a/library/general/src/modules/Popup.rb +++ b/library/general/src/modules/Popup.rb @@ -677,7 +677,8 @@ def ConfirmAbort(severity) # Button that will continue with the installation continue_button = _("&Continue Installation") - if severity == :painless + case severity + when :painless if Mode.repair # Confirm user request to abort System Repair abort_label = _("Really abort YaST System Repair?") @@ -689,27 +690,27 @@ def ConfirmAbort(severity) # Warning text for aborting an installation before anything is installed what_will_happen = _( "If you abort the installation now,\n" \ - "Linux will not be installed.\n" \ - "Your hard disk will remain untouched." + "Linux will not be installed.\n" \ + "Your hard disk will remain untouched." ) end - elsif severity == :incomplete + when :incomplete # Warning text for aborting an installation during the install process # - After some installation steps have been performed - e.g. # disks formatted / some packages already installed what_will_happen = _( "If you abort the installation now, you will\n" \ - "have an incomplete Linux system\n" \ - "that might or might not be usable.\n" \ - "You might need to reinstall.\n" + "have an incomplete Linux system\n" \ + "that might or might not be usable.\n" \ + "You might need to reinstall.\n" ) - elsif severity == :unusable + when :unusable # Warning text for aborting an installation during the install process # right in the middle of some critical process (e.g. formatting) what_will_happen = _( "If you abort the installation now,\n" \ - "Linux will be unusable.\n" \ - "You will need to reinstall." + "Linux will be unusable.\n" \ + "You will need to reinstall." ) else Builtins.y2error("Unknown symbol for ConfirmAbort") @@ -1593,7 +1594,8 @@ def AnyQuestion3(headline, message, yes_button_message, no_button_message, retry no_button = Empty() retry_button = Empty() - if focus == :focus_no + case focus + when :focus_no yes_button = PushButton( Id(:yes), Opt(:key_F10, :okButton), @@ -1609,7 +1611,7 @@ def AnyQuestion3(headline, message, yes_button_message, no_button_message, retry Opt(:key_F6, :customButton), retry_button_message ) - elsif focus == :focus_yes + when :focus_yes yes_button = PushButton( Id(:yes), Opt(:default, :key_F10, :okButton), diff --git a/library/general/src/modules/Report.rb b/library/general/src/modules/Report.rb index 467751a65..1ab9b2ac1 100644 --- a/library/general/src/modules/Report.rb +++ b/library/general/src/modules/Report.rb @@ -192,7 +192,7 @@ def Summary @log_errors ? _("Yes") : _("No") ) ) - summary = Summary.CloseList(summary) + Summary.CloseList(summary) # summary = Summary::AddHeader(summary, _("Yes or No Messages (Critical Messages)")); # summary = Summary::OpenList(summary); # // Report configuration - will be error messages displayed? @@ -207,7 +207,6 @@ def Summary # summary = Summary::AddListItem(summary, sformat(_("Log Yes or No Messages: %1"), (log_yesno_messages) ? # _("Yes") : _("No"))); # summary = Summary::CloseList(summary); - summary end # Get all the Report configuration from a map. diff --git a/library/general/src/modules/Stage.rb b/library/general/src/modules/Stage.rb index bd56ea77e..15d800f94 100644 --- a/library/general/src/modules/Stage.rb +++ b/library/general/src/modules/Stage.rb @@ -49,13 +49,14 @@ def stage arg_count = Builtins.size(WFM.Args) arg_no = 0 while Ops.less_than(arg_no, arg_count) - if WFM.Args(arg_no) == "initial" + case WFM.Args(arg_no) + when "initial" @_stage = "initial" - elsif WFM.Args(arg_no) == "continue" + when "continue" @_stage = "continue" - elsif WFM.Args(arg_no) == "firstboot" + when "firstboot" @_stage = "firstboot" - elsif WFM.Args(arg_no) == "reprobe" + when "reprobe" @_stage = "hardware_probed" end diff --git a/library/general/src/modules/Summary.rb b/library/general/src/modules/Summary.rb index fce0cafc7..fd96fc823 100644 --- a/library/general/src/modules/Summary.rb +++ b/library/general/src/modules/Summary.rb @@ -75,11 +75,11 @@ def DevicesList(devices) devices = deep_copy(devices) text = "" if Builtins.size(devices) == 0 - text = if !Mode.config + text = if Mode.config + Builtins.sformat("
  • %1
", NotConfigured()) + else # translators: summary if no hardware was detected Builtins.sformat("
  • %1
", _("Not detected.")) - else - Builtins.sformat("
  • %1
", NotConfigured()) end else Builtins.foreach(devices) { |dev| text = Ops.add(text, dev) } @@ -161,9 +161,7 @@ def AddSimpleSection(summary, header, item) summary = AddHeader(summary, header) summary = OpenList(summary) summary = AddListItem(summary, item) - summary = CloseList(summary) - - summary + CloseList(summary) end publish function: :NotConfigured, type: "string ()" diff --git a/library/general/src/modules/ValueBrowser.rb b/library/general/src/modules/ValueBrowser.rb index 75695066b..1c09307f9 100644 --- a/library/general/src/modules/ValueBrowser.rb +++ b/library/general/src/modules/ValueBrowser.rb @@ -65,7 +65,7 @@ def FormatSimpleType(variable, indent) elsif Ops.is_float?(variable) Builtins.sformat("%2%1 (float)", variable, indent) elsif Ops.is_string?(variable) - return Builtins.sformat( + Builtins.sformat( "%2%1 (string)", escapestring(Convert.to_string(variable)), indent diff --git a/library/general/test/asciifile_test.rb b/library/general/test/asciifile_test.rb index 9fd67f6bc..c4bfe2f31 100755 --- a/library/general/test/asciifile_test.rb +++ b/library/general/test/asciifile_test.rb @@ -38,7 +38,7 @@ def stub_file_reading(filename, contents) Yast::AsciiFile.ReadFile(fstab_ref, FSTAB_FILENAME) end - # note that the result is `fstab["l"]` + # NOTE: that the result is `fstab["l"]` # as the rest of `fstab` are the parsing parameters it "produces the result under the 'l' key" do expect(fstab_ref.value).to have_key "l" diff --git a/library/general/test/autoinst_issues/invalid_value_test.rb b/library/general/test/autoinst_issues/invalid_value_test.rb index 00b5fe27b..e18bbead6 100755 --- a/library/general/test/autoinst_issues/invalid_value_test.rb +++ b/library/general/test/autoinst_issues/invalid_value_test.rb @@ -18,7 +18,7 @@ # To contact SUSE LLC about this file by physical or electronic mail, you may # find current contact information at www.suse.com. -require_relative "../test_helper.rb" +require_relative "../test_helper" require "installation/autoinst_issues/invalid_value" describe Installation::AutoinstIssues::InvalidValue do diff --git a/library/general/test/autoinst_issues/issues_presenter_test.rb b/library/general/test/autoinst_issues/issues_presenter_test.rb index ddb30926a..fa0e55376 100755 --- a/library/general/test/autoinst_issues/issues_presenter_test.rb +++ b/library/general/test/autoinst_issues/issues_presenter_test.rb @@ -27,10 +27,6 @@ module Test module AutoinstIssues class MissingSection < ::Installation::AutoinstIssues::Issue - def initialize(*args) - super - end - def severity :fatal end @@ -41,10 +37,11 @@ def message end class InvalidValue < ::Installation::AutoinstIssues::Issue - attr_reader :attr - attr_reader :value + attr_reader :attr, :value def initialize(section, attr, value) + super() + @section = section @attr = attr @value = value diff --git a/library/general/test/autoinst_issues/list_test.rb b/library/general/test/autoinst_issues/list_test.rb index a542791b1..8ec3a29da 100755 --- a/library/general/test/autoinst_issues/list_test.rb +++ b/library/general/test/autoinst_issues/list_test.rb @@ -31,6 +31,8 @@ class Exception < ::Installation::AutoinstIssues::Issue # @param error [StandardError] def initialize(error) + super() + @error = error end diff --git a/library/general/test/autoinst_issues/missing_value_test.rb b/library/general/test/autoinst_issues/missing_value_test.rb index d04467470..aa95a6ab4 100755 --- a/library/general/test/autoinst_issues/missing_value_test.rb +++ b/library/general/test/autoinst_issues/missing_value_test.rb @@ -18,7 +18,7 @@ # To contact SUSE LLC about this file by physical or electronic mail, you may # find current contact information at www.suse.com. -require_relative "../test_helper.rb" +require_relative "../test_helper" require "installation/autoinst_issues/missing_value" describe Installation::AutoinstIssues::MissingValue do diff --git a/library/general/test/directory_test.rb b/library/general/test/directory_test.rb index 0f3515e12..673d6d326 100755 --- a/library/general/test/directory_test.rb +++ b/library/general/test/directory_test.rb @@ -20,7 +20,7 @@ let(:file) { "data_file.txt" } it "returns the full path" do - expect(IO.read(file_path)).to eq "Data file content" + expect(File.read(file_path)).to eq "Data file content" end end end diff --git a/library/general/test/installation/autoinst_profile/section_with_attributes_test.rb b/library/general/test/installation/autoinst_profile/section_with_attributes_test.rb index 14c078df1..53566b0f0 100644 --- a/library/general/test/installation/autoinst_profile/section_with_attributes_test.rb +++ b/library/general/test/installation/autoinst_profile/section_with_attributes_test.rb @@ -57,6 +57,8 @@ def new_from_hashes(hash = {}) define_attr_accessors def initialize + super + @children = [] @group = nil end diff --git a/library/general/test/linuxrc_test.rb b/library/general/test/linuxrc_test.rb index 9af9e0f11..a4fc7cad7 100755 --- a/library/general/test/linuxrc_test.rb +++ b/library/general/test/linuxrc_test.rb @@ -66,7 +66,7 @@ def load_install_inf(defaults_replacement = {}) .with(path(".etc.install_inf")) .and_return install_inf.keys - install_inf.keys.each do |key| + install_inf.each_key do |key| allow(Yast::SCR).to receive(:Read) .with(path(".etc.install_inf.#{key}")) .and_return install_inf[key] diff --git a/library/general/test/popup_test.rb b/library/general/test/popup_test.rb index 685c0a813..506d66d64 100755 --- a/library/general/test/popup_test.rb +++ b/library/general/test/popup_test.rb @@ -25,8 +25,7 @@ it "opens a popup dialog and closes it at the end" do expect(ui).to receive(:OpenDialog).ordered expect(ui).to receive(:CloseDialog).ordered - # just pass an empty block - subject.Feedback("Label", "Message") {} + subject.Feedback("Label", "Message") {} # just pass an empty block end it "closes the popup even when an exception occurs in the block" do @@ -58,14 +57,14 @@ expect(ui).to receive(:OpenDialog).ordered expect(ui).to receive(:CloseDialog).ordered subject.Feedback("test", "test") do - subject.SuppressFeedback {} + subject.SuppressFeedback {} # just empty testing block end end it "just call block if no feedback is given" do expect(ui).to_not receive(:OpenDialog) expect(ui).to_not receive(:CloseDialog) - subject.SuppressFeedback {} + subject.SuppressFeedback {} # empty block passed end context "when block is missing" do diff --git a/library/general/test/test_helper.rb b/library/general/test/test_helper.rb index 9da563759..17c3bef0c 100644 --- a/library/general/test/test_helper.rb +++ b/library/general/test/test_helper.rb @@ -1,3 +1,3 @@ -require_relative "../../../test/test_helper.rb" +require_relative "../../../test/test_helper" GENERAL_DATA_PATH = File.join(__dir__, "data") diff --git a/library/general/test/ui/greasemonkey_test.rb b/library/general/test/ui/greasemonkey_test.rb index 61af598dc..3a816e868 100755 --- a/library/general/test/ui/greasemonkey_test.rb +++ b/library/general/test/ui/greasemonkey_test.rb @@ -72,7 +72,7 @@ let(:old) { term(:LeftRadioButtonWithAttachment, "foo", "bar", "contents") } let(:new) do VBox( - # NOTE that it does not expand this Greasemonkey term! + # NOTE: that it does not expand this Greasemonkey term! term(:LeftRadioButton, "foo", "bar"), HBox(HSpacing(4), "contents") ) @@ -96,7 +96,7 @@ let(:old) { term(:LeftCheckBoxWithAttachment, "foo", "bar", "contents") } let(:new) do VBox( - # NOTE that it does not expand this Greasemonkey term! + # NOTE: that it does not expand this Greasemonkey term! term(:LeftCheckBox, "foo", "bar"), HBox(HSpacing(4), "contents") ) diff --git a/library/general/test/ui/installation/layout_test.rb b/library/general/test/ui/installation/layout_test.rb index 03b076774..f7d49b39e 100755 --- a/library/general/test/ui/installation/layout_test.rb +++ b/library/general/test/ui/installation/layout_test.rb @@ -227,7 +227,7 @@ it "closes the wizard" do expect(Yast::Wizard).to receive(:CloseDialog) - subject.open_wizard {} + subject.open_wizard {} # block is not needed end end end diff --git a/library/general/test/ui/text_helpers_test.rb b/library/general/test/ui/text_helpers_test.rb index 69bc1bf94..9d36a3e0e 100755 --- a/library/general/test/ui/text_helpers_test.rb +++ b/library/general/test/ui/text_helpers_test.rb @@ -43,7 +43,7 @@ class TestTextHelpers it "does not break words" do wrapped_text = subject.wrap_text(text) - expect(wrapped_text).to match(/it\'s/) + expect(wrapped_text).to match(/it's/) expect(wrapped_text).to match(/not_real_but_really_long_word/) end @@ -241,10 +241,10 @@ class TestTextHelpers let(:text) do "

YaST is both" \ "

    " \ - "
  1. an extremely flexible installer
  2. " \ - "
  3. a powerful control center
  4. " \ + "
  5. an extremely flexible installer
  6. " \ + "
  7. a powerful control center
  8. " \ "
" \ - "

" + "

" end let(:result) do diff --git a/library/general/test/ui/ui_extension_checker_test.rb b/library/general/test/ui/ui_extension_checker_test.rb index 7f2ec29e4..c63db8a19 100755 --- a/library/general/test/ui/ui_extension_checker_test.rb +++ b/library/general/test/ui/ui_extension_checker_test.rb @@ -1,7 +1,7 @@ #! /usr/bin/env rspec require_relative "../test_helper" -require "ui/ui_extension_checker.rb" +require "ui/ui_extension_checker" describe Yast::UIExtensionChecker do describe "#new" do diff --git a/library/general/test/yast2/secret_attributes_test.rb b/library/general/test/yast2/secret_attributes_test.rb index c7a229bce..2c06f0eda 100755 --- a/library/general/test/yast2/secret_attributes_test.rb +++ b/library/general/test/yast2/secret_attributes_test.rb @@ -28,6 +28,7 @@ class ClassWithPassword include Yast2::SecretAttributes attr_accessor :name + secret_attr :password end @@ -36,6 +37,7 @@ class ClassWithData include Yast2::SecretAttributes attr_accessor :name + secret_attr :data end diff --git a/library/gpg/src/modules/GPG.rb b/library/gpg/src/modules/GPG.rb index 76735e171..4a1743f81 100644 --- a/library/gpg/src/modules/GPG.rb +++ b/library/gpg/src/modules/GPG.rb @@ -147,7 +147,7 @@ def parse_key(lines) # @param [String] input gpg output # @return [Array] parsed keys def parseKeys(input) - # note: see /usr/share/doc/packages/gpg/DETAILS for another way + # NOTE: see /usr/share/doc/packages/gpg/DETAILS for another way ret = [] lines = Builtins.splitstring(input, "\n") @@ -219,7 +219,12 @@ def CreateKey ret = false - if !text_mode + if text_mode + command = Ops.add("LC_ALL=en_US.UTF-8 ", command) + Builtins.y2internal("Executing in terminal: %1", command) + # in ncurses use UI::RunInTerminal + ret = UI.RunInTerminal(command) == 0 + else if Ops.less_than(SCR.Read(path(".target.size"), XTERM_PATH), 0) # FIXME: do it Report.Error(_("Xterm is missing, install xterm package.")) @@ -233,7 +238,7 @@ def CreateKey SCR.Execute(path(".target.bash"), "/usr/bin/rm -f #{exit_file.shellescape}") if FileUtils.Exists(exit_file) command = "LC_ALL=en_US.UTF-8 #{XTERM_PATH} -e " \ - "\"#{command}; echo $? > #{exit_file.shellescape}\"" + "\"#{command}; echo $? > #{exit_file.shellescape}\"" Builtins.y2internal("Executing: %1", command) @@ -257,11 +262,6 @@ def CreateKey Builtins.y2warning("Exit file is missing, the gpg command has failed") ret = false end - else - command = Ops.add("LC_ALL=en_US.UTF-8 ", command) - Builtins.y2internal("Executing in terminal: %1", command) - # in ncurses use UI::RunInTerminal - ret = UI.RunInTerminal(command) == 0 end if ret @@ -428,7 +428,7 @@ def encrypted_symmetric?(file) # @raise [GPGFailed] when encryption failed def encrypt_symmetric(input_file, output_file, password) out = callGPG("--armor --batch --symmetric --passphrase '#{String.Quote(password)}' " \ - "--output '#{String.Quote(output_file)}' '#{String.Quote(input_file)}'") + "--output '#{String.Quote(output_file)}' '#{String.Quote(input_file)}'") raise GPGFailed, out["stderr"] if out["exit"] != 0 end diff --git a/library/gpg/src/modules/GPGWidgets.rb b/library/gpg/src/modules/GPGWidgets.rb index 4c9122388..d035e3824 100644 --- a/library/gpg/src/modules/GPGWidgets.rb +++ b/library/gpg/src/modules/GPGWidgets.rb @@ -282,9 +282,9 @@ def CreateNewKey "handle" => fun_ref(method(:GpgNewKey), "symbol (string, map)"), "help" => _( "

Create a new GPG key
\n" \ - "gpg --gen-key is started, see the gpg manual page for more information.\n" \ - "Press Ctrl+C to cancel.\n" \ - "

" + "gpg --gen-key is started, see the gpg manual page for more information.\n" \ + "Press Ctrl+C to cancel.\n" \ + "

" ) } end diff --git a/library/gpg/test/test_helper.rb b/library/gpg/test/test_helper.rb index 08dc933d5..6affe9fe9 100644 --- a/library/gpg/test/test_helper.rb +++ b/library/gpg/test/test_helper.rb @@ -1 +1 @@ -require_relative "../../../test/test_helper.rb" +require_relative "../../../test/test_helper" diff --git a/library/log/examples/logviewcore1.rb b/library/log/examples/logviewcore1.rb index eb8913051..0315d860b 100644 --- a/library/log/examples/logviewcore1.rb +++ b/library/log/examples/logviewcore1.rb @@ -40,9 +40,10 @@ def main loop do @widget = UI.TimeoutUserInput(250) - if @widget == :timeout + case @widget + when :timeout LogViewCore.Update(Id(:log)) - elsif @widget == :close + when :close break end end diff --git a/library/log/examples/logviewcore2.rb b/library/log/examples/logviewcore2.rb index 3c454a04e..d13879c7b 100644 --- a/library/log/examples/logviewcore2.rb +++ b/library/log/examples/logviewcore2.rb @@ -46,9 +46,10 @@ def main loop do @widget = UI.TimeoutUserInput(250) - if @widget == :timeout + case @widget + when :timeout LogViewCore.Update(Id(:log)) - elsif @widget == :close + when :close break end end diff --git a/library/log/examples/logviewcore3.rb b/library/log/examples/logviewcore3.rb index 158ffb053..449fd0147 100644 --- a/library/log/examples/logviewcore3.rb +++ b/library/log/examples/logviewcore3.rb @@ -45,9 +45,10 @@ def main loop do @widget = UI.TimeoutUserInput(250) - if @widget == :timeout + case @widget + when :timeout LogViewCore.Update(Id(:log)) - elsif @widget == :close + when :close break end end diff --git a/library/log/src/modules/LogView.rb b/library/log/src/modules/LogView.rb index b7b451e8d..0dd376628 100644 --- a/library/log/src/modules/LogView.rb +++ b/library/log/src/modules/LogView.rb @@ -106,8 +106,8 @@ def LogSelectionHelp # help for the log widget, part 1, alt. 1 _( "

Displayed Log
\n" \ - "Use Log to select the log to display. It will be displayed in\n" \ - "the field below.

\n" + "Use Log to select the log to display. It will be displayed in\n" \ + "the field below.

\n" ) end @@ -127,8 +127,8 @@ def AdvancedSaveHelp(label) Builtins.sformat( _( "

\n" \ - "To process advanced actions or save the log into a file, click %1\n" \ - "and select the action to process.

" + "To process advanced actions or save the log into a file, click %1\n" \ + "and select the action to process.

" ), label ) @@ -142,8 +142,8 @@ def AdvancedHelp(label) Builtins.sformat( _( "

\n" \ - "To process advanced actions, click %1\n" \ - "and select the action to process.

" + "To process advanced actions, click %1\n" \ + "and select the action to process.

" ), label ) @@ -155,8 +155,8 @@ def SaveHelp # help for the log widget, part 2, alt. 3 _( "

\n" \ - "To save the log into a file, click Save Log and select the file\n" \ - "to which to save the log.

\n" + "To save the log into a file, click Save Log and select the file\n" \ + "to which to save the log.

\n" ) end diff --git a/library/network/src/lib/network/firewalld.rb b/library/network/src/lib/network/firewalld.rb index 561e2eb4c..37c5e3ee0 100644 --- a/library/network/src/lib/network/firewalld.rb +++ b/library/network/src/lib/network/firewalld.rb @@ -66,7 +66,7 @@ def fwd_output(output = true) cmd_result["stdout"] else log.debug "#{command} returned: #{cmd_result["stdout"]}" - cmd_result["exit"].zero? ? true : false + cmd_result["exit"].zero? end else raise FirewallCMDError, "Calling firewall-cmd (cmd: #{command}) failed: #{cmd_result["stderr"]}" @@ -96,13 +96,13 @@ class FirewalldBashAPI # Simple wrapper for commands. Returns true on success def fwd_quiet_result(*args) - fwcmd = FWCmd.new(args.join("")) + fwcmd = FWCmd.new(args.join) fwcmd.fwd_output(false) end # Simple wrapper for commands. Returns command output def fwd_result(*args) - fwcmd = FWCmd.new(args.join("")) + fwcmd = FWCmd.new(args.join) fwcmd.fwd_output(true) end @@ -134,37 +134,37 @@ def make_permanent # @return [Array] List of firewall zones def zones - fwd_result("--permanent --get-zones").split(" ") + fwd_result("--permanent --get-zones").split end # @param zone [String] The firewall zone # @return [Array] list of zone's interfaces def list_interfaces(zone) - fwd_result("--permanent --zone=#{zone.shellescape} --list-interfaces").split(" ") + fwd_result("--permanent --zone=#{zone.shellescape} --list-interfaces").split end # @param zone [String] The firewall zone # @return [Arrray] list of zone's services def list_services(zone) - fwd_result("--permanent --zone=#{zone.shellescape} --list-services").split(" ") + fwd_result("--permanent --zone=#{zone.shellescape} --list-services").split end # @param zone [String] The firewall zone # @return [Array] list of zone's ports def list_ports(zone) - fwd_result("--permanent --zone=#{zone.shellescape} --list-ports").split(" ") + fwd_result("--permanent --zone=#{zone.shellescape} --list-ports").split end # @param zone [String] The firewall zone # @return [Array] list of zone's protocols def list_protocols(zone) - fwd_result("--permanent --zone=#{zone.shellescape} --list-protocols").split(" ") + fwd_result("--permanent --zone=#{zone.shellescape} --list-protocols").split end # @param zone [String] The firewall zone # @return [Array] list of all information for given zone def list_all(zone) - fwd_result("--permanent --zone=#{zone.shellescape} --list-all").split(" ") + fwd_result("--permanent --zone=#{zone.shellescape} --list-all").split end # @return [Array] list of all information for all firewall zones @@ -199,7 +199,7 @@ def remove_interface(zone, interface) # @return [Array] List of firewall services def services - fwd_result("--permanent --get-services").split(" ") + fwd_result("--permanent --get-services").split end # @param service [String] The firewall service @@ -336,7 +336,7 @@ def remove_masquerade(zone) # all, unicast, broadcast, multicast and off # @return [Boolean] True if desired packet type is being logged when denied def log_denied_packets?(kind) - (fwd_result("--get-log-denied").strip == kind) ? true : false + (fwd_result("--get-log-denied").strip == kind) end # @param kind [String] Denied packets to log. Possible values are: diff --git a/library/network/src/lib/network/susefirewall.rb b/library/network/src/lib/network/susefirewall.rb index db7869387..f5f65e2d7 100644 --- a/library/network/src/lib/network/susefirewall.rb +++ b/library/network/src/lib/network/susefirewall.rb @@ -43,6 +43,8 @@ class SuSEFirewallClass < Module include Yast::Logger def initialize + super + textdomain "base" end @@ -64,16 +66,16 @@ def SetStartService(start_service) return nil end - if GetStartService() != start_service - SetModified() - - Builtins.y2milestone("Setting start-firewall to %1", start_service) - else + if GetStartService() == start_service # without set modified! Builtins.y2milestone( "start-firewall has been already set to %1", start_service ) + else + SetModified() + + Builtins.y2milestone("Setting start-firewall to %1", start_service) end Ops.set(@SETTINGS, "start_firewall", start_service) @@ -101,16 +103,16 @@ def SetEnableService(enable_service) return nil end - if GetEnableService() != enable_service - SetModified() - - Builtins.y2milestone("Setting enable-firewall to %1", enable_service) - else + if GetEnableService() == enable_service # without set modified Builtins.y2milestone( "enable-firewall has been already set to %1", enable_service ) + else + SetModified() + + Builtins.y2milestone("Setting enable-firewall to %1", enable_service) end Ops.set(@SETTINGS, "enable_firewall", enable_service) @@ -128,10 +130,10 @@ def StartServices if Service.Start(@firewall_service) Builtins.y2milestone("Started") - return true + true else Builtins.y2error("Cannot start service %1", @firewall_service) - return false + false end end @@ -145,10 +147,10 @@ def StopServices if Service.Stop(@firewall_service) Builtins.y2milestone("Stopped") - return true + true else Builtins.y2error("Could not stop service %1", @firewall_service) - return false + false end end @@ -191,10 +193,10 @@ def IsEnabled if Service.Enabled(@firewall_service) Builtins.y2milestone("Firewall service is enabled") - return true + true else Builtins.y2milestone("Firewall service is not enabled") - return false + false end end @@ -210,10 +212,10 @@ def IsStarted Builtins.y2milestone("Checking firewall status...") if Service.Status(@firewall_service) == 0 Builtins.y2milestone("Firewall service is started") - return true + true else Builtins.y2milestone("Firewall service is stopped") - return false + false end end @@ -966,14 +968,14 @@ def AddService(service, protocol, interface) # Adding service support into each mentioned zone Builtins.foreach(zones_affected) do |zone| # If there isn't already - if !ArePortsOrServicesAllowed([service], protocol, zone, true) - AddAllowedPortsOrServices([service], protocol, zone) - else + if ArePortsOrServicesAllowed([service], protocol, zone, true) Builtins.y2milestone( "Port %1 has been already allowed in %2", service, zone ) + else + AddAllowedPortsOrServices([service], protocol, zone) end end diff --git a/library/network/src/lib/network/susefirewall2.rb b/library/network/src/lib/network/susefirewall2.rb index 253c529ab..4691ab6d8 100644 --- a/library/network/src/lib/network/susefirewall2.rb +++ b/library/network/src/lib/network/susefirewall2.rb @@ -517,10 +517,11 @@ def GetBroadcastAllowedPorts Builtins.foreach(GetKnownFirewallZones()) do |zone| broadcast = GetBroadcastConfiguration(zone) # no broadcast allowed for this zone - if broadcast == "no" + case broadcast + when "no" Ops.set(allowed_ports, zone, []) # BNC #694782: "yes" is automatically translated by SuSEfirewall2 - elsif broadcast == "yes" + when "yes" Ops.set(allowed_ports, zone, ["yes"]) # only listed ports allow broadcast else @@ -799,15 +800,16 @@ def RemoveServiceSupportFromZone(service, zone) needed_ports = Ops.get(needed, key, []) next if needed_ports == [] - if key == "tcp_ports" + case key + when "tcp_ports" RemoveAllowedPortsOrServices(needed_ports, "TCP", zone, true) - elsif key == "udp_ports" + when "udp_ports" RemoveAllowedPortsOrServices(needed_ports, "UDP", zone, true) - elsif key == "rpc_ports" + when "rpc_ports" RemoveAllowedPortsOrServices(needed_ports, "RPC", zone, false) - elsif key == "ip_protocols" + when "ip_protocols" RemoveAllowedPortsOrServices(needed_ports, "IP", zone, false) - elsif "broadcast_ports" == key + when "broadcast_ports" RemoveAllowedBroadcast(needed_ports, zone) else Builtins.y2error("Unknown key '%1'", key) @@ -848,15 +850,16 @@ def AddServiceSupportIntoZone(service, zone) needed_ports = Ops.get(needed, key, []) next if needed_ports == [] - if key == "tcp_ports" + case key + when "tcp_ports" AddAllowedPortsOrServices(needed_ports, "TCP", zone) - elsif key == "udp_ports" + when "udp_ports" AddAllowedPortsOrServices(needed_ports, "UDP", zone) - elsif key == "rpc_ports" + when "rpc_ports" AddAllowedPortsOrServices(needed_ports, "RPC", zone) - elsif key == "ip_protocols" + when "ip_protocols" AddAllowedPortsOrServices(needed_ports, "IP", zone) - elsif "broadcast_ports" == key + when "broadcast_ports" AddAllowedBroadcast(needed_ports, zone) else Builtins.y2error("Unknown key '%1'", key) @@ -1042,10 +1045,10 @@ def GetZoneOfInterface(interface) Builtins.sformat( _( "Interface '%1' is included in multiple firewall zones.\n" \ - "Continuing with configuration can produce errors.\n" \ - "\n" \ - "It is recommended to leave the configuration and repair it manually in\n" \ - "the file '/etc/sysconfig/SuSEFirewall'." + "Continuing with configuration can produce errors.\n" \ + "\n" \ + "It is recommended to leave the configuration and repair it manually in\n" \ + "the file '/etc/sysconfig/SuSEFirewall'." ), interface ) @@ -1360,35 +1363,36 @@ def IsServiceSupportedInZone(service, zone) needed_ports = Ops.get(needed, key, []) next if needed_ports == [] - if key == "tcp_ports" + case key + when "tcp_ports" service_is_supported = ArePortsOrServicesAllowed( needed_ports, "TCP", zone, true ) - elsif key == "udp_ports" + when "udp_ports" service_is_supported = ArePortsOrServicesAllowed( needed_ports, "UDP", zone, true ) - elsif key == "rpc_ports" + when "rpc_ports" service_is_supported = ArePortsOrServicesAllowed( needed_ports, "RPC", zone, false ) - elsif key == "ip_protocols" + when "ip_protocols" service_is_supported = ArePortsOrServicesAllowed( needed_ports, "IP", zone, false ) - elsif "broadcast_ports" == key + when "broadcast_ports" # testing for allowed broadcast ports service_is_supported = IsBroadcastAllowed(needed_ports, zone) else @@ -1632,7 +1636,7 @@ def ActivateConfiguration # Not started - start it if !IsStarted() Builtins.y2milestone("Starting firewall services") - return StartServices() + StartServices() # Started - restart it # modified - restart it, or ... # bugzilla #186186 @@ -1643,23 +1647,23 @@ def ActivateConfiguration Builtins.y2milestone("Stopping firewall services") StopServices() Builtins.y2milestone("Starting firewall services") - return StartServices() + StartServices() # not modified - skip restart else Builtins.y2milestone( "Configuration hasn't modified, skipping restarting services" ) - return true + true end # Firewall should stop after Write() # started - stop elsif IsStarted() Builtins.y2milestone("Stopping firewall services") - return StopServices() + StopServices() # stopped - skip stopping else Builtins.y2milestone("Firewall has been stopped already") - return true + true end end @@ -1813,13 +1817,14 @@ def GetAdditionalServices(protocol, zone) if IsServiceSupportedInZone(service_id, zone) == true # all needed ports etc for service/protocol needed_all = [] - if protocol == "TCP" + case protocol + when "TCP" needed_all = SuSEFirewallServices.GetNeededTCPPorts(service_id) - elsif protocol == "UDP" + when "UDP" needed_all = SuSEFirewallServices.GetNeededUDPPorts(service_id) - elsif protocol == "RPC" + when "RPC" needed_all = SuSEFirewallServices.GetNeededRPCPorts(service_id) - elsif protocol == "IP" + when "IP" needed_all = SuSEFirewallServices.GetNeededIPProtocols(service_id) end Builtins.foreach(needed_all) do |remove_port| @@ -2152,7 +2157,8 @@ def AddForwardIntoMasqueradeRule(source_net, forward_to_ip, protocol, req_port, def GetLoggingSettings(rule) ret_val = nil - if rule == "ACCEPT" + case rule + when "ACCEPT" ret_val = if Ops.get_string(@SETTINGS, "FW_LOG_ACCEPT_ALL", "no") == "yes" "ALL" elsif Ops.get_string(@SETTINGS, "FW_LOG_ACCEPT_CRIT", "yes") == "yes" @@ -2160,7 +2166,7 @@ def GetLoggingSettings(rule) else "NONE" end - elsif rule == "DROP" + when "DROP" ret_val = if Ops.get_string(@SETTINGS, "FW_LOG_DROP_ALL", "no") == "yes" "ALL" elsif Ops.get_string(@SETTINGS, "FW_LOG_DROP_CRIT", "yes") == "yes" @@ -2186,22 +2192,25 @@ def GetLoggingSettings(rule) def SetLoggingSettings(rule, state) SetModified() - if rule == "ACCEPT" - if state == "ALL" + case rule + when "ACCEPT" + case state + when "ALL" Ops.set(@SETTINGS, "FW_LOG_ACCEPT_CRIT", "yes") Ops.set(@SETTINGS, "FW_LOG_ACCEPT_ALL", "yes") - elsif state == "CRIT" + when "CRIT" Ops.set(@SETTINGS, "FW_LOG_ACCEPT_CRIT", "yes") Ops.set(@SETTINGS, "FW_LOG_ACCEPT_ALL", "no") else Ops.set(@SETTINGS, "FW_LOG_ACCEPT_CRIT", "no") Ops.set(@SETTINGS, "FW_LOG_ACCEPT_ALL", "no") end - elsif rule == "DROP" - if state == "ALL" + when "DROP" + case state + when "ALL" Ops.set(@SETTINGS, "FW_LOG_DROP_CRIT", "yes") Ops.set(@SETTINGS, "FW_LOG_DROP_ALL", "yes") - elsif state == "CRIT" + when "CRIT" Ops.set(@SETTINGS, "FW_LOG_DROP_CRIT", "yes") Ops.set(@SETTINGS, "FW_LOG_DROP_ALL", "no") else diff --git a/library/network/src/lib/network/susefirewall2services.rb b/library/network/src/lib/network/susefirewall2services.rb index c62a10593..ad5275ad9 100644 --- a/library/network/src/lib/network/susefirewall2services.rb +++ b/library/network/src/lib/network/susefirewall2services.rb @@ -478,13 +478,13 @@ def SetNeededPortsAndProtocols(service, store_definition) # flush the cache to the disk if write_ok - if !SCR.Write(path(".firewall_service_definition"), nil) - log.error "Cannot write to disk!" - write_ok = false - else + if SCR.Write(path(".firewall_service_definition"), nil) # not only store to disk but also to the memory @services[service] = new_store_definition SetModified() + else + log.error "Cannot write to disk!" + write_ok = false end end diff --git a/library/network/src/lib/network/susefirewalld.rb b/library/network/src/lib/network/susefirewalld.rb index 23566b2b0..38b422db2 100644 --- a/library/network/src/lib/network/susefirewalld.rb +++ b/library/network/src/lib/network/susefirewalld.rb @@ -67,6 +67,8 @@ def api end def initialize + super + textdomain "base" # firewalld API interface. @@ -177,12 +179,12 @@ def Import(import_settings) Read() import_settings = deep_copy(import_settings || {}) # Sanitize it - import_settings.keys.each do |k| + import_settings.each_key do |k| if !GetKnownFirewallZones().include?(k) && !KEY_SETTINGS.include?(k) Builtins.y2warning("Removing invalid key: %1 from imported settings", k) import_settings.delete(k) elsif import_settings[k].is_a?(Hash) - import_settings[k].keys.each do |v| + import_settings[k].each_key do |v| if !ZONE_ATTRIBUTES.include?(v) Builtins.y2warning("Removing invalid value: %1 from key %2", v, k) import_settings[k].delete(v) @@ -192,25 +194,22 @@ def Import(import_settings) end # Ruby's merge will probably not work since we have nested hashes - @SETTINGS.keys.each do |key| - next unless import_settings.include?(key) - - if import_settings[key].class == Hash - # Merge them - @SETTINGS[key].merge!(import_settings[key]) - else - @SETTINGS[key] = import_settings[key] + @SETTINGS.each_key do |key| + if import_settings.include?(key) + if import_settings[key].instance_of?(Hash) + # Merge them + @SETTINGS[key].merge!(import_settings[key]) + else + @SETTINGS[key] = import_settings[key] + end + end + # Merge missing attributes + if GetKnownFirewallZones().include?(key) + # is this a zone? + @SETTINGS[key] = EMPTY_ZONE.merge(@SETTINGS[key]) + # Everything may have been modified + @SETTINGS[key][:modified] = [:interfaces, :masquerade, :ports, :protocols, :services] end - end - - # Merge missing attributes - @SETTINGS.keys.each do |key| - next unless GetKnownFirewallZones().include?(key) - - # is this a zone? - @SETTINGS[key] = EMPTY_ZONE.merge(@SETTINGS[key]) - # Everything may have been modified - @SETTINGS[key][:modified] = [:interfaces, :masquerade, :ports, :protocols, :services] end # Tests mock the read method so read the NetworkInterface list again @@ -268,7 +267,7 @@ def read_zones zone = nil all_zone_info.each do |e| # is it a zone? - z = e.split("\s")[0] + z = e.split[0] if GetKnownFirewallZones().include?(z) zone = z next @@ -279,10 +278,10 @@ def read_zones # do not bother if empty next if attrs[1].nil? - vals = attrs[1].split("\s") + vals = attrs[1].split # Fix up for masquerade if attr == :masquerade - set_to_zone_attr(zone, attr, ((vals == "no") ? false : true)) + set_to_zone_attr(zone, attr, vals != "no") else vals.each { |x| add_to_zone_attr(zone, attr, x) } end @@ -315,9 +314,7 @@ def WriteConfiguration # FIXME: Need to improve that to not re-write everything begin # Set logging - if !@SETTINGS["logging"].nil? - @fwd_api.log_denied_packets(@SETTINGS["logging"]) if !@fwd_api.log_denied_packets?(@SETTINGS["logging"]) - end + @fwd_api.log_denied_packets(@SETTINGS["logging"]) if !@SETTINGS["logging"].nil? && !@fwd_api.log_denied_packets?(@SETTINGS["logging"]) # Configure the zones GetKnownFirewallZones().each do |zone| if zone_attr_modified?(zone) @@ -380,25 +377,25 @@ def ActivateConfiguration if GetStartService() # Not started - start it - if !IsStarted() - Builtins.y2milestone("Starting firewall services") - return StartServices() - # Started - restart it - else + if IsStarted() Builtins.y2milestone("Firewall has been started already") # Make it real @fwd_api.reload - return true + true + else + Builtins.y2milestone("Starting firewall services") + StartServices() + # Started - restart it end # Firewall should stop after Write() # started - stop elsif IsStarted() Builtins.y2milestone("Stopping firewall services") - return StopServices() + StopServices() # stopped - skip stopping else Builtins.y2milestone("Firewall has been stopped already") - return true + true end end @@ -752,11 +749,11 @@ def GetLoggingSettings(rule) drop_rule = @SETTINGS["logging"] case drop_rule when "off" - return "NONE" + "NONE" when "broadcast", "multicast", "unicast" - return "CRIT" + "CRIT" when "all" - return "ALL" + "ALL" end else Builtins.y2error("Possible rules are only 'ACCEPT' or 'DROP'") @@ -847,9 +844,10 @@ def GetAllowedServicesForZoneProto(zone, protocol) result = get_zone_attr(zone, :protocols) if protocol == "ip" # We return the name of service instead of its ports get_zone_attr(zone, :services).each do |s| # to be SF2 compatible. - if protocol == "tcp" + case protocol + when "tcp" result << s if !SuSEFirewallServices.GetNeededTCPPorts(s).empty? - elsif protocol == "udp" + when "udp" result << s if !SuSEFirewallServices.GetNeededUDPPorts(s).empty? end end @@ -1178,12 +1176,13 @@ def sanitize_services_and_ports(allowed_services, protocol) Builtins.y2debug("Examining %1", s) # Is it a service? if SuSEFirewallServices.GetSupportedServices().keys.include?(s) - if protocol == "tcp" + case protocol + when "tcp" if !SuSEFirewallServices.GetNeededTCPPorts(s).empty? Builtins.y2debug("Adding service %1", s) services << s end - elsif protocol == "udp" + when "udp" if !SuSEFirewallServices.GetNeededUDPPorts(s).empty? Builtins.y2debug("Adding service %1", s) services << s diff --git a/library/network/src/lib/network/susefirewalldservices.rb b/library/network/src/lib/network/susefirewalldservices.rb index 34f81d7a4..704449d73 100644 --- a/library/network/src/lib/network/susefirewalldservices.rb +++ b/library/network/src/lib/network/susefirewalldservices.rb @@ -35,6 +35,8 @@ class SuSEFirewalldServicesClass < SuSEFirewallServicesClass IGNORED_SERVICES = ["..", "."].freeze def initialize + super + textdomain "base" @services = nil @@ -151,13 +153,13 @@ def populate_service(service_name) # This going to be too expensive (5 API calls per service) but this # is really the slowpath since we rarely need to extract so much # information from a service - SuSEFirewall.api.service_modules(service_name).split(" ").each do |x| + SuSEFirewall.api.service_modules(service_name).split.each do |x| @services[service_name]["modules"] << x end - SuSEFirewall.api.service_protocols(service_name).split(" ").each do |x| + SuSEFirewall.api.service_protocols(service_name).split.each do |x| @services[service_name]["protocols"] << x end - SuSEFirewall.api.service_ports(service_name).split(" ").each do |x| + SuSEFirewall.api.service_ports(service_name).split.each do |x| port_proto = x.split("/") @services[service_name]["tcp_ports"] << port_proto[0] if port_proto[1] == "tcp" @services[service_name]["udp_ports"] << port_proto[0] if port_proto[1] == "udp" diff --git a/library/network/src/lib/network/susefirewallservices.rb b/library/network/src/lib/network/susefirewallservices.rb index 6a1e3033c..88a9888b2 100644 --- a/library/network/src/lib/network/susefirewallservices.rb +++ b/library/network/src/lib/network/susefirewallservices.rb @@ -25,9 +25,6 @@ module Yast # Service not found exception class SuSEFirewalServiceNotFound < StandardError - def initialize(message) - super message - end end # Global Definition of Firewall Services @@ -49,6 +46,8 @@ class SuSEFirewallServicesClass < Module }.freeze def initialize + super + textdomain "base" end diff --git a/library/network/src/lib/y2firewall/firewalld/api/services.rb b/library/network/src/lib/y2firewall/firewalld/api/services.rb index 40745ff8e..c5239b41d 100644 --- a/library/network/src/lib/y2firewall/firewalld/api/services.rb +++ b/library/network/src/lib/y2firewall/firewalld/api/services.rb @@ -47,7 +47,7 @@ def delete_service(service) # # @return [Array] List of firewall services def services - string_command("--get-services").split(" ") + string_command("--get-services").split end # Show all the service declaration (name, description, ports, @@ -114,7 +114,7 @@ def service_supported?(service) # reads the permanent configuration # @return [Array] The firewall service ports def service_ports(service, permanent: permanent?) - string_command("--service=#{service}", "--get-ports", permanent: permanent).split(" ") + string_command("--service=#{service}", "--get-ports", permanent: permanent).split end # @param service [String] The firewall service @@ -122,7 +122,7 @@ def service_ports(service, permanent: permanent?) # reads the permanent configuration # @return [Array] The firewall service protocols def service_protocols(service, permanent: permanent?) - string_command("--service=#{service}", "--get-protocols", permanent: permanent).split(" ") + string_command("--service=#{service}", "--get-protocols", permanent: permanent).split end # @param service [String] The firewall service @@ -130,7 +130,7 @@ def service_protocols(service, permanent: permanent?) # reads the permanent configuration # @return [Array] The firewall service modules def service_modules(service, permanent: permanent?) - string_command("--service=#{service}", "--get-modules", permanent: permanent).split(" ") + string_command("--service=#{service}", "--get-modules", permanent: permanent).split end # @param service [String] The firewall service diff --git a/library/network/src/lib/y2firewall/firewalld/api/zones.rb b/library/network/src/lib/y2firewall/firewalld/api/zones.rb index a8a8537ab..44e1e65f2 100644 --- a/library/network/src/lib/y2firewall/firewalld/api/zones.rb +++ b/library/network/src/lib/y2firewall/firewalld/api/zones.rb @@ -29,7 +29,7 @@ class Api module Zones # @return [Array] List of firewall zones def zones - string_command("--get-zones").split(" ") + string_command("--get-zones").split end # Create the given zone in firewalld. New zones must be created @@ -53,7 +53,7 @@ def delete_zone(zone) # reads the permanent configuration # @return [Array] list of zone's interfaces def list_interfaces(zone, permanent: permanent?) - string_command("--zone=#{zone}", "--list-interfaces", permanent: permanent).split(" ") + string_command("--zone=#{zone}", "--list-interfaces", permanent: permanent).split end # @param zone [String] The firewall zone @@ -61,7 +61,7 @@ def list_interfaces(zone, permanent: permanent?) # reads the permanent configuration # @return [Arrray] list of zone's services def list_services(zone, permanent: permanent?) - string_command("--zone=#{zone}", "--list-services", permanent: permanent).split(" ") + string_command("--zone=#{zone}", "--list-services", permanent: permanent).split end # @param zone [String] The firewall zone @@ -69,7 +69,7 @@ def list_services(zone, permanent: permanent?) # reads the permanent configuration # @return [Array] list of zone's ports def list_ports(zone, permanent: permanent?) - string_command("--zone=#{zone}", "--list-ports", permanent: permanent).split(" ") + string_command("--zone=#{zone}", "--list-ports", permanent: permanent).split end # @param zone [String] The firewall zone @@ -77,7 +77,7 @@ def list_ports(zone, permanent: permanent?) # reads the permanent configuration # @return [Array] list of zone's protocols def list_protocols(zone, permanent: permanent?) - string_command("--zone=#{zone}", "--list-protocols", permanent: permanent).split(" ") + string_command("--zone=#{zone}", "--list-protocols", permanent: permanent).split end # @param zone [String] The firewall zone @@ -88,7 +88,7 @@ def list_all(zone, permanent: permanent?, verbose: false) args = ["--zone=#{zone}", "--list-all"] args << "--verbose" if verbose - string_command(*args, permanent: permanent).split(" ") + string_command(*args, permanent: permanent).split end # @param permanent [Boolean] if true and firewalld is running it diff --git a/library/network/src/lib/y2firewall/firewalld/zone_reader.rb b/library/network/src/lib/y2firewall/firewalld/zone_reader.rb index 169087156..e788e6ef6 100644 --- a/library/network/src/lib/y2firewall/firewalld/zone_reader.rb +++ b/library/network/src/lib/y2firewall/firewalld/zone_reader.rb @@ -113,7 +113,7 @@ def initialize_zones value = entries.first.to_s if BOOLEAN_ATTRIBUTES.include?(attribute) - zone.public_send("#{attribute}=", (value == "yes") ? true : false) + zone.public_send("#{attribute}=", (value == "yes")) elsif zone.attributes.include?(attribute.to_sym) zone.public_send("#{attribute}=", value) else diff --git a/library/network/src/modules/CWMFirewallInterfaces.rb b/library/network/src/modules/CWMFirewallInterfaces.rb index a40dd66f7..7d21d075d 100644 --- a/library/network/src/modules/CWMFirewallInterfaces.rb +++ b/library/network/src/modules/CWMFirewallInterfaces.rb @@ -383,18 +383,15 @@ def InterfacesValidate(_widget, _key, _event) end end - if ifaces.empty? - # question popup - if !Popup.YesNo( + if ifaces.empty? && !Popup.YesNo( _( "No interface is selected. Service will not\n" \ - "be available for other computers.\n" \ - "\n" \ - "Continue?" + "be available for other computers.\n" \ + "\n" \ + "Continue?" ) ) - return false - end + return false end firewall_ifaces = Selected2Opened(ifaces, false) @@ -405,42 +402,39 @@ def InterfacesValidate(_widget, _key, _event) log.info("removed_ifaces: #{removed_ifaces}") # to hide that special string - if !added_ifaces.empty? - if !Popup.YesNo( + if !added_ifaces.empty? && !Popup.YesNo( Builtins.sformat( # yes-no popup _( "Because of firewalld settings, the port\n" \ - "on the following interfaces will additionally be open:\n" \ - "%1\n" \ - "\n" \ - "Continue?" + "on the following interfaces will additionally be open:\n" \ + "%1\n" \ + "\n" \ + "Continue?" ), added_ifaces.join("\n") ) ) - return false - end + return false end # to hide that special string - if !removed_ifaces.empty? - if !Popup.YesNo( + if !removed_ifaces.empty? && !Popup.YesNo( Builtins.sformat( # yes-no popup _( "Because of firewalld settings, the port\n" \ - "on the following interfaces cannot be opened:\n" \ - "%1\n" \ - "\n" \ - "Continue?" + "on the following interfaces cannot be opened:\n" \ + "%1\n" \ + "\n" \ + "Continue?" ), removed_ifaces.join("\n") ) ) - return false - end + return false end + true end @@ -655,11 +649,11 @@ def OpenFirewallHandle(widget, _key, event) Builtins.y2milestone("FD: %1", handle_firewall_details) ret = nil Builtins.y2milestone("RT: %1", ret) - if !handle_firewall_details.nil? - ret = handle_firewall_details.call - else + if handle_firewall_details.nil? w = Builtins.filter(widget) { |k, _v| "services" == k } DisplayDetailsPopup(w) + else + ret = handle_firewall_details.call end UpdateFirewallStatus() EnableOrDisableFirewallDetails() @@ -760,8 +754,8 @@ def OpenFirewallHelpTemplate(restart_displayed) # %1 is check box label, eg. "Open Port in Firewall" (without quotes) help = _( "

Firewall Settings
\n" \ - "To open the firewall to allow access to the service from remote computers,\n" \ - "set %1.
" + "To open the firewall to allow access to the service from remote computers,\n" \ + "set %1.
" ) if restart_displayed # help text for firewall port openning widget 2/3, optional @@ -775,11 +769,10 @@ def OpenFirewallHelpTemplate(restart_displayed) ) end # help text for firewall settings widget 3/3, - help = Ops.add( + Ops.add( help, _("This option is available only if the firewall\nis enabled.

") ) - help end # Get the help text to the firewall opening widget @@ -1055,14 +1048,14 @@ def interface_label(name) def services_not_defined_widget(services) services_list = services.map do |service| - if !firewalld.current_service_names.include?(service) + if firewalld.current_service_names.include?(service) # TRANSLATORS: do not modify '%{service}', it will be replaced with service name. # TRANSLATORS: item in a list, '-' is used as marker. Feel free to change it - HBox(HSpacing(2), Left(Label(format(_("- %{service} (Not available)"), service: service)))) + HBox(HSpacing(2), Left(Label(format(_("- %{service}"), service: service)))) else # TRANSLATORS: do not modify '%{service}', it will be replaced with service name. # TRANSLATORS: item in a list, '-' is used as marker. Feel free to change it - HBox(HSpacing(2), Left(Label(format(_("- %{service}"), service: service)))) + HBox(HSpacing(2), Left(Label(format(_("- %{service} (Not available)"), service: service)))) end end diff --git a/library/network/src/modules/Internet.rb b/library/network/src/modules/Internet.rb index 2661ea28a..286c3440c 100644 --- a/library/network/src/modules/Internet.rb +++ b/library/network/src/modules/Internet.rb @@ -100,14 +100,12 @@ def GetDevices # @param [String] log file for the commands output # @return true if successful started def Start(log) - if @type == "dsl" && @capi_adsl || @type == "isdn" + if (@type == "dsl" && @capi_adsl) || @type == "isdn" status = Service.Status("isdn") Builtins.y2milestone("We need ISDN service, status: %1", status) - if status != 0 - if !Service.Start("isdn") - Builtins.y2error("start failed") - return false - end + if status != 0 && !Service.Start("isdn") + Builtins.y2error("start failed") + return false end end @@ -139,14 +137,12 @@ def Start(log) return false end - if @type == "isdn" && !@capi_isdn - if SCR.Execute( - path(".target.bash"), - "/sbin/isdnctrl dial #{@device.shellescape}" - ) != 0 - Builtins.y2error("isdnctrl failed") - return false - end + if @type == "isdn" && !@capi_isdn && (SCR.Execute( + path(".target.bash"), + "/sbin/isdnctrl dial #{@device.shellescape}" + ) != 0) + Builtins.y2error("isdnctrl failed") + return false end true @@ -183,7 +179,7 @@ def Status # Test if the interface is connected # @return true if connected def Connected - if @type == "dsl" || @type == "modem" || @type == "isdn" && @capi_isdn + if @type == "dsl" || @type == "modem" || (@type == "isdn" && @capi_isdn) tmp1 = Convert.to_string( SCR.Read( path(".target.string"), diff --git a/library/network/src/modules/NetworkInterfaces.rb b/library/network/src/modules/NetworkInterfaces.rb index b5481c586..44992b25b 100644 --- a/library/network/src/modules/NetworkInterfaces.rb +++ b/library/network/src/modules/NetworkInterfaces.rb @@ -196,9 +196,8 @@ def IsEmpty(value) def GetEthTypeFromSysfs(dev) sys_dir_path = "/sys/class/net/#{dev}" - if FileUtils.Exists("#{sys_dir_path}/wireless") - "wlan" - elsif FileUtils.Exists("#{sys_dir_path}/phy80211") + if FileUtils.Exists("#{sys_dir_path}/wireless") || + FileUtils.Exists("#{sys_dir_path}/phy80211") "wlan" elsif FileUtils.Exists("#{sys_dir_path}/bridge") "br" @@ -647,12 +646,12 @@ def generate_config(pth, values) v, _j, s = val.rpartition("_") log.info("#{val}:#{v}:#{s}") # Global - if !LOCALS.include?(v) - config[val] = item - else + if LOCALS.include?(v) config["_aliases"] ||= {} config["_aliases"][s] ||= {} config["_aliases"][s][v] = item + else + config[val] = item end end log.info("config=#{ConcealSecrets1(config)}") @@ -995,13 +994,7 @@ def Import(devregex, devices) to: "map >>" ) - @initialized = if devices.nil? || devices == {} - # devices == $[] is used in lan_auto "Reset" as a way how to - # rollback changes imported from AY - false - else - true - end + @initialized = !(devices.nil? || devices == {}) Builtins.y2milestone( "NetworkInterfaces::Import - done, cache content: %1", @@ -1287,10 +1280,10 @@ def Change2(name, newdev, check) return false end - t = if !IsEmpty(newdev) - GetTypeFromIfcfgOrName(name, newdev) - else + t = if IsEmpty(newdev) GetType(name) + else + GetTypeFromIfcfgOrName(name, newdev) end if name == @Name @@ -1346,9 +1339,10 @@ def Commit Builtins.y2debug("Deleted=%1", @Deleted) Builtins.y2debug("operation=%1", @operation) - if @operation == :add || @operation == :edit + case @operation + when :add, :edit Change2(@Name, @Current, @operation == :add) - elsif @operation == :delete + when :delete Delete2(@Name) else Builtins.y2error("Unknown operation: %1 (%2)", @operation, @Name) @@ -1400,7 +1394,7 @@ def GetIP(device) def Locate(key, val) ret = [] - @Devices.values.each do |devsmap| + @Devices.each_value do |devsmap| devsmap.each do |device, conf| ret << device if conf[key] == val end @@ -1561,7 +1555,7 @@ def delete_alias(devices, iface, alias_num) # look in OriginalDevs because we need to catch all variables # of the alias - dev_aliases.fetch(alias_num, {}).keys.each do |key| + dev_aliases.fetch(alias_num, {}).each_key do |key| p = base + "#{key}_#{alias_num}" log.debug("deleting: #{p}") SCR.Write(p, nil) diff --git a/library/network/src/modules/NetworkPopup.rb b/library/network/src/modules/NetworkPopup.rb index 1c659eeb1..3a84bc1a5 100644 --- a/library/network/src/modules/NetworkPopup.rb +++ b/library/network/src/modules/NetworkPopup.rb @@ -203,8 +203,7 @@ def NFSServer(selected) end # selection box label - ret = ChooseItemSimple(_("&NFS Servers"), @found_nfs_servers, selected) - ret + ChooseItemSimple(_("&NFS Servers"), @found_nfs_servers, selected) end # Give me one host name on the local network @@ -227,8 +226,7 @@ def HostName(selected) end # selection box label - ret = ChooseItemSimple(_("Re&mote Hosts"), @found_hosts, selected) - ret + ChooseItemSimple(_("Re&mote Hosts"), @found_hosts, selected) end # Give me export path of selected server @@ -247,8 +245,7 @@ def NFSExport(server, selected) dirs = [] if dirs.nil? # selection box label - ret = ChooseItemSimple(_("&Exported Directories"), dirs, selected) - ret + ChooseItemSimple(_("&Exported Directories"), dirs, selected) end publish function: :ChooseItem, type: "string (string, list , string)" diff --git a/library/network/src/modules/NetworkService.rb b/library/network/src/modules/NetworkService.rb index 6917b8e3c..b0143f0df 100644 --- a/library/network/src/modules/NetworkService.rb +++ b/library/network/src/modules/NetworkService.rb @@ -97,9 +97,9 @@ def RunSystemCtl(service, action, force: false) raise ArgumentError, "No network service defined." if service.nil? cmd = "/usr/bin/systemctl "\ - "#{force ? "--force" : ""} " \ - "#{action.shellescape} " \ - "#{service.shellescape}.service" + "#{force ? "--force" : ""} " \ + "#{action.shellescape} " \ + "#{service.shellescape}.service" ret = SCR.Execute(path(".target.bash_output"), cmd, "TERM" => "raw") Builtins.y2debug("RunSystemCtl: Command '%1' returned '%2'", cmd, ret) Ops.get_integer(ret, "exit", -1) @@ -304,9 +304,9 @@ def ConfirmNetworkManager cont = Popup.ContinueCancel( _( "Your network interfaces are currently controlled by NetworkManager\n" \ - "but the service to configure might not work well with it.\n" \ - "\n" \ - "Really continue?" + "but the service to configure might not work well with it.\n" \ + "\n" \ + "Really continue?" ) ) Builtins.y2milestone( @@ -330,10 +330,10 @@ def isNetworkv4Running ) if net == 0 Builtins.y2milestone("IPv4 network is running ...") - return true + true else Builtins.y2milestone("IPv4 network is not running ...") - return false + false end end @@ -346,10 +346,10 @@ def isNetworkv6Running if net == 0 Builtins.y2milestone("IPv6 network is running ...") - return true + true else Builtins.y2milestone("IPv6 network is not running ...") - return false + false end end diff --git a/library/network/src/modules/PortAliases.rb b/library/network/src/modules/PortAliases.rb index 5bc6d58e3..fe2db6e3e 100644 --- a/library/network/src/modules/PortAliases.rb +++ b/library/network/src/modules/PortAliases.rb @@ -60,8 +60,8 @@ def AllowedPortNameOrNumber # TRANSLATORS: popup informing message, allowed characters for port-names _( "A port name may consist of the characters 'a-z', 'A-Z', '0-9', and '*+._-'.\n" \ - "A port number may be a number from 0 to 65535.\n" \ - "No spaces are allowed.\n" + "A port number may be a number from 0 to 65535.\n" \ + "No spaces are allowed.\n" ) end diff --git a/library/network/src/modules/PortRanges.rb b/library/network/src/modules/PortRanges.rb index cd1bf04fb..3c3315cbb 100644 --- a/library/network/src/modules/PortRanges.rb +++ b/library/network/src/modules/PortRanges.rb @@ -438,53 +438,51 @@ def FlattenServices(old_list, protocol) Builtins.foreach(port_numbers_to_port_names) do |port_number, _port_names| # Port is not in any defined port range - if !PortIsInPortranges(Builtins.tostring(port_number), list_of_ranges) - # Port - 1 IS in some port range - if PortIsInPortranges( - Builtins.tostring(Ops.subtract(port_number, 1)), + if PortIsInPortranges(Builtins.tostring(port_number), list_of_ranges) + Builtins.y2milestone( + "Removing port %1 mentioned in port ranges %2", + port_number, list_of_ranges ) - # Creating fake port range, to be joined with another one - list_of_ranges = Builtins.add( - list_of_ranges, - CreateNewPortRange(Ops.subtract(port_number, 1), port_number) - ) - # Port + 1 IS in some port range - elsif PortIsInPortranges( - Builtins.tostring(Ops.add(port_number, 1)), - list_of_ranges + elsif PortIsInPortranges( + Builtins.tostring(Ops.subtract(port_number, 1)), + list_of_ranges + ) + # Port - 1 IS in some port range + list_of_ranges = Builtins.add( + list_of_ranges, + CreateNewPortRange(Ops.subtract(port_number, 1), port_number) ) - # Creating fake port range, to be joined with another one - list_of_ranges = Builtins.add( - list_of_ranges, - CreateNewPortRange(port_number, Ops.add(port_number, 1)) - ) - # Port is not in any port range and also it cannot be joined with any one + # Creating fake port range, to be joined with another one + # Port + 1 IS in some port range + elsif PortIsInPortranges( + Builtins.tostring(Ops.add(port_number, 1)), + list_of_ranges + ) + # Creating fake port range, to be joined with another one + list_of_ranges = Builtins.add( + list_of_ranges, + CreateNewPortRange(port_number, Ops.add(port_number, 1)) + ) + # Port is not in any port range and also it cannot be joined with any one + else + # Port names of this port + used_port_names = Ops.get( + port_numbers_to_port_names, + port_number, + [] + ) + if Ops.greater_than(Builtins.size(used_port_names), 0) + new_list = Builtins.add(new_list, Ops.get(used_port_names, 0, "")) else - # Port names of this port - used_port_names = Ops.get( - port_numbers_to_port_names, - port_number, - [] + Builtins.y2milestone( + "No port name for port number %1. Adding %1...", + port_number ) - if Ops.greater_than(Builtins.size(used_port_names), 0) - new_list = Builtins.add(new_list, Ops.get(used_port_names, 0, "")) - else - Builtins.y2milestone( - "No port name for port number %1. Adding %1...", - port_number - ) - # There are no port names (hmm?), adding port number - new_list = Builtins.add(new_list, Builtins.tostring(port_number)) - end + # There are no port names (hmm?), adding port number + new_list = Builtins.add(new_list, Builtins.tostring(port_number)) end # Port is in a port range - else - Builtins.y2milestone( - "Removing port %1 mentioned in port ranges %2", - port_number, - list_of_ranges - ) end end @@ -563,6 +561,8 @@ def FlattenServices(old_list, protocol) # If new port range should be created new_min = nil new_max = nil + # rubocop:disable Lint/DuplicateBranch + # wrong detection of duplicate branch as if cause logic and workflow # the second one is inside the first one if Ops.less_or_equal(min_pr, this_min_pr) && Ops.greater_or_equal(max_pr, this_max_pr) @@ -586,7 +586,7 @@ def FlattenServices(old_list, protocol) new_max = this_max_pr # the second one partly covers the first one (by its left side) elsif Ops.greater_or_equal(min_pr, this_min_pr) && - Ops.less_or_equal(max_pr, this_max_pr) + Ops.greater_or_equal(max_pr, this_max_pr) # take this_min_pr & max_pr any_change_during_this_loop = true new_min = this_min_pr @@ -604,6 +604,7 @@ def FlattenServices(old_list, protocol) new_min = this_min_pr new_max = max_pr end + # rubocop:enable Lint/DuplicateBranch if any_change_during_this_loop && !new_min.nil? && !new_max.nil? new_port_range = CreateNewPortRange(new_min, new_max) Builtins.y2milestone( diff --git a/library/network/src/modules/SuSEFirewallProposal.rb b/library/network/src/modules/SuSEFirewallProposal.rb index ffe29d6b9..ac44c1af3 100644 --- a/library/network/src/modules/SuSEFirewallProposal.rb +++ b/library/network/src/modules/SuSEFirewallProposal.rb @@ -506,14 +506,14 @@ def Propose end # Not changed by user - Propose from scratch - if !GetChangedByUser() + if GetChangedByUser() + Builtins.y2milestone("Calling firewall configuration update proposal") + UpdateProposal() + else Builtins.y2milestone("Calling firewall configuration proposal") Reset() ProposeFunctions() # Changed - don't break user's configuration - else - Builtins.y2milestone("Calling firewall configuration update proposal") - UpdateProposal() end nil @@ -635,15 +635,13 @@ def ProposalSummary "SSH is " + (is_ssh_enabled ? "" : "not ") + "enabled" ) - if Linuxrc.usessh - if !is_ssh_enabled - # TRANSLATORS: This is a warning message. Installation over SSH without SSH allowed on firewall - AddWarning( - _( - "You are installing a system over SSH, but you have not opened the SSH port on the firewall." - ) + if Linuxrc.usessh && !is_ssh_enabled + # TRANSLATORS: This is a warning message. Installation over SSH without SSH allowed on firewall + AddWarning( + _( + "You are installing a system over SSH, but you have not opened the SSH port on the firewall." ) - end + ) end # when the firewall is enabled and we are installing the system over VNC diff --git a/library/network/src/modules/firewalld_wrapper.rb b/library/network/src/modules/firewalld_wrapper.rb index 02bc3faa3..17487089a 100644 --- a/library/network/src/modules/firewalld_wrapper.rb +++ b/library/network/src/modules/firewalld_wrapper.rb @@ -35,6 +35,8 @@ class FirewalldWrapperClass < Module VALID_PROTOCOLS = ["udp", "tcp", "sctp", "dccp"].freeze def initialize + super + Yast.import "PortAliases" Yast.import "PortRanges" end @@ -210,11 +212,9 @@ def firewalld # either a number or a known service name # @return [Boolean] true if is valid port or range of ports def valid_port?(port_or_range) - if !PortRanges.IsValidPortRange(port_or_range) - unless PortAliases.GetPortNumber(port_or_range) - log.error("The given port or range of ports are not valid: #{port_or_range}") - return false - end + if !PortRanges.IsValidPortRange(port_or_range) && !PortAliases.GetPortNumber(port_or_range) + log.error("The given port or range of ports are not valid: #{port_or_range}") + return false end true diff --git a/library/network/test/test_helper.rb b/library/network/test/test_helper.rb index cc344b30c..43cfd54c0 100644 --- a/library/network/test/test_helper.rb +++ b/library/network/test/test_helper.rb @@ -1,4 +1,4 @@ -require_relative "../../../test/test_helper.rb" +require_relative "../../../test/test_helper" require "fileutils" Yast.import "NetworkInterfaces" diff --git a/library/network/test/y2firewall/firewalld/api/services_test.rb b/library/network/test/y2firewall/firewalld/api/services_test.rb index 9f4bd7f06..45ca4b2e7 100755 --- a/library/network/test/y2firewall/firewalld/api/services_test.rb +++ b/library/network/test/y2firewall/firewalld/api/services_test.rb @@ -60,7 +60,7 @@ it "obtains the list of firewalld defined services" do allow(api).to receive(:string_command).with("--get-services").and_return(defined_services) - expect(subject.services).to eql(defined_services.split(" ")) + expect(subject.services).to eql(defined_services.split) end end diff --git a/library/network/test/y2firewall/firewalld/api/zones_test.rb b/library/network/test/y2firewall/firewalld/api/zones_test.rb index b920a5c10..3081c1aa5 100755 --- a/library/network/test/y2firewall/firewalld/api/zones_test.rb +++ b/library/network/test/y2firewall/firewalld/api/zones_test.rb @@ -30,7 +30,7 @@ it "obtains the list of firewalld defined zones" do allow(api).to receive(:string_command).with("--get-zones").and_return(known_zones) - expect(subject.zones).to eql(known_zones.split(" ")) + expect(subject.zones).to eql(known_zones.split) end end diff --git a/library/packages/src/lib/packages/file_conflict_callbacks.rb b/library/packages/src/lib/packages/file_conflict_callbacks.rb index 68ed25dc3..0069335f7 100644 --- a/library/packages/src/lib/packages/file_conflict_callbacks.rb +++ b/library/packages/src/lib/packages/file_conflict_callbacks.rb @@ -131,7 +131,7 @@ def report(excluded_packages, conflicts) if Yast::Mode.auto || Yast::Mode.commandline # TRANSLATORS: An error message, %s is the actual list of detected conflicts Yast::Report.Error(_("File conflicts detected, these conflicting files will " \ - "be overwritten:\n\n%s") % conflicts.join("\n\n")) + "be overwritten:\n\n%s") % conflicts.join("\n\n")) return true end @@ -168,8 +168,8 @@ def dialog(conflicts) # TRANSLATORS: A popup label, use max. 70 chars per line, use more lines if needed label = _("File conflicts happen when two packages attempt to install\n" \ - "files with the same name but different contents. If you continue\n" \ - "the conflicting files will be replaced, losing the previous content.") + "files with the same name but different contents. If you continue\n" \ + "the conflicting files will be replaced, losing the previous content.") # TRANSLATORS: Popup heading heading = n_("A File Conflict Detected", "File Conflicts Detected", conflicts.size) diff --git a/library/packages/src/lib/y2packager/license.rb b/library/packages/src/lib/y2packager/license.rb index 8176b836f..cbfee69c4 100644 --- a/library/packages/src/lib/y2packager/license.rb +++ b/library/packages/src/lib/y2packager/license.rb @@ -58,7 +58,7 @@ def find(product_name, content: nil) handler = LicensesHandlers.for(fetcher, product_name) if fetcher license = License.new(product_name: product_name, fetcher: fetcher, - handler: handler, content: content) + handler: handler, content: content) return unless license.id cached_license = cache.values.find { |l| l.id == license.id } diff --git a/library/packages/src/lib/y2packager/licenses_fetchers/base.rb b/library/packages/src/lib/y2packager/licenses_fetchers/base.rb index f5b591559..c85f68b16 100644 --- a/library/packages/src/lib/y2packager/licenses_fetchers/base.rb +++ b/library/packages/src/lib/y2packager/licenses_fetchers/base.rb @@ -47,7 +47,7 @@ def found? def content(lang) # FIXME: not #default_content at some place? if default_lang?(lang) && @default_content - return (@default_content&.empty?) ? nil : @default_content + return @default_content&.empty? ? nil : @default_content end license_content_for(lang) diff --git a/library/packages/src/lib/y2packager/licenses_fetchers/rpm.rb b/library/packages/src/lib/y2packager/licenses_fetchers/rpm.rb index c24c8cc54..72012ad03 100644 --- a/library/packages/src/lib/y2packager/licenses_fetchers/rpm.rb +++ b/library/packages/src/lib/y2packager/licenses_fetchers/rpm.rb @@ -19,12 +19,9 @@ module LicensesFetchers # of a given product from a RPM package class Rpm < Archive # FIXME: there's (ATM) no way to indent the 'private' below so rubocop accepts it - # rubocop:disable Layout/IndentationWidth private - # rubocop:enable Layout/IndentationWidth - # Check if a license archive exists # # @return [Boolean] True, if an archive exists diff --git a/library/packages/src/lib/y2packager/licenses_fetchers/tarball.rb b/library/packages/src/lib/y2packager/licenses_fetchers/tarball.rb index 01019792b..a69f84493 100644 --- a/library/packages/src/lib/y2packager/licenses_fetchers/tarball.rb +++ b/library/packages/src/lib/y2packager/licenses_fetchers/tarball.rb @@ -22,12 +22,9 @@ module LicensesFetchers # of a given product from a tar archive (.tar.gz) class Tarball < Archive # FIXME: there's (ATM) no way to indent the 'private' below so rubocop accepts it - # rubocop:disable Layout/IndentationWidth private - # rubocop:enable Layout/IndentationWidth - attr_reader :archive_file_name # Check if a license archive exists diff --git a/library/packages/src/lib/y2packager/product.rb b/library/packages/src/lib/y2packager/product.rb index 9b0afcaea..b586ce58c 100644 --- a/library/packages/src/lib/y2packager/product.rb +++ b/library/packages/src/lib/y2packager/product.rb @@ -169,8 +169,8 @@ def ==(other) result = arch == other.arch && name == other.name && version == other.version && vendor == other.vendor log.info("Comparing products: '#{arch}' <=> '#{other.arch}', '#{name}' <=> '#{other.name}', "\ - "'#{version}' <=> '#{other.version}', '#{vendor}' <=> '#{other.vendor}' => "\ - "result: #{result}") + "'#{version}' <=> '#{other.version}', '#{vendor}' <=> '#{other.vendor}' => "\ + "result: #{result}") result end diff --git a/library/packages/src/lib/y2packager/release_notes_fetchers/rpm.rb b/library/packages/src/lib/y2packager/release_notes_fetchers/rpm.rb index 2bf3f6155..8936b8c7b 100644 --- a/library/packages/src/lib/y2packager/release_notes_fetchers/rpm.rb +++ b/library/packages/src/lib/y2packager/release_notes_fetchers/rpm.rb @@ -56,8 +56,8 @@ def release_notes(prefs) relnotes = extract_release_notes(prefs) log.info "Got release notes for #{product.name} from RPM " \ - "#{release_notes_package.name} #{release_notes_package.version} " \ - "with #{prefs}" + "#{release_notes_package.name} #{release_notes_package.version} " \ + "with #{prefs}" relnotes end diff --git a/library/packages/src/lib/y2packager/release_notes_fetchers/url.rb b/library/packages/src/lib/y2packager/release_notes_fetchers/url.rb index 2151b3928..036530cf1 100644 --- a/library/packages/src/lib/y2packager/release_notes_fetchers/url.rb +++ b/library/packages/src/lib/y2packager/release_notes_fetchers/url.rb @@ -115,7 +115,7 @@ def release_notes(prefs) if relnotes log.info "Got release notes for #{product.name} from URL #{relnotes_url} " \ - "with #{prefs}" + "with #{prefs}" return relnotes end diff --git a/library/packages/src/lib/y2packager/repository.rb b/library/packages/src/lib/y2packager/repository.rb index db5c0ecc6..000d6a486 100644 --- a/library/packages/src/lib/y2packager/repository.rb +++ b/library/packages/src/lib/y2packager/repository.rb @@ -130,7 +130,7 @@ def create(name:, url:, product_dir: "", enabled: true, autorefresh: true) # @param product_dir [String] Product directory # @param enabled [Boolean] Is the repository enabled? # @param autorefresh [Boolean] Is auto-refresh enabled for this repository? - def initialize(repo_id:, repo_alias:, name:, url:, raw_url: nil, product_dir: "", enabled:, autorefresh:) + def initialize(repo_id:, repo_alias:, name:, url:, enabled:, autorefresh:, raw_url: nil, product_dir: "") @repo_id = repo_id @repo_alias = repo_alias @name = name diff --git a/library/packages/src/lib/y2packager/resolvable.rb b/library/packages/src/lib/y2packager/resolvable.rb index 1bbd549c2..8b9727236 100644 --- a/library/packages/src/lib/y2packager/resolvable.rb +++ b/library/packages/src/lib/y2packager/resolvable.rb @@ -101,7 +101,7 @@ def initialize(hash) # Backward compatibility method to access resolvable like hash. def [](key) log.info "Calling [] with #{key}. It is deprecated. Use method name " \ - "directly. Called from #{caller(1).first}" + "directly. Called from #{caller(1).first}" public_send(key.to_sym) # key not found, so return nil to be compatible @@ -166,7 +166,7 @@ def from_hash(hash) # @param attr [Symbol] The required attribute to load. # @return [Object] The read value. def load_attribute(attr) - attrs = Hash[((UNIQUE_ATTRIBUTES + OPTIONAL_ATTRIBUTES).map { |a| [a, instance_variable_get("@#{a}")] })] + attrs = ((UNIQUE_ATTRIBUTES + OPTIONAL_ATTRIBUTES).map { |a| [a, instance_variable_get("@#{a}")] }).to_h resolvables = Yast::Pkg.Resolvables(attrs, [attr]) # Finding more than one result is suspicious, log a warning diff --git a/library/packages/src/lib/y2packager/zypp_url.rb b/library/packages/src/lib/y2packager/zypp_url.rb index daccf3209..16548951c 100644 --- a/library/packages/src/lib/y2packager/zypp_url.rb +++ b/library/packages/src/lib/y2packager/zypp_url.rb @@ -45,6 +45,8 @@ class ZyppUrl < SimpleDelegator # # @param url [String, ZyppUrl, URI::Generic] def initialize(url) + super + uri = begin URI(repovars_escape(url.to_s)) diff --git a/library/packages/src/modules/PackageCallbacks.rb b/library/packages/src/modules/PackageCallbacks.rb index c063324e8..28e843703 100644 --- a/library/packages/src/modules/PackageCallbacks.rb +++ b/library/packages/src/modules/PackageCallbacks.rb @@ -31,7 +31,7 @@ class PackageCallbacksClass < Module include Yast::Logger # text to clean progress bar in command line - CLEAR_PROGRESS_TEXT = "\b" * 10 + " " * 10 + "\b" * 10 + CLEAR_PROGRESS_TEXT = ("\b" * 10) + (" " * 10) + ("\b" * 10) # max. length of the text in the repository popup window MAX_POPUP_TEXT_SIZE = 60 # base in seconds for automatic retry after a timeout, @@ -52,6 +52,8 @@ class PackageCallbacksClass < Module # # @param name [Symbol] name of the added method def self.method_added(name) + super + # log the callbacks only when requested, it's quite verbose return if ENV["Y2DEBUG_CALLBACKS"] != "1" @@ -84,10 +86,10 @@ def #{name}_hook(*params) class_eval(hook, __FILE__, __LINE__) # rename the original method - class_eval("alias #{name}_without_hook #{name}", __FILE__, __LINE__) + class_eval("alias #{name}_without_hook #{name}", __FILE__, __LINE__) # alias m_without_hook m # replace the original method with the hook - class_eval("alias #{name} #{name}_hook", __FILE__, __LINE__) + class_eval("alias #{name} #{name}_hook", __FILE__, __LINE__) # alias m m_hook end def main @@ -341,9 +343,10 @@ def DoneProvide(error, reason, name) error_symbol = "ERROR" # https://github.com/openSUSE/libzypp/blob/8dda46306f06440e1acaefb36fb60f6ce909fd42/zypp/ZYppCallbacks.h#L106 - if error == 2 + case error + when 2 error_symbol = "IO" - elsif error == 3 + when 3 error_symbol = "INVALID" end @@ -494,7 +497,12 @@ def DonePackage(error, reason) UI.CloseDialog if @_package_popup @_package_popup = false - if error != 0 + if error == 0 + # no error, there is additional info (rpm output), see bnc#456446 + Builtins.y2milestone("Additional RPM otput: %1", reason) + + CommandLine.Print(reason) if Mode.commandline + else Builtins.y2milestone( "DonePackage(error: %1, reason: '%2')", error, @@ -590,12 +598,7 @@ def DonePackage(error, reason) return "R" if r == :retry end - # default: ignore - else - # no error, there is additional info (rpm output), see bnc#456446 - Builtins.y2milestone("Additional RPM otput: %1", reason) - - CommandLine.Print(reason) if Mode.commandline + # default: ignore end "I" @@ -983,13 +986,13 @@ def MediaChange(error_code, error, url, product, current, current_label, wanted, if found Builtins.y2milestone("Device %1 has index %2", eject_device, dindex) - return "E#{dindex}" + "E#{dindex}" else Builtins.y2warning( "Device %1 not found in the list, using default", eject_device ) - return "E" + "E" end when :url Builtins.y2milestone("Redirecting to: %1", URL.HidePassword(url)) @@ -1147,16 +1150,17 @@ def SourceCreateError(url, error, description) # error message - a label followed by a richtext with details message = _("An error occurred while creating the repository.") - if error == :NOT_FOUND + case error + when :NOT_FOUND # error message - a label followed by a richtext with details message = _("Unable to retrieve the remote repository description.") - elsif error == :IO + when :IO # error message - a label followed by a richtext with details message = _("An error occurred while retrieving the new metadata.") - elsif error == :INVALID + when :INVALID # error message - a label followed by a richtext with details message = _("The repository is not valid.") - elsif error == :REJECTED + when :REJECTED # error message - a label followed by a richtext with details message = _("The repository metadata is invalid.") end @@ -1274,19 +1278,20 @@ def SourceProbeError(url, error, description) # error message - a label followed by a richtext with details message = _("Error occurred while probing the repository.") - if error == :NOT_FOUND + case error + when :NOT_FOUND # error message - a label followed by a richtext with details message = _("Unable to retrieve the remote repository description.") - elsif error == :IO + when :IO # error message - a label followed by a richtext with details message = _("An error occurred while retrieving the new metadata.") - elsif error == :INVALID + when :INVALID # error message - a label followed by a richtext with details message = _("The repository is not valid.") - elsif error == :NO_ERROR + when :NO_ERROR # error message - a label followed by a richtext with details message = _("Repository probing details.") - elsif error == :REJECTED + when :REJECTED # error message - a label followed by a richtext with details message = _("Repository metadata is invalid.") end @@ -1384,13 +1389,14 @@ def SourceReportError(source_id, url, error, description) # error message - a label followed by a richtext with details message = Builtins.sformat(_("Repository %1"), url) - if error == :NOT_FOUND + case error + when :NOT_FOUND # error message - a label followed by a richtext with details message = _("Unable to retrieve the remote repository description.") - elsif error == :IO + when :IO # error message - a label followed by a richtext with details message = _("An error occurred while retrieving the new metadata.") - elsif error == :INVALID + when :INVALID # error message - a label followed by a richtext with details message = _("The repository is not valid.") end @@ -1575,15 +1581,15 @@ def ScriptStart(patch_name, patch_version, patch_arch, script_path) # popup heading Heading(_("Running Script")), VBox( - if patch_full_name != "" + if patch_full_name == "" + Empty() + else HBox( # label, patch name follows Label(Opt(:boldFont), _("Patch: ")), Label(patch_full_name), HStretch() ) - else - Empty() end, HBox( # label, script name follows @@ -1651,13 +1657,14 @@ def ScriptProblem(description) # Abort is the default ret = "A" - if ui == :retry + case ui + when :retry # ignore ret = "I" - elsif ui == :yes + when :yes # retry ret = "R" - elsif ui == :no + when :no # abort ret = "A" else @@ -1744,32 +1751,30 @@ def CloseDownloadProgressPopup end def InitDownload(task) - if !Mode.commandline - if !full_screen && !IsDownloadProgressPopup() - # heading of popup - heading = _("Downloading") + if !Mode.commandline && (!full_screen && !IsDownloadProgressPopup()) + # heading of popup + heading = _("Downloading") - UI.OpenDialog( - Opt(:decorated), + UI.OpenDialog( + Opt(:decorated), + VBox( + Heading(Id(:download_progress_popup_window), heading), VBox( - Heading(Id(:download_progress_popup_window), heading), - VBox( - HSpacing(60), - HBox( - HSpacing(1), - ProgressBar(Id(:progress), task, 100), - HSpacing(1) - ), - VSpacing(0.5), - ButtonBox( - PushButton(Id(:abort), Opt(:cancelButton), Label.AbortButton) - ), - VSpacing(0.5) - ) + HSpacing(60), + HBox( + HSpacing(1), + ProgressBar(Id(:progress), task, 100), + HSpacing(1) + ), + VSpacing(0.5), + ButtonBox( + PushButton(Id(:abort), Opt(:cancelButton), Label.AbortButton) + ), + VSpacing(0.5) ) ) - UI.ChangeWidget(Id(:progress), :Value, 0) - end + ) + UI.ChangeWidget(Id(:progress), :Value, 0) end nil @@ -1861,9 +1866,10 @@ def ProgressDownload(percent, bps_avg, bps_current) # display "Continue", "Skip Refresh" dialog answer = AskAbortRefresh() - if answer == :continue + case answer + when :continue download_aborted = false - elsif answer == :skip + when :skip download_aborted = true @autorefreshing_aborted = true @@ -2189,9 +2195,10 @@ def ErrorScanDb(error, description) if show_details error_symbol = "UNKNOWN" - if error == 0 + case error + when 0 error_symbol = "NO_ERROR" - elsif error == 1 + when 1 error_symbol = "FAILED" end @@ -2256,7 +2263,7 @@ def Authentication(url, msg, username, password) # dgettext() url_query = URI(url).query if url_query - url_params = Hash[URI.decode_www_form(url_query)] + url_params = URI.decode_www_form(url_query).to_h if url_params.key?("credentials") # Seems to be the url of a registration server, so add the tip to msg tip = Builtins.dgettext("registration", @@ -3223,7 +3230,7 @@ def remember_autoeject end def process_message(msg, max_len) - words = msg.split(" ") + words = msg.split log.info "words: %{words}" diff --git a/library/packages/src/modules/PackageKit.rb b/library/packages/src/modules/PackageKit.rb index 025fb28e7..1adde2b18 100644 --- a/library/packages/src/modules/PackageKit.rb +++ b/library/packages/src/modules/PackageKit.rb @@ -37,7 +37,7 @@ def main; end # @return [Boolean] return true if PackageKit is currently running def IsRunning cmd = "/usr/bin/dbus-send --system --dest=org.freedesktop.DBus --type=method_call --print-reply " \ - "--reply-timeout=200 / org.freedesktop.DBus.NameHasOwner string:org.freedesktop.PackageKit" + "--reply-timeout=200 / org.freedesktop.DBus.NameHasOwner string:org.freedesktop.PackageKit" Builtins.y2milestone("Checking PackageKit status: %1", cmd) out = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd)) @@ -59,7 +59,7 @@ def IsRunning # you have to check the current status using isRunning() function. def SuggestQuit cmd = "/usr/bin/dbus-send --system --dest=org.freedesktop.PackageKit --type=method_call " \ - "/org/freedesktop/PackageKit org.freedesktop.PackageKit.SuggestDaemonQuit" + "/org/freedesktop/PackageKit org.freedesktop.PackageKit.SuggestDaemonQuit" Builtins.y2milestone("Asking PackageKit to quit: %1", cmd) ret = Convert.to_integer(SCR.Execute(path(".target.bash"), cmd)) diff --git a/library/packages/src/modules/PackageLock.rb b/library/packages/src/modules/PackageLock.rb index a7e64d13b..907d9cacc 100644 --- a/library/packages/src/modules/PackageLock.rb +++ b/library/packages/src/modules/PackageLock.rb @@ -59,10 +59,10 @@ def AskPackageKit else _( "PackageKit is blocking software management.\n" \ - "This happens when the updater applet or another software management\n" \ - "application is running.\n" \ - "\n" \ - "Ask PackageKit to quit?" + "This happens when the updater applet or another software management\n" \ + "application is running.\n" \ + "\n" \ + "Ask PackageKit to quit?" ) end @@ -158,8 +158,8 @@ def Connect(show_continue_button) # TRANSLATORS: an error message with question _( "Would you like to retry accessing the software manager,\n" \ - "continue without having access to the software management,\n" \ - "or abort?\n" + "continue without having access to the software management,\n" \ + "or abort?\n" ) ), Label.RetryButton, diff --git a/library/packages/src/modules/PackageSystem.rb b/library/packages/src/modules/PackageSystem.rb index efcf2b18c..d7fc2b04c 100644 --- a/library/packages/src/modules/PackageSystem.rb +++ b/library/packages/src/modules/PackageSystem.rb @@ -130,21 +130,17 @@ def SelectPackages(toinstall, toremove) ok = true Builtins.foreach(toinstall) do |p| - if ok == true - if Pkg.PkgInstall(p) != true - Builtins.y2error("Package %1 install failed: %2", p, Pkg.LastError) - ok = false - end + if ok == true && (Pkg.PkgInstall(p) != true) + Builtins.y2error("Package %1 install failed: %2", p, Pkg.LastError) + ok = false end end return false if ok != true Builtins.foreach(toremove) do |p| - if ok == true - if Pkg.PkgDelete(p) != true - Builtins.y2error("Package %1 delete failed: %2", p, Pkg.LastError) - ok = false - end + if ok == true && (Pkg.PkgDelete(p) != true) + Builtins.y2error("Package %1 delete failed: %2", p, Pkg.LastError) + ok = false end end @@ -254,11 +250,9 @@ def DoInstallAndRemoveInt(toinstall, toremove) PackagesUI.show_update_messages(result) Builtins.foreach(Ops.get_list(result, 2, [])) do |remaining| - if ok == true - if Builtins.contains(toinstall, remaining) - Builtins.y2error("Package remain: %1", remaining) - ok = false - end + if ok == true && Builtins.contains(toinstall, remaining) + Builtins.y2error("Package remain: %1", remaining) + ok = false end end return false if ok != true @@ -422,8 +416,8 @@ def CheckAndInstallPackagesInteractive(packages) # continue/cancel popup _( "Installing required packages failed. If you continue\n" \ - "without installing required packages,\n" \ - "YaST may not work properly.\n" + "without installing required packages,\n" \ + "YaST may not work properly.\n" ) ) end diff --git a/library/packages/src/modules/PackagesUI.rb b/library/packages/src/modules/PackagesUI.rb index fdd8937e6..c5f02324b 100644 --- a/library/packages/src/modules/PackagesUI.rb +++ b/library/packages/src/modules/PackagesUI.rb @@ -95,9 +95,10 @@ def DisplayHelpMsg(headline, helptext, color, vdim) helptext = deep_copy(helptext) dia_opt = Opt(:decorated) - if color == :warncolor + case color + when :warncolor dia_opt = Opt(:decorated, :warncolor) - elsif color == :infocolor + when :infocolor dia_opt = Opt(:decorated, :infocolor) end @@ -174,12 +175,12 @@ def ConfirmLicenses # help text help = _( "

License Confirmation
\n" \ - "The package in the headline of the dialog requires an explicit confirmation\n" \ - "of acceptance of its license.\n" \ - "If you reject the license of the package, the package will not be installed.\n" \ - "
\n" \ - "To accept the license of the package, click I Agree.\n" \ - "To reject the license of the package, click I Disagree

." + "The package in the headline of the dialog requires an explicit confirmation\n" \ + "of acceptance of its license.\n" \ + "If you reject the license of the package, the package will not be installed.\n" \ + "
\n" \ + "To accept the license of the package, click I Agree.\n" \ + "To reject the license of the package, click I Disagree

." ) UI.OpenDialog( @@ -206,11 +207,11 @@ def ConfirmLicenses package, ui == :accept ) - if ui != :accept + if ui == :accept + Pkg.PkgMarkLicenseConfirmed(package) + else Pkg.PkgTaboo(package) ret = false - else - Pkg.PkgMarkLicenseConfirmed(package) end end @@ -310,10 +311,10 @@ def RunPackageSelector(options) # exception text raise _("Opening package selector failed.") if !UI.OpenDialog( Opt(:defaultsize), - if !widget_options.empty? - PackageSelector(Id(:packages), widget_options, "") - else + if widget_options.empty? PackageSelector(Id(:packages), "") + else + PackageSelector(Id(:packages), widget_options, "") end ) @@ -342,32 +343,32 @@ def RunPatternSelector(enable_back: false, cancel_label: Label.CancelButton) # Help text for software patterns / selections dialog help_text = _( "

\n" \ - "\t\t This dialog allows you to define this system's tasks and what software to install.\n" \ - "\t\t Available tasks and software for this system are shown by category in the left\n" \ - "\t\t column. To view a description for an item, select it in the list.\n" \ - "\t\t

" + "\t\t This dialog allows you to define this system's tasks and what software to install.\n" \ + "\t\t Available tasks and software for this system are shown by category in the left\n" \ + "\t\t column. To view a description for an item, select it in the list.\n" \ + "\t\t

" ) + _( "

\n" \ - "\t\t Change the status of an item by clicking its status icon\n" \ - "\t\t or right-click any icon for a context menu.\n" \ - "\t\t With the context menu, you can also change the status of all items.\n" \ - "\t\t

" + "\t\t Change the status of an item by clicking its status icon\n" \ + "\t\t or right-click any icon for a context menu.\n" \ + "\t\t With the context menu, you can also change the status of all items.\n" \ + "\t\t

" ) + _( "

\n" \ - "\t\t Details opens the detailed software package selection\n" \ - "\t\t where you can view and select individual software packages.\n" \ - "\t\t

" + "\t\t Details opens the detailed software package selection\n" \ + "\t\t where you can view and select individual software packages.\n" \ + "\t\t

" ) + _( "

\n" \ - "\t\t The disk usage display in the lower right corner shows the remaining disk space\n" \ - "\t\t after all requested changes will have been performed.\n" \ - "\t\t Hard disk partitions that are full or nearly full can degrade\n" \ - "\t\t system performance and in some cases even cause serious problems.\n" \ - "\t\t The system needs some available disk space to run properly.\n" \ - "\t\t

" + "\t\t The disk usage display in the lower right corner shows the remaining disk space\n" \ + "\t\t after all requested changes will have been performed.\n" \ + "\t\t Hard disk partitions that are full or nearly full can degrade\n" \ + "\t\t system performance and in some cases even cause serious problems.\n" \ + "\t\t The system needs some available disk space to run properly.\n" \ + "\t\t

" ) # bugzilla #298056 @@ -702,27 +703,28 @@ def ShowInstallationSummaryMap(summary) # handle detail requests (clicking a link in the summary) if Ops.is_string?(result) # display installation log - if result == "install_log" + case result + when "install_log" ShowDetailsString( _("Installation log"), Ops.get_string(summary, "install_log", "") ) - elsif result == "installed_packages" + when "installed_packages" ShowDetailsList( _("Installed Packages"), Ops.get_list(summary, "installed_list", []) ) - elsif result == "updated_packages" + when "updated_packages" ShowDetailsList( _("Updated Packages"), Ops.get_list(summary, "updated_list", []) ) - elsif result == "removed_packages" + when "removed_packages" ShowDetailsList( _("Removed Packages"), Ops.get_list(summary, "removed_list", []) ) - elsif result == "remaining_packages" + when "remaining_packages" ShowDetailsList( _("Remaining Packages"), Ops.get_list(summary, "remaining", []) @@ -746,8 +748,8 @@ def ShowInstallationSummaryMap(summary) if new_action != "summary" # disabling installation report dialog, inform the user how to enable it back Popup.Message(_("If you want to show this report dialog again edit\n\n"\ - "System > Yast2 > GUI > PKGMGR_ACTION_AT_EXIT\n\n" \ - "value in the YaST sysconfig editor.")) + "System > Yast2 > GUI > PKGMGR_ACTION_AT_EXIT\n\n" \ + "value in the YaST sysconfig editor.")) end Builtins.y2milestone("Changing PKGMGR_ACTION_AT_EXIT from #{current_action.inspect} to #{new_action.inspect}") diff --git a/library/packages/src/modules/SignatureCheckCallbacks.rb b/library/packages/src/modules/SignatureCheckCallbacks.rb index bf499bcc2..6d06eef14 100644 --- a/library/packages/src/modules/SignatureCheckCallbacks.rb +++ b/library/packages/src/modules/SignatureCheckCallbacks.rb @@ -65,7 +65,7 @@ def AcceptUnsignedFile(filename, repo_id) dont_show_dialog_ident, filename ) - return SignatureCheckDialogs.UseUnsignedItem( + SignatureCheckDialogs.UseUnsignedItem( :file, filename, dont_show_dialog_ident, @@ -73,7 +73,7 @@ def AcceptUnsignedFile(filename, repo_id) ) # Return the default value entered by user else - return SignatureCheckDialogs.GetDefaultDialogReturn( + SignatureCheckDialogs.GetDefaultDialogReturn( dont_show_dialog_ident, filename ) @@ -100,14 +100,14 @@ def AcceptFileWithoutChecksum(filename) dont_show_dialog_ident, filename ) - return SignatureCheckDialogs.UseItemWithNoChecksum( + SignatureCheckDialogs.UseItemWithNoChecksum( :file, filename, dont_show_dialog_ident ) # Return the default value entered by user else - return SignatureCheckDialogs.GetDefaultDialogReturn( + SignatureCheckDialogs.GetDefaultDialogReturn( dont_show_dialog_ident, filename ) @@ -128,7 +128,7 @@ def AcceptWrongDigest(filename, requested_digest, found_digest) dont_show_dialog_ident, filename ) - return SignatureCheckDialogs.UseFileWithWrongDigest( + SignatureCheckDialogs.UseFileWithWrongDigest( filename, requested_digest, found_digest, @@ -136,7 +136,7 @@ def AcceptWrongDigest(filename, requested_digest, found_digest) ) else # Return the default value entered by user - return SignatureCheckDialogs.GetDefaultDialogReturn( + SignatureCheckDialogs.GetDefaultDialogReturn( dont_show_dialog_ident, filename ) @@ -158,14 +158,14 @@ def AcceptUnknownDigest(filename, digest) dont_show_dialog_ident, filename ) - return SignatureCheckDialogs.UseFileWithUnknownDigest( + SignatureCheckDialogs.UseFileWithUnknownDigest( filename, digest, dont_show_dialog_ident ) else # Return the default value entered by user - return SignatureCheckDialogs.GetDefaultDialogReturn( + SignatureCheckDialogs.GetDefaultDialogReturn( dont_show_dialog_ident, filename ) @@ -194,7 +194,7 @@ def AcceptUnknownGpgKey(filename, keyid, repoid) filename ) # Unknown keyname == "Unknown Key" - return SignatureCheckDialogs.ItemSignedWithUnknownSignature( + SignatureCheckDialogs.ItemSignedWithUnknownSignature( :file, filename, keyid, @@ -203,7 +203,7 @@ def AcceptUnknownGpgKey(filename, keyid, repoid) ) # Return the default value entered by user else - return SignatureCheckDialogs.GetDefaultDialogReturn( + SignatureCheckDialogs.GetDefaultDialogReturn( dont_show_dialog_ident, filename ) diff --git a/library/packages/src/modules/SignatureCheckDialogs.rb b/library/packages/src/modules/SignatureCheckDialogs.rb index 8f5e2b620..d1450cd97 100644 --- a/library/packages/src/modules/SignatureCheckDialogs.rb +++ b/library/packages/src/modules/SignatureCheckDialogs.rb @@ -259,12 +259,12 @@ def UseUnsignedItem(item_type, item_name, dont_show_dialog_ident, repository) # %3 is URL of the repository _( "The package %1 from repository %2\n" \ - "%3\n" \ - "is not digitally signed. This means that the origin\n" \ - "and integrity of the package cannot be verified. Installing the package\n" \ - "may put the integrity of your system at risk.\n" \ - "\n" \ - "Install it anyway?" + "%3\n" \ + "is not digitally signed. This means that the origin\n" \ + "and integrity of the package cannot be verified. Installing the package\n" \ + "may put the integrity of your system at risk.\n" \ + "\n" \ + "Install it anyway?" ) else item_name = strip_download_prefix(item_name) @@ -273,12 +273,12 @@ def UseUnsignedItem(item_type, item_name, dont_show_dialog_ident, repository) # %3 is URL of the repository _( "The file %1 from repository %2\n" \ - "%3\n" \ - "is not digitally signed. The origin and integrity of the file\n" \ - "cannot be verified. Using the file anyway puts the integrity of your \n" \ - "system at risk.\n" \ - "\n" \ - "Use it anyway?\n" + "%3\n" \ + "is not digitally signed. The origin and integrity of the file\n" \ + "cannot be verified. Using the file anyway puts the integrity of your \n" \ + "system at risk.\n" \ + "\n" \ + "Use it anyway?\n" ) end, item_name, @@ -341,22 +341,22 @@ def UseItemWithNoChecksum(item_type, item_name, dont_show_dialog_ident) # popup question, %1 stands for the package name _( "No checksum for package %1 was found in the repository.\n" \ - "While the package is part of the signed repository, it is not contained \n" \ - "in the list of checksums in this repository. Installing the package puts \n" \ - "the integrity of your system at risk.\n" \ - "\n" \ - "Install it anyway?\n" + "While the package is part of the signed repository, it is not contained \n" \ + "in the list of checksums in this repository. Installing the package puts \n" \ + "the integrity of your system at risk.\n" \ + "\n" \ + "Install it anyway?\n" ) else item_name = strip_download_prefix(item_name) # popup question, %1 stands for the filename _( "No checksum for file %1 was found in the repository.\n" \ - "This means that the file is part of the signed repository,\n" \ - "but the list of checksums in this repository does not mention this file. Using the file\n" \ - "may put the integrity of your system at risk.\n" \ - "\n" \ - "Use it anyway?" + "This means that the file is part of the signed repository,\n" \ + "but the list of checksums in this repository does not mention this file. Using the file\n" \ + "may put the integrity of your system at risk.\n" \ + "\n" \ + "Use it anyway?" ) end, item_name @@ -415,28 +415,28 @@ def UseCorruptedItem(item_type, item_name, key, repository) # popup question, %1 stands for the package name, %2 for the complete description of the GnuPG key (multiline) _( "Package %1 from repository %2\n" \ - "%3\n" \ - "is signed with the following GnuPG key, but the integrity check failed: %4\n" \ - "\n" \ - "The package has been changed, either by accident or by an attacker,\n" \ - "since the repository creator signed it. Installing it is a big risk\n" \ - "for the integrity and security of your system.\n" \ - "\n" \ - "Install it anyway?\n" + "%3\n" \ + "is signed with the following GnuPG key, but the integrity check failed: %4\n" \ + "\n" \ + "The package has been changed, either by accident or by an attacker,\n" \ + "since the repository creator signed it. Installing it is a big risk\n" \ + "for the integrity and security of your system.\n" \ + "\n" \ + "Install it anyway?\n" ) else item_name = strip_download_prefix(item_name) # popup question, %1 stands for the filename, %2 for the complete description of the GnuPG key (multiline) _( "File %1 from repository %2\n" \ - "%3\n" \ - "is signed with the following GnuPG key, but the integrity check failed: %4\n" \ - "\n" \ - "The file has been changed, either by accident or by an attacker,\n" \ - "since the repository creator signed it. Using it is a big risk\n" \ - "for the integrity and security of your system.\n" \ - "\n" \ - "Use it anyway?\n" + "%3\n" \ + "is signed with the following GnuPG key, but the integrity check failed: %4\n" \ + "\n" \ + "The file has been changed, either by accident or by an attacker,\n" \ + "since the repository creator signed it. Using it is a big risk\n" \ + "for the integrity and security of your system.\n" \ + "\n" \ + "Use it anyway?\n" ) end, item_name, @@ -478,33 +478,33 @@ def ItemSignedWithUnknownSignature(item_type, item_name, key_id, dont_show_dialo # popup question, %1 stands for the package name, %2 for the complex multiline description of the GnuPG key _( "The package %1 is digitally signed\n" \ - "with the following unknown GnuPG key: %2.\n" \ - "\n" \ - "This means that a trust relationship to the creator of the package\n" \ - "cannot be established. Installing the package may put the integrity\n" \ - "of your system at risk.\n" \ - "\n" \ - "Install it anyway?" + "with the following unknown GnuPG key: %2.\n" \ + "\n" \ + "This means that a trust relationship to the creator of the package\n" \ + "cannot be established. Installing the package may put the integrity\n" \ + "of your system at risk.\n" \ + "\n" \ + "Install it anyway?" ) else item_name = strip_download_prefix(item_name) # popup question, %1 stands for the filename, %2 for the complex multiline description of the GnuPG key _( "The file %1\n" \ - "is digitally signed with the following unknown GnuPG key: %2.\n" \ - "\n" \ - "This means that a trust relationship to the creator of the file\n" \ - "cannot be established. Using the file may put the integrity\n" \ - "of your system at risk.\n" \ - "\n" \ - "Use it anyway?" + "is digitally signed with the following unknown GnuPG key: %2.\n" \ + "\n" \ + "This means that a trust relationship to the creator of the file\n" \ + "cannot be established. Using the file may put the integrity\n" \ + "of your system at risk.\n" \ + "\n" \ + "Use it anyway?" ) end, # TODO: use something like "%1 from %2" and make it translatable - if repo_url != "" - Builtins.sformat("%1 (%2)", item_name, repo_url) - else + if repo_url == "" item_name + else + Builtins.sformat("%1 (%2)", item_name, repo_url) end, Ops.add( "\n", @@ -567,28 +567,28 @@ def ItemSignedWithPublicSignature(item_type, item_name, key) # popup question, %1 stands for the package name, %2 for the key ID, %3 for the key name _( "The package %1 is digitally signed\n" \ - "with key '%2 (%3)'.\n" \ - "\n" \ - "There is no trust relationship with the owner of the key.\n" \ - "If you trust the owner, mark the key as trusted.\n" \ - "\n" \ - "Installing a package from an unknown repository puts\n" \ - "the integrity of your system at risk. It is safest\n" \ - "to skip the package.\n" + "with key '%2 (%3)'.\n" \ + "\n" \ + "There is no trust relationship with the owner of the key.\n" \ + "If you trust the owner, mark the key as trusted.\n" \ + "\n" \ + "Installing a package from an unknown repository puts\n" \ + "the integrity of your system at risk. It is safest\n" \ + "to skip the package.\n" ) else item_name = strip_download_prefix(item_name) # popup question, %1 stands for the filename, %2 for the key ID, %3 for the key name _( "The file %1 is digitally signed\n" \ - "with key '%2 (%3)'.\n" \ - "\n" \ - "There is no trust relationship with the owner of the key.\n" \ - "If you trust the owner, mark the key as trusted.\n" \ - "\n" \ - "Installing a file from an unknown repository puts\n" \ - "the integrity of your system at risk. It is safest\n" \ - "to skip it.\n" + "with key '%2 (%3)'.\n" \ + "\n" \ + "There is no trust relationship with the owner of the key.\n" \ + "If you trust the owner, mark the key as trusted.\n" \ + "\n" \ + "Installing a file from an unknown repository puts\n" \ + "the integrity of your system at risk. It is safest\n" \ + "to skip it.\n" ) end, item_name, @@ -642,16 +642,16 @@ def ImportGPGKeyIntoTrustedDialog(key, repository) # additional Richtext (HTML) warning text (kind of help), 1/2 warning_text = _( "

The owner of the key may distribute updates,\n" \ - "packages, and package repositories that your system will trust and offer\n" \ - "for installation and update without any further warning. In this way,\n" \ - "importing the key into your keyring of trusted keys allows the key owner\n" \ - "to have a certain amount of control over the software on your system.

" + "packages, and package repositories that your system will trust and offer\n" \ + "for installation and update without any further warning. In this way,\n" \ + "importing the key into your keyring of trusted keys allows the key owner\n" \ + "to have a certain amount of control over the software on your system.

" ) + # additional Richtext (HTML) warning text (kind of help), 2/2 _( "

A warning dialog opens for every package that\n" \ - "is not signed by a trusted (imported) key. If you do not trust the key,\n" \ - "the packages or repositories created by the owner of the key will not be used.

" + "is not signed by a trusted (imported) key. If you do not trust the key,\n" \ + "the packages or repositories created by the owner of the key will not be used.

" ) repo = Pkg.SourceGeneralData(repository) @@ -660,8 +660,8 @@ def ImportGPGKeyIntoTrustedDialog(key, repository) dialog_text = Builtins.sformat( _( "The following GnuPG key has been found in repository\n" \ - "%1\n" \ - "(%2):" + "%1\n" \ + "(%2):" ), Ops.get_locale(repo, "name", _("Unknown")), (repo && repo["url"]) ? repo["url"].scan(/.{1,59}/).join("\n") : _("Unknown") @@ -670,9 +670,9 @@ def ImportGPGKeyIntoTrustedDialog(key, repository) # popup message - label, part 2 dialog_text2 = _( "You can choose to import it into your keyring of trusted\n" \ - "public keys, meaning that you trust the owner of the key.\n" \ - "You should be sure that you can trust the owner and that\n" \ - "the key really belongs to that owner before importing it." + "public keys, meaning that you trust the owner of the key.\n" \ + "You should be sure that you can trust the owner and that\n" \ + "the key really belongs to that owner before importing it." ) expires = Ops.get_integer(key, "expires_raw", 0) @@ -755,14 +755,14 @@ def UseFileWithWrongDigest(filename, requested_digest, found_digest, dont_show_d Builtins.sformat( _( "The expected checksum of file %1\n" \ - "is %2,\n" \ - "but the current checksum is %3.\n" \ - "\n" \ - "The file has been changed by accident or by an attacker\n" \ - "since the repository creator signed it. Using it is a big risk\n" \ - "for the integrity and security of your system.\n" \ - "\n" \ - "Use it anyway?\n" + "is %2,\n" \ + "but the current checksum is %3.\n" \ + "\n" \ + "The file has been changed by accident or by an attacker\n" \ + "since the repository creator signed it. Using it is a big risk\n" \ + "for the integrity and security of your system.\n" \ + "\n" \ + "Use it anyway?\n" ), filename, requested_digest, @@ -792,13 +792,13 @@ def UseFileWithUnknownDigest(filename, digest, dont_show_dialog_ident) Builtins.sformat( _( "The checksum of file %1\n" \ - "is %2,\n" \ - "but the expected checksum is not known.\n" \ - "\n" \ - "This means that the origin and integrity of the file\n" \ - "cannot be verified. Using the file puts the integrity of your system at risk.\n" \ - "\n" \ - "Use it anyway?\n" + "is %2,\n" \ + "but the expected checksum is not known.\n" \ + "\n" \ + "This means that the origin and integrity of the file\n" \ + "cannot be verified. Using the file puts the integrity of your system at risk.\n" \ + "\n" \ + "Use it anyway?\n" ), filename, digest @@ -944,15 +944,16 @@ def WaitForYesNoCancelUserInput loop do user_input = UI.UserInput # yes button - if user_input == :yes + case user_input + when :yes ret = true break # no button - elsif user_input == :no + when :no ret = false break # closing window uisng [x] - elsif user_input == :cancel + when :cancel ret = nil break else @@ -1017,7 +1018,9 @@ def GPGKeyAsString(key) # Part of the GnuPG key description in popup, %1 is a GnuPG key name Builtins.sformat(_("Name: %1"), Ops.get_string(key, "name", "")) ), - if Ops.get_string(key, "created", "") != "" + if Ops.get_string(key, "created", "") == "" + "" + else Ops.add( "\n", Builtins.sformat( @@ -1025,11 +1028,11 @@ def GPGKeyAsString(key) Ops.get_string(key, "created", "") ) ) - else - "" end ), - if Ops.get_string(key, "expires", "") != "" + if Ops.get_string(key, "expires", "") == "" + "" + else Ops.add( "\n", Builtins.sformat( @@ -1037,8 +1040,6 @@ def GPGKeyAsString(key) Ops.get_string(key, "expires", "") ) ) - else - "" end ) end diff --git a/library/packages/src/modules/SlideShow.rb b/library/packages/src/modules/SlideShow.rb index 83efb368a..2b5c010e3 100644 --- a/library/packages/src/modules/SlideShow.rb +++ b/library/packages/src/modules/SlideShow.rb @@ -631,12 +631,10 @@ def SwitchToReleaseNotesView(id) # Help text for the dialog def HelpText # Help text while software packages are being installed (displayed only in rare cases) - help_text = _("

Packages are being installed.

") + + _("

Packages are being installed.

") + _( "

Aborting Installation Package installation can be aborted using the Abort button. However, the system then can be in an inconsistent or unusable state or it may not boot if the basic system component is not installed.

" ) - - help_text end # set the release notes for slide show @@ -825,7 +823,7 @@ def HandleInput(button) @user_switched_to = :release_notes SwitchToReleaseNotesView(button) end - # note: `abort is handled in SlideShowCallbacks::HandleInput() + # NOTE: `abort is handled in SlideShowCallbacks::HandleInput() nil end @@ -1025,7 +1023,7 @@ def Setup(stages) new_size = 100 - total_size + updated_stage["size"] log.info "Updating '#{updated_stage_name}' stage size from " \ - "#{updated_stage["size"]}% to #{new_size}%" + "#{updated_stage["size"]}% to #{new_size}%" updated_stage["size"] = new_size @_stages[updated_stage_name] = updated_stage diff --git a/library/packages/src/modules/Slides.rb b/library/packages/src/modules/Slides.rb index e21877da1..7ec87e30c 100644 --- a/library/packages/src/modules/Slides.rb +++ b/library/packages/src/modules/Slides.rb @@ -140,9 +140,9 @@ def HaveSlideSupport Ops.greater_or_equal(Ops.get_integer(disp, "DefaultWidth", -1), 800) && Ops.greater_or_equal(Ops.get_integer(disp, "DefaultHeight", -1), 600) && Ops.greater_or_equal(Ops.get_integer(disp, "Depth", -1), 8) - return true + true else - return false + false end end diff --git a/library/packages/test/dummy_callbacks_test.rb b/library/packages/test/dummy_callbacks_test.rb index 7949ad4af..1cceea665 100755 --- a/library/packages/test/dummy_callbacks_test.rb +++ b/library/packages/test/dummy_callbacks_test.rb @@ -6,7 +6,7 @@ class FakePkg class << self - def method_missing(_met, *args, &_block) # rubocop:disable Style/MethodMissingSuper + def method_missing(_met, *args, &_block) signature = args.first.signature args_count = signature.include?("()") ? 0 : (signature.count(",") + 1) diff --git a/library/packages/test/file_conflict_callbacks_test.rb b/library/packages/test/file_conflict_callbacks_test.rb index 0750d8897..bd889488e 100755 --- a/library/packages/test/file_conflict_callbacks_test.rb +++ b/library/packages/test/file_conflict_callbacks_test.rb @@ -109,8 +109,7 @@ def CallbackFileConflictFinish(func) ].freeze MOCK_METHODS.each do |method| - # mock empty methods with a single argument - define_method(method) { |arg| } + define_method(method) { |arg| } # mock empty methods with a single argument end end diff --git a/library/packages/test/product_factory.rb b/library/packages/test/product_factory.rb index ef6343ce0..fc269fd55 100644 --- a/library/packages/test/product_factory.rb +++ b/library/packages/test/product_factory.rb @@ -53,7 +53,7 @@ def self.create_product(attrs = {}) product["register_target"] = attrs["register_target"] || "sle-12-x86_64" product["relnotes_url"] = attrs["relnotes_url"] || "https://www.suse.com/releasenotes/#{product["arch"]}/SLE-#{product_id}/12-SP#{sp}/" \ - "release-notes-#{product_id}.rpm" + "release-notes-#{product_id}.rpm" product["relnotes_urls"] = attrs["relnotes_urls"] || [product["relnotes_url"]] product["short_name"] = attrs["short_name"] || "SLE#{product_id.upcase}12-SP#{sp}" product["source"] = attrs["source"] || rand(10) @@ -85,13 +85,13 @@ def self.create_product_packages(product_name: "product", src: nil) package_name = "#{product_name}-release" package = Y2Packager::Resolvable.new( "kind" => :package, - "name" => package_name, "status" => :selected, - "deps" => [{ "requires" => "foo" }, { "provides" => "bar" }, - { "provides" => "defaultpattern(#{pattern_name})" }] + "name" => package_name, "status" => :selected, + "deps" => [{ "requires" => "foo" }, { "provides" => "bar" }, + { "provides" => "defaultpattern(#{pattern_name})" }] ) product = Y2Packager::Resolvable.new( ProductFactory.create_product("status" => :selected, - "source" => src, "product_package" => package_name) + "source" => src, "product_package" => package_name) ) [pattern_name, package_name, package, product] diff --git a/library/packages/test/test_helper.rb b/library/packages/test/test_helper.rb index bc51104da..180ca4377 100644 --- a/library/packages/test/test_helper.rb +++ b/library/packages/test/test_helper.rb @@ -1,4 +1,4 @@ -require_relative "../../../test/test_helper.rb" +require_relative "../../../test/test_helper" require "pathname" PACKAGES_FIXTURES_PATH = Pathname.new(File.dirname(__FILE__)).join("data") diff --git a/library/packages/test/y2packager/licenses_fetchers/rpm_test.rb b/library/packages/test/y2packager/licenses_fetchers/rpm_test.rb index 47a65fd2e..3ae5eafc7 100755 --- a/library/packages/test/y2packager/licenses_fetchers/rpm_test.rb +++ b/library/packages/test/y2packager/licenses_fetchers/rpm_test.rb @@ -31,7 +31,7 @@ def rpm_path_for(package) let(:package_name) { "sles-release" } let(:package_properties) do [Y2Packager::Resolvable.new(kind: :product, - name: "SLE_RT", status: :available, source: 2, product_package: package_name)] + name: "SLE_RT", status: :available, source: 2, product_package: package_name)] end let(:package_status) { :selected } let(:package_path) { rpm_path_for("licenses_test_package-0.1-0.noarch.rpm") } diff --git a/library/packages/test/y2packager/product_reader_test.rb b/library/packages/test/y2packager/product_reader_test.rb index 1179ebce8..3310024fd 100755 --- a/library/packages/test/y2packager/product_reader_test.rb +++ b/library/packages/test/y2packager/product_reader_test.rb @@ -150,9 +150,9 @@ .and_return(nil) allow(subject).to receive(:product_package).with("SLES_BCL-release") .and_return(Y2Packager::Resolvable.new("name" => "product_package", - "source" => 1, "version" => "1.0", "arch" => "x86_64", - "kind" => :package, "deps" => [{ "conflicts"=>"kernel < 4.4" }, - { "provides"=>"specialproduct(SLES_BCL)" }])) + "source" => 1, "version" => "1.0", "arch" => "x86_64", + "kind" => :package, "deps" => [{ "conflicts"=>"kernel < 4.4" }, + { "provides"=>"specialproduct(SLES_BCL)" }])) allow(Yast::Linuxrc).to receive(:InstallInf).with("specialproduct").and_return(nil) end diff --git a/library/packages/test/y2packager/product_test.rb b/library/packages/test/y2packager/product_test.rb index 7d9b466f6..8ff223c21 100755 --- a/library/packages/test/y2packager/product_test.rb +++ b/library/packages/test/y2packager/product_test.rb @@ -103,11 +103,11 @@ before do allow(Y2Packager::Resolvable).to receive(:find).with(name: product.name, kind: :product) .and_return([Y2Packager::Resolvable.new("kind" => :product, - "name" => product.name, "status" => status, - "source" => 1, "short_name" => "short_name", - "version" => "1.0", "arch" => "x86_64", "product_package" => "testpackage", - "display_name" => "display_name", "category" => "addon", - "vendor" => "SUSE LINUX Products GmbH, Nuernberg, Germany")]) + "name" => product.name, "status" => status, + "source" => 1, "short_name" => "short_name", + "version" => "1.0", "arch" => "x86_64", "product_package" => "testpackage", + "display_name" => "display_name", "category" => "addon", + "vendor" => "SUSE LINUX Products GmbH, Nuernberg, Germany")]) end context "if product was selected for installation" do @@ -131,11 +131,11 @@ before do allow(Y2Packager::Resolvable).to receive(:find).with(name: product.name, kind: :product) .and_return([Y2Packager::Resolvable.new("kind" => :product, - "name" => product.name, "status" => status, - "source" => 1, "short_name" => "short_name", - "version" => "1.0", "arch" => "x86_64", "product_package" => "testpackage", - "display_name" => "display_name", "category" => "addon", - "vendor" => "SUSE LINUX Products GmbH, Nuernberg, Germany")]) + "name" => product.name, "status" => status, + "source" => 1, "short_name" => "short_name", + "version" => "1.0", "arch" => "x86_64", "product_package" => "testpackage", + "display_name" => "display_name", "category" => "addon", + "vendor" => "SUSE LINUX Products GmbH, Nuernberg, Germany")]) end context "if product is installed" do @@ -406,12 +406,12 @@ allow(Y2Packager::Resolvable).to receive(:find).with(name: product.name, kind: :product, version: product.version) .and_return([Y2Packager::Resolvable.new("kind" => :product, - "name" => "openSUSE", "status" => :selected, - "source" => 1, "short_name" => "short_name", - "version" => product.version, "relnotes_url" => relnotes_url, - "arch" => "x86_64", "product_package" => "testpackage", - "display_name" => "display_name", "category" => "addon", - "vendor" => "SUSE LINUX Products GmbH, Nuernberg, Germany")]) + "name" => "openSUSE", "status" => :selected, + "source" => 1, "short_name" => "short_name", + "version" => product.version, "relnotes_url" => relnotes_url, + "arch" => "x86_64", "product_package" => "testpackage", + "display_name" => "display_name", "category" => "addon", + "vendor" => "SUSE LINUX Products GmbH, Nuernberg, Germany")]) end it "returns relnotes_url property" do diff --git a/library/packages/test/y2packager/release_notes_fetchers/url_test.rb b/library/packages/test/y2packager/release_notes_fetchers/url_test.rb index ef913967a..3c5489770 100755 --- a/library/packages/test/y2packager/release_notes_fetchers/url_test.rb +++ b/library/packages/test/y2packager/release_notes_fetchers/url_test.rb @@ -61,8 +61,8 @@ it "uses cURL to download release notes" do cmd = "/usr/bin/curl --location --verbose --fail --max-time 300 --connect-timeout 15 " \ - "'http://doc.opensuse.org/openSUSE/RELEASE-NOTES.de_DE.txt' --output '/tmp/relnotes' " \ - "> '/var/log/YaST2/curl_log' 2>&1" + "'http://doc.opensuse.org/openSUSE/RELEASE-NOTES.de_DE.txt' --output '/tmp/relnotes' " \ + "> '/var/log/YaST2/curl_log' 2>&1" expect(Yast::SCR).to receive(:Execute).with(Yast::Path.new(".target.bash"), cmd) fetcher.release_notes(prefs) diff --git a/library/sequencer/src/lib/ui/sequence.rb b/library/sequencer/src/lib/ui/sequence.rb index 6a2da5858..299bb1682 100644 --- a/library/sequencer/src/lib/ui/sequence.rb +++ b/library/sequencer/src/lib/ui/sequence.rb @@ -99,7 +99,7 @@ def self.run(aliases, sequence) # next: :finish # } # }) - def run(aliases: nil, sequence:) + def run(sequence:, aliases: nil) aliases ||= from_methods(sequence) self.class.run(aliases, abortable(sequence)) end diff --git a/library/sequencer/src/modules/Sequencer.rb b/library/sequencer/src/modules/Sequencer.rb index 4c2ad3629..694567b05 100644 --- a/library/sequencer/src/modules/Sequencer.rb +++ b/library/sequencer/src/modules/Sequencer.rb @@ -212,9 +212,7 @@ def WS_special(aliases, alias_) ) end ret = false - if Ops.is_list?(found) - ret = Ops.get_boolean(Convert.to_list(found), 1) if Ops.greater_than(Builtins.size(Convert.to_list(found)), 1) - end + ret = Ops.get_boolean(Convert.to_list(found), 1) if Ops.is_list?(found) && Ops.greater_than(Builtins.size(Convert.to_list(found)), 1) ret end diff --git a/library/sequencer/test/test_helper.rb b/library/sequencer/test/test_helper.rb index 08dc933d5..6affe9fe9 100644 --- a/library/sequencer/test/test_helper.rb +++ b/library/sequencer/test/test_helper.rb @@ -1 +1 @@ -require_relative "../../../test/test_helper.rb" +require_relative "../../../test/test_helper" diff --git a/library/system/src/lib/yast2/clients/view_anymsg.rb b/library/system/src/lib/yast2/clients/view_anymsg.rb index 8aba41b21..770ace6b5 100644 --- a/library/system/src/lib/yast2/clients/view_anymsg.rb +++ b/library/system/src/lib/yast2/clients/view_anymsg.rb @@ -138,15 +138,15 @@ def file_state(file) # def start_journal? case file_state(selected_filename) - when :ok then + when :ok false - when :empty then + when :empty Yast2::Popup.show(_("The selected log file is empty.")) false - when :no_file then + when :no_file Yast2::Popup.show(_("The selected item is not a file.")) false - when :no_access then + when :no_access Yast2::Popup.show( _( "You do not have permission to read the selected log file.\n\n" \ @@ -154,7 +154,7 @@ def start_journal? ) ) false - when :missing then + when :missing res = Yast2::Popup.show( _( "The selected log file does not exist.\n\n" \ diff --git a/library/system/src/lib/yast2/fs_snapshot.rb b/library/system/src/lib/yast2/fs_snapshot.rb index 31f234a9a..09f558089 100644 --- a/library/system/src/lib/yast2/fs_snapshot.rb +++ b/library/system/src/lib/yast2/fs_snapshot.rb @@ -76,7 +76,7 @@ class FsSnapshot "--columns config,subvolume | /usr/bin/grep \"^root,\" >/dev/null".freeze CREATE_SNAPSHOT_CMD = "/usr/bin/snapper --no-dbus --root=%{root} create "\ - "--type %{snapshot_type} --description %{description}".freeze + "--type %{snapshot_type} --description %{description}".freeze LIST_SNAPSHOTS_CMD = "/usr/bin/snapper --no-dbus --root=%{root} --utc --csvout list --disable-used-space " \ @@ -157,7 +157,7 @@ def configure_snapper @configured = nil - installation_helper_step_4 + installation_helper_step4 write_snapper_config update_etc_sysconfig_yast2 setup_snapper_quota @@ -192,10 +192,10 @@ def create_snapshot?(snapshot_type) if [:around, :single].include?(snapshot_type) return false if disable_snapshots.include?("all") - return !disable_snapshots.include?(snapshot_type.to_s) + !disable_snapshots.include?(snapshot_type.to_s) else raise ArgumentError, "Unsupported snapshot type #{snapshot_type.inspect}, " \ - "supported are :around and :single" + "supported are :around and :single" end end @@ -364,7 +364,7 @@ def target_root # Unfortunately the steps of the Snapper helper are not much descriptive. # The step 4 must be executed in the target system after installing the # packages and before using snapper for the first time. - def installation_helper_step_4 + def installation_helper_step4 Yast::Execute.on_target("/usr/lib/snapper/installation-helper", "--step", "4") end diff --git a/library/system/src/lib/yast2/ui_plugin_info.rb b/library/system/src/lib/yast2/ui_plugin_info.rb index 3e6190a22..459f05aa9 100644 --- a/library/system/src/lib/yast2/ui_plugin_info.rb +++ b/library/system/src/lib/yast2/ui_plugin_info.rb @@ -49,7 +49,7 @@ def initialize(maps_file = "/proc/self/maps") # def ui_plugins if @ui_plugins.nil? - @ui_plugins = shared_libs.select { |lib| lib =~ /yui\/libyui-/ } + @ui_plugins = shared_libs.grep(/yui\/libyui-/) log.info("UI plug-ins: #{@ui_plugins}") end @ui_plugins @@ -76,7 +76,7 @@ def short_name(ui_plugin) def main_ui_plugin_complete return nil if ui_plugins.empty? - relevant_plugins = ui_plugins.reject { |p| p =~ /rest-api/ } + relevant_plugins = ui_plugins.grep_v(/rest-api/) @main_ui_plugin_complete ||= relevant_plugins.min do |a, b| SharedLibInfo.lib_basename(a).size <=> SharedLibInfo.lib_basename(b).size end diff --git a/library/system/src/modules/FileChanges.rb b/library/system/src/modules/FileChanges.rb index 756657606..90f3a4e9d 100644 --- a/library/system/src/modules/FileChanges.rb +++ b/library/system/src/modules/FileChanges.rb @@ -96,10 +96,9 @@ def ComputeFileChecksum(file) # See also FileUtils::MD5sum() cmd = Builtins.sformat("/usr/bin/md5sum %1", file.shellescape) out = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd)) - # note: it also contains file name, but since it is only to be compared + # NOTE: it also contains file name, but since it is only to be compared # it does not matter - sum = Ops.get_string(out, "stdout", "") - sum + Ops.get_string(out, "stdout", "") end # Check if file was modified compared to the one distributed diff --git a/library/system/src/modules/Hotplug.rb b/library/system/src/modules/Hotplug.rb index d4f6d1b68..3ee30bece 100644 --- a/library/system/src/modules/Hotplug.rb +++ b/library/system/src/modules/Hotplug.rb @@ -116,9 +116,10 @@ def startController(controller) module_modprobe ) end - if load_result == :fail + case load_result + when :fail all_modules_loaded = false - elsif load_result == :dont + when :dont all_modules_loaded = true end # break out of module load loop if one module failed diff --git a/library/system/src/modules/HwStatus.rb b/library/system/src/modules/HwStatus.rb index 2eca39fa5..fd3bb1dd2 100644 --- a/library/system/src/modules/HwStatus.rb +++ b/library/system/src/modules/HwStatus.rb @@ -89,10 +89,10 @@ def Update "Command retval: %1", Ops.get_integer(cmdret, "exit", -1) ) - if exit != 0 - Builtins.y2error("Command output: %1", cmdret) - else + if exit == 0 Builtins.y2debug("Command output: %1", cmdret) + else + Builtins.y2error("Command output: %1", cmdret) end nil diff --git a/library/system/src/modules/Initrd.rb b/library/system/src/modules/Initrd.rb index 88c4ab6f5..750cca4dd 100644 --- a/library/system/src/modules/Initrd.rb +++ b/library/system/src/modules/Initrd.rb @@ -197,7 +197,7 @@ def ListModules # @param [String] modargs arguments to be passes to module def AddModule(modname, modargs) log.warn "Initrd.AddModule() is deprecated, do not use (sysconfig.kernel.INITRD_MODULES " \ - "is not written anymore, see bnc#895084)" + "is not written anymore, see bnc#895084)" if Stage.initial && Builtins.size(@modules) == 0 tmp_mods = Convert.to_string( @@ -209,33 +209,33 @@ def AddModule(modname, modargs) Read() end if !Builtins.contains(ListModules(), modname) || - modname == "aic7xxx" && - !Builtins.contains(ListModules(), "aic7xxx_old") || - modname == "aic7xxx_old" && - !Builtins.contains(ListModules(), "aic7xxx") - if !Builtins.contains(getModulesToSkip, modname) + (modname == "aic7xxx" && + !Builtins.contains(ListModules(), "aic7xxx_old")) || + (modname == "aic7xxx_old" && + !Builtins.contains(ListModules(), "aic7xxx")) + if Builtins.contains(getModulesToSkip, modname) + Builtins.y2milestone( + "Module %1 is in list of modules not to insert to initrd", + modname + ) + else @changed = true Ops.set(@modules_to_store, modname, true) Ops.set(@modules_settings, modname, Misc.SplitOptions(modargs, {})) - if !Builtins.contains(@modules, modname) - @modules = Builtins.add(@modules, modname) + if Builtins.contains(@modules, modname) Builtins.y2milestone( - "Module %1 added to initrd, now contains %2", + "Module %1 from initial list added to initrd, now contains %2", modname, ListModules() ) else + @modules = Builtins.add(@modules, modname) Builtins.y2milestone( - "Module %1 from initial list added to initrd, now contains %2", + "Module %1 added to initrd, now contains %2", modname, ListModules() ) end - else - Builtins.y2milestone( - "Module %1 is in list of modules not to insert to initrd", - modname - ) end else Builtins.y2milestone("Module %1 already present in initrd", modname) diff --git a/library/system/src/modules/Kernel.rb b/library/system/src/modules/Kernel.rb index 4f9d663d7..a25339290 100644 --- a/library/system/src/modules/Kernel.rb +++ b/library/system/src/modules/Kernel.rb @@ -120,7 +120,9 @@ def main def HidePasswords(in_) ret = "" - if !in_.nil? + if in_.nil? + ret = nil + else parts = Builtins.splitstring(in_, " ") first = true @@ -138,8 +140,6 @@ def HidePasswords(in_) end ret = Ops.add(ret, cmdopt) end - else - ret = nil end ret @@ -220,8 +220,8 @@ def IsGraphicalDesktop # # @return [void] def ProbeKernel - kernel_desktop_exists = (Mode.normal || Mode.repair) && - Pkg.PkgInstalled("kernel-desktop") || + kernel_desktop_exists = ((Mode.normal || Mode.repair) && + Pkg.PkgInstalled("kernel-desktop")) || Pkg.PkgAvailable("kernel-desktop") Builtins.y2milestone( "Desktop kernel available: %1", @@ -255,7 +255,7 @@ def ProbeKernel # bugzilla #303842 if cpuinfo_flags - cpuflags = cpuinfo_flags.empty? ? [] : cpuinfo_flags.split(" ") + cpuflags = cpuinfo_flags.empty? ? [] : cpuinfo_flags.split else Builtins.y2error("Cannot read cpuflags") Builtins.y2milestone( @@ -386,15 +386,15 @@ def ComputePackage end end - if the_kernel != "" - @final_kernel = the_kernel - else + if the_kernel == "" Builtins.y2warning( "%1 not available, using kernel-default", @kernel_packages ) @final_kernel = "kernel-default" + else + @final_kernel = the_kernel end @final_kernel end @@ -411,7 +411,7 @@ def GetFinalKernel # @return a list of all kernel packages (including the base package) that # are to be installed together with the base package def ComputePackagesForBase(base, _check_avail) - # Note: kernel-*-nongpl packages have been dropped, use base only + # NOTE: kernel-*-nongpl packages have been dropped, use base only ret = [base] Builtins.y2milestone("Packages for base %1: %2", base, ret) @@ -685,7 +685,7 @@ def params_to_discard(cmdlist) discardlist = [] # some systems (pseries) can autodetect the serial console if cmdlist.include?("AUTOCONSOLE") - # Note: `console` is the only value that depends on the input argument. + # NOTE: `console` is the only value that depends on the input argument. discardlist << "console" discardlist << "AUTOCONSOLE" end diff --git a/library/system/test/fs_snapshot_test.rb b/library/system/test/fs_snapshot_test.rb index fd943232e..a00463318 100755 --- a/library/system/test/fs_snapshot_test.rb +++ b/library/system/test/fs_snapshot_test.rb @@ -169,7 +169,7 @@ def logger describe ".create_single" do CREATE_SINGLE_SNAPSHOT = "/usr/bin/snapper --no-dbus "\ - "--root=/ create --type single --description some-description".freeze + "--root=/ create --type single --description some-description".freeze OPTION_CLEANUP_NUMBER = " --cleanup number".freeze OPTION_IMPORTANT = " --userdata \"important=yes\"".freeze @@ -262,7 +262,7 @@ def logger describe ".create_pre" do CREATE_PRE_SNAPSHOT = "/usr/bin/snapper --no-dbus "\ - "--root=/ create --type pre --description some-description".freeze + "--root=/ create --type pre --description some-description".freeze before do allow(Yast2::FsSnapshot).to receive(:configured?).and_return(configured) @@ -353,8 +353,8 @@ def logger describe ".create_post" do CREATE_POST_SNAPSHOT = "/usr/bin/snapper --no-dbus "\ - "--root=/ create --type post --description some-description "\ - "--pre-num 1".freeze + "--root=/ create --type post --description some-description "\ + "--pre-num 1".freeze before do allow(Yast2::FsSnapshot).to receive(:configured?).and_return(configured) @@ -469,7 +469,7 @@ def logger context "when an snapshot contains a wrong date" do let(:output) do "number,type,pre-number,date,user,cleanup,description\n" \ - "1,single,,bad-date,root,,\n" + "1,single,,bad-date,root,,\n" end it "sets timestamp to nil" do diff --git a/library/system/test/shared_lib_info_test.rb b/library/system/test/shared_lib_info_test.rb index e60b34d37..5ad169d48 100755 --- a/library/system/test/shared_lib_info_test.rb +++ b/library/system/test/shared_lib_info_test.rb @@ -29,7 +29,7 @@ def stored_proc_maps(scenario) end it "finds the Qt UI plug-in" do - ui_plugins = subject.shared_libs.select { |p| p =~ /yui\/libyui/ } + ui_plugins = subject.shared_libs.grep(/yui\/libyui/) expect(ui_plugins).to eq ["/usr/lib64/yui/libyui-qt.so.15.0.0"] end end @@ -38,7 +38,7 @@ def stored_proc_maps(scenario) let(:maps_file) { stored_proc_maps("qt-pkg") } it "finds the Qt UI plug-in and the Qt-Pkg plug-in" do - ui_plugins = subject.shared_libs.select { |p| p =~ /yui\/libyui/ } + ui_plugins = subject.shared_libs.grep(/yui\/libyui/) expect(ui_plugins).to eq ["/usr/lib64/yui/libyui-qt-pkg.so.15.0.0", "/usr/lib64/yui/libyui-qt.so.15.0.0"] end end diff --git a/library/system/test/test_helper.rb b/library/system/test/test_helper.rb index 08dc933d5..6affe9fe9 100644 --- a/library/system/test/test_helper.rb +++ b/library/system/test/test_helper.rb @@ -1 +1 @@ -require_relative "../../../test/test_helper.rb" +require_relative "../../../test/test_helper" diff --git a/library/systemd/src/lib/yast2/compound_service.rb b/library/systemd/src/lib/yast2/compound_service.rb index 01e77d569..1db337db6 100644 --- a/library/systemd/src/lib/yast2/compound_service.rb +++ b/library/systemd/src/lib/yast2/compound_service.rb @@ -177,9 +177,10 @@ def start_mode def start_mode=(configuration) raise ArgumentError, "Invalid parameter #{configuration.inspect}" if !AUTOSTART_OPTIONS.include?(configuration) - if configuration == :inconsistent + case configuration + when :inconsistent reset(exclude: [:action]) - elsif configuration == :on_demand + when :on_demand services_with_socket.each { |s| s.start_mode = :on_demand } services_without_socket.each { |s| s.start_mode = :on_boot } else diff --git a/library/systemd/src/lib/yast2/service_widget.rb b/library/systemd/src/lib/yast2/service_widget.rb index 804a25604..3119b7444 100644 --- a/library/systemd/src/lib/yast2/service_widget.rb +++ b/library/systemd/src/lib/yast2/service_widget.rb @@ -283,10 +283,10 @@ def action_label(value) # @see valid_action? # @param value [Symbol] def selected_item?(value) - if !valid_action?(current_action) - value == :nothing - else + if valid_action?(current_action) current_action == value + else + value == :nothing end end diff --git a/library/systemd/src/modules/Service.rb b/library/systemd/src/modules/Service.rb index dac3ad76a..6a0f7fa77 100644 --- a/library/systemd/src/modules/Service.rb +++ b/library/systemd/src/modules/Service.rb @@ -46,6 +46,8 @@ class ServiceClass < Module attr_reader :error def initialize + super + textdomain "base" @error = "" end @@ -275,7 +277,7 @@ def Status(name) unit = Yast2::Systemd::Service.find(name) failure(:not_found, name) unless unit - (unit&.active?) ? 0 : -1 + unit&.active? ? 0 : -1 end # @deprecated Not supported by systemd @@ -408,12 +410,12 @@ def RunInitScriptOutput(name, param) deprecate("use `start` or `stop` instead") service = Yast2::Systemd::Service.find(name) - if !service - failure(:not_found, name) - success = false - else + if service success = service.send(param) self.error = service.error + else + failure(:not_found, name) + success = false end { "stdout" => "", "stderr" => error, "exit" => success ? 0 : 1 } end diff --git a/library/systemd/src/modules/ServicesProposal.rb b/library/systemd/src/modules/ServicesProposal.rb index 75935fb86..ccf76a67d 100644 --- a/library/systemd/src/modules/ServicesProposal.rb +++ b/library/systemd/src/modules/ServicesProposal.rb @@ -34,6 +34,8 @@ class ServicesProposalClass < Module include Yast::Logger def initialize + super + @services = {} end diff --git a/library/systemd/test/test_helper.rb b/library/systemd/test/test_helper.rb index 1f20f3835..29fe2003f 100644 --- a/library/systemd/test/test_helper.rb +++ b/library/systemd/test/test_helper.rb @@ -1,4 +1,4 @@ -require_relative "../../../test/test_helper.rb" +require_relative "../../../test/test_helper" require "yast2/systemd/unit" require "yast2/systemd/unit_properties" diff --git a/library/systemd/test/yast2/compound_service_test.rb b/library/systemd/test/yast2/compound_service_test.rb index 25f4f6fa1..1bb3f03db 100755 --- a/library/systemd/test/yast2/compound_service_test.rb +++ b/library/systemd/test/yast2/compound_service_test.rb @@ -25,7 +25,7 @@ describe Yast2::CompoundService do def service(*args) args[0] ||= {} - args[0][:"is_a?"] = true + args[0][:is_a?] = true args[0][:errors] = {} double("Yast2::SystemService", *args).as_null_object end diff --git a/library/types/src/modules/Hostname.rb b/library/types/src/modules/Hostname.rb index e575b5cae..7de088c6b 100644 --- a/library/types/src/modules/Hostname.rb +++ b/library/types/src/modules/Hostname.rb @@ -53,8 +53,8 @@ def ValidDomain # Translators: dot: ".", hyphen: "-" _( "A valid domain name consists of components separated by dots.\n" \ - "Each component contains letters, digits, and hyphens. A hyphen may not\n" \ - "start or end a component and the last component may not begin with a digit." + "Each component contains letters, digits, and hyphens. A hyphen may not\n" \ + "start or end a component and the last component may not begin with a digit." ) end @@ -91,14 +91,12 @@ def CheckDomain(domain) return false if domain.nil? || domain == "" # if "domain" contains "." character as last character remove it before validation (but it's valid) - if Ops.greater_than(Builtins.size(domain), 1) - if Builtins.substring(domain, Ops.subtract(Builtins.size(domain), 1), 1) == "." - domain = Builtins.substring( - domain, - 0, - Ops.subtract(Builtins.size(domain), 1) - ) - end + if Ops.greater_than(Builtins.size(domain), 1) && (Builtins.substring(domain, Ops.subtract(Builtins.size(domain), 1), 1) == ".") + domain = Builtins.substring( + domain, + 0, + Ops.subtract(Builtins.size(domain), 1) + ) end l = Builtins.splitstring(domain, ".") return false if Builtins.contains(Builtins.maplist(l) { |h| Check(h) }, false) @@ -131,11 +129,11 @@ def SplitFQ(fqhostname) dn = "" dot = Builtins.findfirstof(fqhostname, ".") - if !dot.nil? + if dot.nil? + hn = fqhostname + else hn = Builtins.substring(fqhostname, 0, dot) dn = Builtins.substring(fqhostname, Ops.add(dot, 1)) - else - hn = fqhostname end [hn, dn] @@ -157,13 +155,13 @@ def MergeFQ(hostname, domain) def CurrentFQ hostname_data = SCR.Execute(path(".target.bash_output"), "/usr/bin/hostname --fqdn") - if hostname_data["exit"] != 0 + if hostname_data["exit"] == 0 + fqhostname = hostname_data["stdout"] + else Builtins.y2warning("Using fallback hostname") fqhostname = SCR.Read(path(".target.string"), "/etc/hostname") || "" fqhostname = "linux.#{@DefaultDomain}" if fqhostname.empty? - else - fqhostname = hostname_data["stdout"] end fqhostname = String.FirstChunk(fqhostname, "\n") diff --git a/library/types/src/modules/IP.rb b/library/types/src/modules/IP.rb index 2e1e8e7f4..9d766aec8 100644 --- a/library/types/src/modules/IP.rb +++ b/library/types/src/modules/IP.rb @@ -71,8 +71,8 @@ def Valid6 # Translators: colon: ":" _( "A valid IPv6 address consists of up to eight\n" \ - "hexadecimal numbers in the range 0 - FFFF separated by colons.\n" \ - "It can contain up to one double colon." + "hexadecimal numbers in the range 0 - FFFF separated by colons.\n" \ + "It can contain up to one double colon." ) end @@ -125,12 +125,12 @@ def ValidNetwork # TRANSLATORS: description of the valid network definition _( "A valid network definition can contain the IP,\n" \ - "IP/Netmask, IP/Netmask_Bits, or 0/0 for all networks.\n" \ - "\n" \ - "Examples:\n" \ - "IP: 192.168.0.1 or 2001:db8:0::1\n" \ - "IP/Netmask: 192.168.0.0/255.255.255.0 or 2001:db8:0::1/56\n" \ - "IP/Netmask_Bits: 192.168.0.0/24 or 192.168.0.1/32 or 2001:db8:0::1/ffff::0\n" + "IP/Netmask, IP/Netmask_Bits, or 0/0 for all networks.\n" \ + "\n" \ + "Examples:\n" \ + "IP: 192.168.0.1 or 2001:db8:0::1\n" \ + "IP/Netmask: 192.168.0.0/255.255.255.0 or 2001:db8:0::1/56\n" \ + "IP/Netmask_Bits: 192.168.0.0/24 or 192.168.0.1/32 or 2001:db8:0::1/ffff::0\n" ) end diff --git a/library/types/src/modules/Netmask.rb b/library/types/src/modules/Netmask.rb index 8fc1c7f6c..fd9ce5700 100644 --- a/library/types/src/modules/Netmask.rb +++ b/library/types/src/modules/Netmask.rb @@ -138,10 +138,10 @@ def FromBits(bits) Ops.add( Ops.add( Ops.get_string(l, b, ""), - if d != 0 - Ops.add(Ops.get_string(m, d, ""), (b != 3) ? "." : "") - else + if d == 0 "" + else + Ops.add(Ops.get_string(m, d, ""), (b != 3) ? "." : "") end ), Ops.get_string(r, (d == 0) ? b : Ops.add(b, 1), "") diff --git a/library/types/src/modules/Punycode.rb b/library/types/src/modules/Punycode.rb index 79d9a4aa2..5e3523440 100644 --- a/library/types/src/modules/Punycode.rb +++ b/library/types/src/modules/Punycode.rb @@ -72,10 +72,10 @@ def GetMaximumCacheSize # @param [Fixnum] new_max_size # @see #GetMaximumCacheSize() def SetMaximumCacheSize(new_max_size) - if !new_max_size.nil? - @maximum_cache_size = new_max_size - else + if new_max_size.nil? Builtins.y2error("Cannot set MaximumCacheSize to nil!") + else + @maximum_cache_size = new_max_size end nil @@ -211,7 +211,7 @@ def ConvertBackAndForth(strings_in, to_punycode) all << test_cached[string_in] else # Recently converted strings found_index += 1 - all << converted_not_cached[found_index] || "" + (all << converted_not_cached[found_index]) || "" # Adding converted strings to cache if to_punycode diff --git a/library/types/src/modules/RichText.rb b/library/types/src/modules/RichText.rb index 708e1cb30..4f97dc37e 100644 --- a/library/types/src/modules/RichText.rb +++ b/library/types/src/modules/RichText.rb @@ -62,27 +62,20 @@ def Rich2Plain(richtext) tag = Builtins.tolower(Builtins.substring(lpart, 0, s)) # *** Handle tags **** - # BR - if tag == "br" + case tag + when "br", "p" result = Ops.add(result, "\n") - # P - elsif tag == "p" - result = Ops.add(result, "\n") - # UL - elsif tag == "ul" + when "ul" inli = true indents = Ops.add(indents, 1) - # /UL - elsif tag == "/ul" + when "/ul" result = Ops.add(result, "\n") if inli && indents == 1 indents = Ops.subtract(indents, 1) inli = false - # LI - elsif tag == "li" + when "li" result = Ops.add(result, "\n") if inli inli = true - # /LI - elsif tag == "/li" + when "/li" inli = false result = Ops.add(result, "\n") end diff --git a/library/types/src/modules/String.rb b/library/types/src/modules/String.rb index 503e3b3c7..86f749145 100644 --- a/library/types/src/modules/String.rb +++ b/library/types/src/modules/String.rb @@ -231,7 +231,7 @@ def FormatTime(seconds) return "" if seconds < 0 if seconds < 3600 # Less than one hour - return Builtins.sformat( + Builtins.sformat( "%1:%2", FormatTwoDigits(seconds / 60), FormatTwoDigits(seconds % 60) @@ -239,7 +239,7 @@ def FormatTime(seconds) else hours = seconds / 3600 seconds = seconds % 3600 - return Builtins.sformat( + Builtins.sformat( "%1:%2:%3", hours, FormatTwoDigits(seconds / 60), @@ -417,9 +417,10 @@ def ParseOptions(options, parameters) end end - if state == :out_of_string + case state + when :out_of_string # ignore separator or white space at the beginning of the string - if separator.include?(character) || remove_whitespace && character =~ /[ \t]/ + if separator.include?(character) || (remove_whitespace && character =~ /[ \t]/) index += 1 next # start of a quoted string @@ -432,7 +433,7 @@ def ParseOptions(options, parameters) str = (character == "\\\"") ? "\"" : character end # after double quoted string - handle non-separator chars after double quote - elsif state == :in_quoted_string_after_dblqt + when :in_quoted_string_after_dblqt if separator.include?(character) ret << str if !unique || !Builtins.contains(ret, str) @@ -443,16 +444,17 @@ def ParseOptions(options, parameters) else str << character end - elsif state == :in_quoted_string - if character == "\"" + when :in_quoted_string + case character + when "\"" # end of quoted string state = :in_quoted_string_after_dblqt - elsif character == "\\\"" + when "\\\"" str << "\"" else str << character end - elsif state == :in_string + when :in_string if separator.include?(character) state = :out_of_string @@ -688,7 +690,7 @@ def Random(len) digits = DIGIT_CHARS + LOWER_CHARS # uses the character classes from above ret = Array.new(len) { digits[rand(digits.size)] } - ret.join("") + ret.join end # Format file name - truncate the middle part of the directory to fit to the reqested lenght. diff --git a/library/types/src/modules/URL.rb b/library/types/src/modules/URL.rb index 1fa9ae6a1..55fb968ca 100644 --- a/library/types/src/modules/URL.rb +++ b/library/types/src/modules/URL.rb @@ -126,9 +126,7 @@ def UnEscapeString(in_, transform) end # replace % at the end - in_ = String.Replace(in_, "%25", "%") - - in_ + String.Replace(in_, "%25", "%") end # Escape reserved characters in string used as a part of URL (e.g. '%' => '%25', '@' => '%40'...) @@ -187,11 +185,11 @@ def Parse(url) # 4,5: ?question # 6,7: #fragment "^" \ - "(([^:/?#]+):[/]{0,2})?" \ - "([^/?#]*)?" \ - "([^?#]*)?" \ - "(\\?([^#]*))?" \ - "(#(.*))?" + "(([^:/?#]+):[/]{0,2})?" \ + "([^/?#]*)?" \ + "([^?#]*)?" \ + "(\\?([^#]*))?" \ + "(#(.*))?" ) Builtins.y2debug("rawtokens=%1", rawtokens) tokens = {} @@ -224,9 +222,9 @@ def Parse(url) # FIXME: "(([^:@]+)|(\\[([^]]+)\\]))" + # 8,9: port "^" \ - "(([^@:]+)(:([^@:]+))?@)?" \ - "(([^:@]+))" \ - "(:([^:@]+))?" + "(([^@:]+)(:([^@:]+))?@)?" \ + "(([^:@]+))" \ + "(:([^:@]+))?" ) Builtins.y2debug("userpass=%1", userpass) @@ -242,10 +240,10 @@ def Parse(url) ) Ops.set(tokens, "port", Ops.get_string(userpass, 7, "")) - if Ops.get_string(userpass, 5, "") != "" - Ops.set(tokens, "host", Ops.get_string(userpass, 5, "")) - else + if Ops.get_string(userpass, 5, "") == "" Ops.set(tokens, "host", Ops.get_string(userpass, 7, "")) + else + Ops.set(tokens, "host", Ops.get_string(userpass, 5, "")) end hostport6 = Builtins.substring( @@ -268,7 +266,7 @@ def Parse(url) # some exceptions for samba scheme (there is optional extra option "domain") if Ops.get_string(tokens, "scheme", "") == "samba" || Ops.get_string(tokens, "scheme", "") == "smb" - # Note: CUPS uses different URL syntax for Samba printers: + # NOTE: CUPS uses different URL syntax for Samba printers: # smb://username:password@workgroup/server/printer # Fortunately yast2-printer does not use URL.ycp, so we can safely support libzypp syntax only: # smb://username:passwd@servername/share/path/on/the/share?workgroup=mygroup diff --git a/library/types/test/test_helper.rb b/library/types/test/test_helper.rb index 08dc933d5..6affe9fe9 100644 --- a/library/types/test/test_helper.rb +++ b/library/types/test/test_helper.rb @@ -1 +1 @@ -require_relative "../../../test/test_helper.rb" +require_relative "../../../test/test_helper" diff --git a/library/types/test/url_test.rb b/library/types/test/url_test.rb index bb1e89fcc..41d84bb93 100755 --- a/library/types/test/url_test.rb +++ b/library/types/test/url_test.rb @@ -152,41 +152,41 @@ it "returns valid URL string" do expect(subject.Build("scheme" => "ftp", - "host" => "ftp.example.com", - "path" => "path/to/dir")).to eq( + "host" => "ftp.example.com", + "path" => "path/to/dir")).to eq( "ftp://ftp.example.com/path/to/dir" ) end it "returns URL string with escaped leading / in the path" do expect(subject.Build("scheme" => "ftp", - "host" => "ftp.example.com", - "path" => "/path/to/dir")).to eq( + "host" => "ftp.example.com", + "path" => "/path/to/dir")).to eq( "ftp://ftp.example.com/%2fpath/to/dir" ) end it "returns URL string with escaped leading // in the path" do expect(subject.Build("scheme" => "ftp", - "host" => "ftp.example.com", - "path" => "//path/to/dir")).to eq( + "host" => "ftp.example.com", + "path" => "//path/to/dir")).to eq( "ftp://ftp.example.com/%2fpath/to/dir" ) end it "returns URL string with escaped leading /// in the path" do expect(subject.Build("scheme" => "ftp", - "host" => "ftp.example.com", - "path" => "///path/to/dir")).to eq( + "host" => "ftp.example.com", + "path" => "///path/to/dir")).to eq( "ftp://ftp.example.com/%2fpath/to/dir" ) end it "returns URL string with escaped leading /// in the path and params" do expect(subject.Build("scheme" => "ftp", - "host" => "ftp.example.com", - "query" => "param1=val1¶m2=val2", - "path" => "///path/to/dir")).to eq( + "host" => "ftp.example.com", + "query" => "param1=val1¶m2=val2", + "path" => "///path/to/dir")).to eq( "ftp://ftp.example.com/%2fpath/to/dir?param1=val1¶m2=val2" ) end @@ -194,7 +194,7 @@ it "returns URL string with escaped non-ASCII chars in the path" do # bnc#446395 expect(subject.Build("scheme" => "dir", - "path" => "/path/to/\u011B\u0161\u010D\u0159\u017E\u00FD\u00E1\u00ED\u00E9/dir")).to eq( + "path" => "/path/to/\u011B\u0161\u010D\u0159\u017E\u00FD\u00E1\u00ED\u00E9/dir")).to eq( "dir:///path/to/%c4%9b%c5%a1%c4%8d%c5%99%c5%be%c3%bd%c3%a1%c3%ad%c3%a9/dir" ) end @@ -202,8 +202,8 @@ it "returns URL string with nonescaped ':' in the path" do # bnc#966413 expect(subject.Build("scheme" => "nfs", - "host" => "test.suse.de", - "path" => "dist/ibs/SUSE:/SLE-SP1:/GA/images/iso/test.iso")).to eq( + "host" => "test.suse.de", + "path" => "dist/ibs/SUSE:/SLE-SP1:/GA/images/iso/test.iso")).to eq( "nfs://test.suse.de/dist/ibs/SUSE:/SLE-SP1:/GA/images/iso/test.iso" ) end @@ -211,17 +211,17 @@ context "given IPv6 host" do it "returns ftp URL string with IPv6 host" do expect(subject.Build("scheme" => "ftp", - "host" => "2001:de8:0:f123::1", - "path" => "///path/to/dir")).to eq( + "host" => "2001:de8:0:f123::1", + "path" => "///path/to/dir")).to eq( "ftp://[2001:de8:0:f123::1]/%2fpath/to/dir" ) end it "returns http URL string with IPv6 host" do expect(subject.Build("scheme" => "http", - "host" => "2001:de8:0:f123::1", - "port" => "8080", - "path" => "///path/to/dir")).to eq( + "host" => "2001:de8:0:f123::1", + "port" => "8080", + "path" => "///path/to/dir")).to eq( "http://[2001:de8:0:f123::1]:8080/path/to/dir" ) end @@ -231,11 +231,11 @@ it "returns samba URL string" do # bnc#491482 expect(subject.Build("domain" => "workgroup", - "host" => "myserver.com", - "pass" => "passwd", - "path" => "/share$$share/path/on/the/share", - "scheme" => "smb", - "user" => "username")).to eq( + "host" => "myserver.com", + "pass" => "passwd", + "path" => "/share$$share/path/on/the/share", + "scheme" => "smb", + "user" => "username")).to eq( "smb://username:passwd@myserver.com/share$$share/path/on/the/share?workgroup=workgroup" ) end diff --git a/library/wizard/src/modules/Confirm.rb b/library/wizard/src/modules/Confirm.rb index 49d279447..bc2d4bf3e 100644 --- a/library/wizard/src/modules/Confirm.rb +++ b/library/wizard/src/modules/Confirm.rb @@ -175,9 +175,9 @@ def MustBeRoot # Message in a continue/cancel popup pop = _( "This module must be run as root.\n" \ - "If you continue now, the module may not function properly.\n" \ - "For example, some settings can be read improperly\n" \ - "and it is unlikely that settings can be written.\n" + "If you continue now, the module may not function properly.\n" \ + "For example, some settings can be read improperly\n" \ + "and it is unlikely that settings can be written.\n" ) # Popup headline diff --git a/library/wizard/src/modules/HTML.rb b/library/wizard/src/modules/HTML.rb index 421abde74..c04946c4e 100644 --- a/library/wizard/src/modules/HTML.rb +++ b/library/wizard/src/modules/HTML.rb @@ -137,9 +137,7 @@ def List(items) html = Ops.add(Ops.add(Ops.add(html, "
  • "), item), "
  • ") end - html = Ops.add(html, "") - - html + Ops.add(html, "") end # Make a HTML (unsorted) colored list from a list of strings @@ -165,9 +163,7 @@ def ColoredList(items, color) ) end - html = Ops.add(html, "") - - html + Ops.add(html, "") end # Colorize a piece of HTML code diff --git a/library/wizard/src/modules/Progress.rb b/library/wizard/src/modules/Progress.rb index 7046450f5..3e64dad57 100644 --- a/library/wizard/src/modules/Progress.rb +++ b/library/wizard/src/modules/Progress.rb @@ -167,7 +167,8 @@ def PushState "progress_val" => @progress_val } - if current_subprogress == :progress + case current_subprogress + when :progress Ops.set( state, "subprogress_label", @@ -178,7 +179,7 @@ def PushState "subprogress_value", Convert.to_integer(UI.QueryWidget(Id(:subprogress_progress), :Value)) ) - elsif current_subprogress == :tick + when :tick Ops.set( state, "subprogress_label", @@ -416,7 +417,7 @@ def New(window_title, progress_title, length, stg, tits, help_text) end bar = Builtins.add(bar, Left(HBox(HSquash(items)))) - bar = if 0 != @steps + bar = if 0 == @steps Builtins.add( bar, VBox( @@ -424,7 +425,7 @@ def New(window_title, progress_title, length, stg, tits, help_text) ReplacePoint(Id(:subprogress_replace_point), Empty()), ReplacePoint( Id(:progress_replace_point), - ProgressBar(Id(:pb), progress_title, length, 0) + Label(Id(:pb), Opt(:hstretch), progress_title) ), VSpacing(2) ) @@ -437,7 +438,7 @@ def New(window_title, progress_title, length, stg, tits, help_text) ReplacePoint(Id(:subprogress_replace_point), Empty()), ReplacePoint( Id(:progress_replace_point), - Label(Id(:pb), Opt(:hstretch), progress_title) + ProgressBar(Id(:pb), progress_title, length, 0) ), VSpacing(2) ) @@ -487,10 +488,11 @@ def SubprogressValue(value) current_type = CurrentSubprogressType() # normal progress - if current_type == :progress + case current_type + when :progress UI.ChangeWidget(Id(:subprogress_progress), :Value, value) # tick progress - elsif current_type == :tick + when :tick UI.ChangeWidget(Id(:subprogress_tick), :Alive, true) else Builtins.y2warning("No subprogress is defined, cannot set the value!") @@ -513,14 +515,15 @@ def SubprogressType(type, max_value) ) if type == CurrentSubprogressType() - if type == :progress + case type + when :progress # just reset the current value of the progress bar if the requested progress is the same if max_value == @last_subprogress_max Builtins.y2milestone("Resetting the subprogressbar...") SubprogressValue(0) return end - elsif type == :tick + when :tick # just restart the animation UI.ChangeWidget(Id(:subprogress_tick), :Alive, true) else @@ -531,11 +534,12 @@ def SubprogressType(type, max_value) widget = Empty() - if type == :progress + case type + when :progress widget = ProgressBar(Id(:subprogress_progress), " ", max_value, 0) - elsif type == :tick + when :tick widget = BusyIndicator(Id(:subprogress_tick), " ", 3000) - elsif type == :none + when :none widget = Empty() else Builtins.y2error("Unknown subprogress type: %1", type) @@ -557,9 +561,10 @@ def SubprogressTitle(title) current_type = CurrentSubprogressType() - if current_type == :progress + case current_type + when :progress UI.ChangeWidget(Id(:subprogress_progress), :Label, title) - elsif current_type == :tick + when :tick UI.ChangeWidget(Id(:subprogress_tick), :Label, title) else Builtins.y2warning("No subprogress is defined, cannot set the label!") @@ -863,14 +868,12 @@ def CloseSuperior # Make one step in a superior progress bar. def StepSuperior if Ops.greater_or_equal(@super_step, 0) && - Ops.less_than(@super_step, @super_steps) - if !UI.HasSpecialWidget(:Wizard) - UI.ChangeWidget( - Id(Builtins.sformat("super_progress_%1", @super_step)), - :Value, - UI.Glyph(:CheckMark) - ) - end + Ops.less_than(@super_step, @super_steps) && !UI.HasSpecialWidget(:Wizard) + UI.ChangeWidget( + Id(Builtins.sformat("super_progress_%1", @super_step)), + :Value, + UI.Glyph(:CheckMark) + ) end @super_step = Ops.add(@super_step, 1) return if Ops.greater_or_equal(@super_step, @super_steps) diff --git a/library/wizard/src/modules/Wizard.rb b/library/wizard/src/modules/Wizard.rb index bc022e5eb..9fb6a2d24 100644 --- a/library/wizard/src/modules/Wizard.rb +++ b/library/wizard/src/modules/Wizard.rb @@ -948,9 +948,7 @@ def SetAbortButton(id, label) # @note This is a stable API function # def HideNextButton - if UI.WizardCommand(term(:SetNextButtonLabel, "")) == false - UI.ReplaceWidget(Id(:rep_next), Empty()) if UI.WidgetExists(Id(:rep_next)) - end + UI.ReplaceWidget(Id(:rep_next), Empty()) if UI.WizardCommand(term(:SetNextButtonLabel, "")) == false && UI.WidgetExists(Id(:rep_next)) nil end @@ -962,9 +960,7 @@ def HideNextButton # @note This is a stable API function # def HideBackButton - if UI.WizardCommand(term(:SetBackButtonLabel, "")) == false - UI.ReplaceWidget(Id(:rep_back), Empty()) if UI.WidgetExists(Id(:rep_back)) - end + UI.ReplaceWidget(Id(:rep_back), Empty()) if UI.WizardCommand(term(:SetBackButtonLabel, "")) == false && UI.WidgetExists(Id(:rep_back)) nil end @@ -1701,10 +1697,11 @@ def CreateMenuInternal(menu, parent) end mm = Builtins.maplist(m) do |cc| - if Ops.get_string(cc, "type", "") == "MenuEntry" + case Ops.get_string(cc, "type", "") + when "MenuEntry" menu_entry = Ops.get_string(cc, "id", "") next Item(Id(menu_entry), Ops.get_string(cc, "title", "")) - elsif Ops.get_string(cc, "type", "") == "SubMenu" + when "SubMenu" sub_menu = Ops.get_string(cc, "id", "") next term( :menu, diff --git a/library/wizard/test/manual/progress_demo.rb b/library/wizard/test/manual/progress_demo.rb index 8ab11a214..7781cee99 100755 --- a/library/wizard/test/manual/progress_demo.rb +++ b/library/wizard/test/manual/progress_demo.rb @@ -52,6 +52,8 @@ class ProgressDemo < Client attr_accessor :progress_type def initialize + super + Yast.import "UI" Yast.import "Progress" diff --git a/library/wizard/test/test_helper.rb b/library/wizard/test/test_helper.rb index 08dc933d5..6affe9fe9 100644 --- a/library/wizard/test/test_helper.rb +++ b/library/wizard/test/test_helper.rb @@ -1 +1 @@ -require_relative "../../../test/test_helper.rb" +require_relative "../../../test/test_helper" diff --git a/library/xml/src/modules/XML.rb b/library/xml/src/modules/XML.rb index 756142aef..66fc1701b 100644 --- a/library/xml/src/modules/XML.rb +++ b/library/xml/src/modules/XML.rb @@ -137,7 +137,7 @@ def YCPToXMLString(doc_type, contents) metadata = @docs[doc_type] if !metadata log.error "Calling YCPToXML with unknown doc_type #{doc_type.inspect}. " \ - "Known types #{@docs.keys.inspect}" + "Known types #{@docs.keys.inspect}" return nil end @@ -337,21 +337,18 @@ def add_element(doc, metadata, parent, contents, parent_array: nil) def fetch_type(text, children, node) raise XMLDeserializationError.for_node(node, "contains both 't' and 'type' attributes") if node["t"] && node["type"] - type = node["t"] || node["type"] || detect_type(text, children, node) - type + node["t"] || node["type"] || detect_type(text, children, node) end def detect_type(text, children, node) # backward compatibility. Newly maps should have its type if text.empty? && !children.empty? "map" - elsif !text.empty? && children.empty? - "string" - # keep cdata trick to create empty string - elsif !node.children.reject(&:text?).select(&:cdata?).empty? - "string" - elsif text.empty? && children.empty? - # default type is text if nothing is specified and cannot interfere + elsif (!text.empty? && children.empty?) || + # keep cdata trick to create empty string + !node.children.reject(&:text?).select(&:cdata?).empty? || + # default type is text if nothing is specified and cannot interfere + (text.empty? && children.empty?) "string" else raise XMLDeserializationError.for_node(node, "contains both text #{text.inspect} and elements #{children.inspect}.") diff --git a/library/xml/test/test_helper.rb b/library/xml/test/test_helper.rb index 08dc933d5..6affe9fe9 100644 --- a/library/xml/test/test_helper.rb +++ b/library/xml/test/test_helper.rb @@ -1 +1 @@ -require_relative "../../../test/test_helper.rb" +require_relative "../../../test/test_helper" diff --git a/library/xml/test/xml_test.rb b/library/xml/test/xml_test.rb index ac3856e1f..c03a87e69 100644 --- a/library/xml/test/xml_test.rb +++ b/library/xml/test/xml_test.rb @@ -22,11 +22,11 @@ it "returns converted xml for known doc type and passed object" do input = { "test" => :abc, "lest" => 15 } expected = "\n" \ - "\n" \ - "\n" \ - " 15\n" \ - " abc\n" \ - "\n" + "\n" \ + "\n" \ + " 15\n" \ + " abc\n" \ + "\n" expect(subject.YCPToXMLString("test", input)).to eq expected end @@ -35,11 +35,11 @@ it "creates xml element with t=boolean attribute" do input = { "test" => true, "lest" => false } expected = "\n" \ - "\n" \ - "\n" \ - " false\n" \ - " true\n" \ - "\n" + "\n" \ + "\n" \ + " false\n" \ + " true\n" \ + "\n" expect(subject.YCPToXMLString("test", input)).to eq expected end @@ -49,11 +49,11 @@ it "creates xml element with t=integer attribute" do input = { "test" => 5, "lest" => -5 } expected = "\n" \ - "\n" \ - "\n" \ - " -5\n" \ - " 5\n" \ - "\n" + "\n" \ + "\n" \ + " -5\n" \ + " 5\n" \ + "\n" expect(subject.YCPToXMLString("test", input)).to eq expected end @@ -63,11 +63,11 @@ it "creates xml element with t=symbol attribute" do input = { "test" => :test, "lest" => :lest } expected = "\n" \ - "\n" \ - "\n" \ - " lest\n" \ - " test\n" \ - "\n" + "\n" \ + "\n" \ + " lest\n" \ + " test\n" \ + "\n" expect(subject.YCPToXMLString("test", input)).to eq expected end @@ -77,11 +77,11 @@ it "creates xml element with no type attribute" do input = { "test" => "test", "lest" => "lest" } expected = "\n" \ - "\n" \ - "\n" \ - " lest\n" \ - " test\n" \ - "\n" + "\n" \ + "\n" \ + " lest\n" \ + " test\n" \ + "\n" expect(subject.YCPToXMLString("test", input)).to eq expected end @@ -91,13 +91,13 @@ it "create xml elements for its keys and values and t=map attribute" do input = { "test" => { "a" => "b", "lest" => :lest } } expected = "\n" \ - "\n" \ - "\n" \ - " \n" \ - " b\n" \ - " lest\n" \ - " \n" \ - "\n" + "\n" \ + "\n" \ + " \n" \ + " b\n" \ + " lest\n" \ + " \n" \ + "\n" expect(subject.YCPToXMLString("test", input)).to eq expected end @@ -111,14 +111,14 @@ it "places keys in alphabetic sorting" do input = { "test" => { "a" => "b", "lest" => :lest, "b" => "c" } } expected = "\n" \ - "\n" \ - "\n" \ - " \n" \ - " b\n" \ - " c\n" \ - " lest\n" \ - " \n" \ - "\n" + "\n" \ + "\n" \ + " \n" \ + " b\n" \ + " c\n" \ + " lest\n" \ + " \n" \ + "\n" expect(subject.YCPToXMLString("test", input)).to eq expected end @@ -140,13 +140,13 @@ it "create xml elements for values and specify t=list" do input = { "test" => ["b", :lest] } expected = "\n" \ - "\n" \ - "\n" \ - " \n" \ - " b\n" \ - " lest\n" \ - " \n" \ - "\n" + "\n" \ + "\n" \ + " \n" \ + " b\n" \ + " lest\n" \ + " \n" \ + "\n" expect(subject.YCPToXMLString("test", input)).to eq expected end @@ -155,13 +155,13 @@ it "creates xml elements with name passed to listEntries if found" do input = { "list1" => ["b", :lest] } expected = "\n" \ - "\n" \ - "\n" \ - " \n" \ - " b\n" \ - " lest\n" \ - " \n" \ - "\n" + "\n" \ + "\n" \ + " \n" \ + " b\n" \ + " lest\n" \ + " \n" \ + "\n" expect(subject.YCPToXMLString("test", input)).to eq expected end @@ -183,11 +183,11 @@ input = { "test" => :abc, "lest" => 15 } expected = "\n" \ - "\n" \ - "\n" \ - " 15\n" \ - " abc\n" \ - "\n" + "\n" \ + "\n" \ + " 15\n" \ + " abc\n" \ + "\n" expect(subject.YCPToXMLString("testns", input)).to eq expected end @@ -197,61 +197,61 @@ context "regarding 'config:type' and 't' attributes:" do it "recognizes the 't' attribute" do input = "\n" \ - " sym\n" \ - "\n" + " sym\n" \ + "\n" expected = { "foo" => :sym } expect(subject.XMLToYCPString(input)).to eq expected end it "recognizes the 'type' attribute (unnamespaced)" do input = "\n" \ - " sym\n" \ - "\n" + " sym\n" \ + "\n" expected = { "foo" => :sym } expect(subject.XMLToYCPString(input)).to eq expected end it "recognizes the 'config:type' attribute" do input = "\n" \ - " sym\n" \ - "\n" + " sym\n" \ + "\n" expected = { "foo" => :sym } expect(subject.XMLToYCPString(input)).to eq expected end it "recognizes the 'config:type' attribute even with a different prefix" do input = "\n" \ - " sym\n" \ - "\n" + " sym\n" \ + "\n" expected = { "foo" => :sym } expect(subject.XMLToYCPString(input)).to eq expected end it "in case of conflict it raises" do input = "\n" \ - " str\n" \ - " str\n" \ - "\n" + " str\n" \ + " str\n" \ + "\n" expect { subject.XMLToYCPString(input) }.to raise_error(Yast::XMLDeserializationError, /both 't' and 'type'/) end it "in raises when the type is invalid" do input = "\n" \ - " old\n" \ - "\n" + " old\n" \ + "\n" expect { subject.XMLToYCPString(input) }.to raise_error(Yast::XMLDeserializationError, /invalid type "typewriter"/) end end it "returns string for xml element with type=\"string\"" do input = "\n" \ - "\n" \ - "\n" \ - " 5\n" \ - " \n" \ - " -5 \n" \ - " \n" \ - "\n" + "\n" \ + "\n" \ + " 5\n" \ + " \n" \ + " -5 \n" \ + " \n" \ + "\n" expected = { "test" => "5", "lest" => "-5" } expect(subject.XMLToYCPString(input)).to eq expected @@ -260,12 +260,12 @@ # backward compatibility it "returns string for xml element with type=\"disksize\"" do input = "\n" \ - "\n" \ - " 5\n" \ - " \n" \ - " -5 \n" \ - " \n" \ - "\n" + "\n" \ + " 5\n" \ + " \n" \ + " -5 \n" \ + " \n" \ + "\n" expected = { "test" => "5", "lest" => "-5" } expect(subject.XMLToYCPString(input)).to eq expected @@ -273,12 +273,12 @@ it "returns string for xml element without type and with text" do input = "\n" \ - "\n" \ - " 5\n" \ - " \n" \ - " -5 \n" \ - " \n" \ - "\n" + "\n" \ + " 5\n" \ + " \n" \ + " -5 \n" \ + " \n" \ + "\n" expected = { "test" => "5", "lest" => "-5" } expect(subject.XMLToYCPString(input)).to eq expected @@ -286,10 +286,10 @@ it "returns integer for xml element with type=\"integer\"" do input = "\n" \ - "\n" \ - " 5\n" \ - " -5\n" \ - "\n" + "\n" \ + " 5\n" \ + " -5\n" \ + "\n" expected = { "test" => 5, "lest" => -5 } expect(subject.XMLToYCPString(input)).to eq expected @@ -297,21 +297,21 @@ it "raises XMLDeserializationError (with line info) for invalid integers" do input = "\n" \ - "\n" \ - " 5\n" \ - " -5\n" \ - " invalid\n" \ - "\n" + "\n" \ + " 5\n" \ + " -5\n" \ + " invalid\n" \ + "\n" expect { subject.XMLToYCPString(input) }.to raise_error(Yast::XMLDeserializationError, /at line 5: cannot be parsed as an integer/) end it "returns symbol for xml element with type=\"symbol\"" do input = "\n" \ - "\n" \ - " 5\n" \ - " test\n" \ - "\n" + "\n" \ + " 5\n" \ + " test\n" \ + "\n" expected = { "test" => :"5", "lest" => :test } expect(subject.XMLToYCPString(input)).to eq expected @@ -319,10 +319,10 @@ it "returns boolean for xml element with type=\"boolean\"" do input = "\n" \ - "\n" \ - " true\n" \ - " false\n" \ - "\n" + "\n" \ + " true\n" \ + " false\n" \ + "\n" expected = { "test" => true, "lest" => false } expect(subject.XMLToYCPString(input)).to eq expected @@ -330,22 +330,22 @@ it "raises XMLDeserializationError xml element with type=\"boolean\" and unknown value" do input = "\n" \ - "\n" \ - " true\n" \ - " invalid\n" \ - "\n" + "\n" \ + " true\n" \ + " invalid\n" \ + "\n" expect { subject.XMLToYCPString(input) }.to raise_error(Yast::XMLDeserializationError) end it "returns array for xml element with type=\"list\"" do input = "\n" \ - "\n" \ - " \n" \ - " false\n" \ - " 5\n" \ - " \n" \ - "\n" + "\n" \ + " \n" \ + " false\n" \ + " 5\n" \ + " \n" \ + "\n" expected = { "test" => [false, 5] } expect(subject.XMLToYCPString(input)).to eq expected @@ -353,15 +353,15 @@ it "works also on nested arrays" do input = "\n" \ - "\n" \ - " \n" \ - " \n" \ - " false\n" \ - " true\n" \ - " \n" \ - " 5\n" \ - " \n" \ - "\n" + "\n" \ + " \n" \ + " \n" \ + " false\n" \ + " true\n" \ + " \n" \ + " 5\n" \ + " \n" \ + "\n" expected = { "test" => [[false, true], 5] } expect(subject.XMLToYCPString(input)).to eq expected @@ -475,9 +475,9 @@ # for cdata see global before it "returns cdata section as string" do input = "\n" \ - "\n" \ - " false\n" \ - "\n" + "\n" \ + " false\n" \ + "\n" expected = { "cdata1" => "false" } expect(subject.XMLToYCPString(input)).to eq expected @@ -485,9 +485,9 @@ it "raises XMLDeserializationError if xml is malformed" do input = "\n" \ - "\n" \ - " blabla\n" \ - "\n" + "\n" \ + " blabla\n" \ + "\n" expect { subject.XMLToYCPString(input) }.to raise_error(Yast::XMLDeserializationError, /mismatch/) end @@ -499,10 +499,10 @@ it "ignores xml comments" do input = "\n" \ - "\n" \ - " \n" \ - " \n" \ - "\n" + "\n" \ + " \n" \ + " \n" \ + "\n" expected = { "test" => [] } expect(subject.XMLToYCPString(input)).to eq expected