diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..11e55b9 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,97 @@ +# use the shared Yast defaults +inherit_from: + /usr/share/YaST2/data/devtools/data/rubocop-0.71.0_yast_style.yml + +# this needs more testing if we can have frozen string literals +Style/FrozenStringLiteralComment: + Enabled: false + +# Offense count: 1 +# Configuration parameters: AllowKeywordBlockArguments. +Lint/UnderscorePrefixedVariableName: + Exclude: + - 'src/include/add-on/add-on-workflow.rb' + +Naming/MethodName: + Enabled: false + +Naming/VariableName: + Enabled: false + +Lint/Loop: + Enabled: false + +# Offense count: 11 +Metrics/AbcSize: + Max: 200 + +# Offense count: 24 +# Configuration parameters: CountComments, ExcludedMethods. +# ExcludedMethods: refine +Metrics/BlockLength: + Max: 350 + +# Offense count: 5 +# Configuration parameters: CountBlocks. +Metrics/BlockNesting: + Max: 4 + +# Offense count: 11 +Metrics/CyclomaticComplexity: + Max: 40 + +# Offense count: 12 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Max: 122 + +# Offense count: 16 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/MethodLength: + Max: 280 + +# Offense count: 1 +# Configuration parameters: CountComments. +Metrics/ModuleLength: + Max: 1400 + +# Offense count: 2 +# Configuration parameters: CountKeywordArgs. +Metrics/ParameterLists: + Max: 7 + +# Offense count: 10 +Metrics/PerceivedComplexity: + Max: 41 + +# Offense count: 10 +# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS +Naming/FileName: + Exclude: + - 'src/clients/add-on.rb' + - 'src/clients/add-on_auto.rb' + - 'src/clients/add-on_proposal.rb' + - 'src/clients/inst_add-on.rb' + - 'src/clients/inst_add-on_software.rb' + - 'src/include/add-on/add-on-workflow.rb' + - 'src/lib/add-on/clients/add-on_auto.rb' + - 'src/lib/add-on/clients/inst_add-on.rb' + - 'src/modules/AddOnOthers.rb' + - 'test/y2add_on/clients/inst_add-on_test.rb' + +# Offense count: 8 +Style/Documentation: + Exclude: + - 'spec/**/*' + - 'test/**/*' + - 'src/clients/add-on.rb' + - 'src/clients/add-on_proposal.rb' + - 'src/clients/inst_add-on_software.rb' + - 'src/clients/vendor.rb' + - 'src/include/add-on/add-on-workflow.rb' + - 'src/include/add-on/misc.rb' + - 'src/lib/add-on/clients/add-on_auto.rb' + - 'src/modules/AddOnOthers.rb' diff --git a/Rakefile b/Rakefile index 573acba..017fab9 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,7 @@ require "yast/rake" Yast::Tasks.configuration do |conf| - #lets ignore license check for now + # lets ignore license check for now conf.skip_license_check << /.*/ conf.install_locations["doc/autodocs"] = conf.install_doc_dir end diff --git a/package/yast2-add-on.changes b/package/yast2-add-on.changes index 2ebc324..178a275 100644 --- a/package/yast2-add-on.changes +++ b/package/yast2-add-on.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Wed Jun 10 14:04:00 UTC 2020 - Josef Reidinger + +- Reduce autoyast profile size if addons are empty (bsc#1172749) +- 4.3.1 + ------------------------------------------------------------------- Thu May 7 08:58:18 UTC 2020 - Josef Reidinger diff --git a/package/yast2-add-on.spec b/package/yast2-add-on.spec index 066e08f..2e3e9b1 100644 --- a/package/yast2-add-on.spec +++ b/package/yast2-add-on.spec @@ -17,7 +17,7 @@ Name: yast2-add-on -Version: 4.3.0 +Version: 4.3.1 Release: 0 Summary: YaST2 - Add-On media installation code License: GPL-2.0-only diff --git a/src/clients/add-on.rb b/src/clients/add-on.rb index 1d8ded2..a5822e8 100644 --- a/src/clients/add-on.rb +++ b/src/clients/add-on.rb @@ -1,9 +1,7 @@ -# encoding: utf-8 - -# File: clients/add-on.ycp -# Package: yast2-installation -# Summary: Install an add-on product -# Authors: Jiri Srain +# File: clients/add-on.ycp +# Package: yast2-installation +# Summary: Install an add-on product +# Authors: Jiri Srain # module Yast class AddOnClient < Client @@ -33,7 +31,7 @@ def main "interface, use '%{zypper}' instead for adding a new repository or " \ "'%{SUSEConnect}' to register a new add-on." ), - { zypper: "zypper", SUSEConnect: "SUSEConnect" } + zypper: "zypper", SUSEConnect: "SUSEConnect" ), "guihandler" => fun_ref(method(:run_GUI), "symbol ()") ) diff --git a/src/clients/add-on_proposal.rb b/src/clients/add-on_proposal.rb index 890bf3f..10a3c0f 100644 --- a/src/clients/add-on_proposal.rb +++ b/src/clients/add-on_proposal.rb @@ -1,12 +1,10 @@ -# encoding: utf-8 - -# File: add-on_proposal.ycp +# File: add-on_proposal.ycp # -# Authors: Jiri Srain +# Authors: Jiri Srain # -# Purpose: Proposal function dispatcher - add-no products +# Purpose: Proposal function dispatcher - add-no products # -# See also file proposal-API.txt for details. +# See also file proposal-API.txt for details. module Yast class AddOnProposalClient < Client def main @@ -32,13 +30,13 @@ def main @items = Builtins.maplist(AddOnProduct.add_on_products) do |product| data = Pkg.SourceGeneralData(Ops.get_integer(product, "media", -1)) # placeholder for unknown path - dir = Ops.get_locale(data, "product_dir", product.fetch( "product_dir", _("Unknown"))) + dir = Ops.get_locale(data, "product_dir", product.fetch("product_dir", _("Unknown"))) dir = "/" if dir == "" # summary item, %1 is product name, %2 media URL, %3 directory on media Builtins.sformat( "%1 (Media %2, directory %3)", Ops.get_string(product, "product", _("No name defined")), - Ops.get_locale(data, "url", product.fetch( "media_url", _("Unknown"))), + Ops.get_locale(data, "url", product.fetch("media_url", _("Unknown"))), dir ) end diff --git a/src/clients/inst_add-on_software.rb b/src/clients/inst_add-on_software.rb index 61af87e..310356b 100644 --- a/src/clients/inst_add-on_software.rb +++ b/src/clients/inst_add-on_software.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - # File: inst_add-on_software.ycp # # Client providing the software overview/selection to be used @@ -83,7 +81,7 @@ def main # Call the package selector # Since yast2 >= 2.17.58 - @ret = PackagesUI.RunPackageSelector({ "mode" => @run_in_mode }) + @ret = PackagesUI.RunPackageSelector("mode" => @run_in_mode) Builtins.y2milestone("RunPackageSelector returned %1", @ret) @dialog_ret = :next @@ -96,9 +94,9 @@ def main Builtins.y2milestone("Selected resolvables will be installed now") if WFM.CallFunction( - "inst_rpmcopy", - [GetInstArgs.Buttons(false, false)] - ) == :abort + "inst_rpmcopy", + [GetInstArgs.Buttons(false, false)] + ) == :abort @dialog_ret = :abort else Kernel.InformAboutKernelChange diff --git a/src/clients/vendor.rb b/src/clients/vendor.rb index d964c5d..eb5d6ae 100644 --- a/src/clients/vendor.rb +++ b/src/clients/vendor.rb @@ -1,9 +1,7 @@ -# encoding: utf-8 - -# File: clients/vendor.ycp -# Package: yast2-add-on -# Summary: Load vendor driver CD -# Authors: Klaus Kaempf +# File: clients/vendor.ycp +# Package: yast2-add-on +# Summary: Load vendor driver CD +# Authors: Klaus Kaempf # # $Id$ @@ -70,9 +68,9 @@ def main # try to mount device while SCR.Execute( - path(".target.mount"), - [@default_device, Installation.sourcedir] - ) == false + path(".target.mount"), + [@default_device, Installation.sourcedir] + ) == false # VENDOR: cant mount /dev/cdrom popup if !Popup.ContinueCancel(_("Please insert the vendor CD-ROM")) UI.CloseDialog @@ -86,7 +84,6 @@ def main @cdpath = Installation.sourcedir - # get directory on update disk from installation (value from install.inf) # # if not set, determine directory from installed products @@ -100,13 +97,13 @@ def main else Pkg.TargetInit("/", false) - base = Y2Packager::Resolvable.find(kind: :product, - status: :installed, - category: "base") + base = Y2Packager::Resolvable.find(kind: :product, + status: :installed, + category: "base") if base.empty? # fallback - base = Y2Packager::Resolvable.find(kind: :product, - status: :installed) + base = Y2Packager::Resolvable.find(kind: :product, + status: :installed) end version = base[0] ? base[0].version_version : "" @@ -128,7 +125,7 @@ def main @dirlist2 = Convert.to_list(SCR.Read(path(".target.dir"), @cdpath)) if Ops.less_or_equal(Builtins.size(@dirlist2), 0) || - !(Builtins.contains(@dirlist2, "suse")) + !Builtins.contains(@dirlist2, "suse") # VENDOR: vendor cd contains wrong data return wrong_cd( _("Could not find driver data on the CD-ROM.\nAborting now."), @@ -146,8 +143,8 @@ def main @dirlist = Convert.convert( SCR.Read(path(".target.dir"), @cdpath), - :from => "any", - :to => "list " + from: "any", + to: "list " ) if Ops.less_or_equal(Builtins.size(@dirlist), 0) # VENDOR: vendor cd doesn't contain data for current system and linux version @@ -185,9 +182,7 @@ def main @inst_count = 0 @short_lang = "" - if Ops.greater_than(Builtins.size(@language), 2) - @short_lang = Builtins.substring(@language, 0, 2) - end + @short_lang = Builtins.substring(@language, 0, 2) if Ops.greater_than(Builtins.size(@language), 2) # try to load .inst files, try with (xx_XX) ISO language first, # then with 2 char language code @@ -259,15 +254,15 @@ def main end @result_message = "" - if Ops.greater_than(@inst_count, 0) + @result_message = if Ops.greater_than(@inst_count, 0) # VENDOR: message box with number of drivers installed - @result_message = Builtins.sformat( + Builtins.sformat( _("Installed %1 drivers from CD"), @inst_count ) else # VENDOR: message box with error text - @result_message = _( + _( "No driver data found on the CD-ROM.\nAborting now." ) end @@ -278,7 +273,7 @@ def main SCR.Execute(path(".target.umount"), Installation.sourcedir) UI.CloseDialog - :ok + :ok # EOF end diff --git a/src/include/add-on/add-on-workflow.rb b/src/include/add-on/add-on-workflow.rb index 77eb8e8..357ec2f 100755 --- a/src/include/add-on/add-on-workflow.rb +++ b/src/include/add-on/add-on-workflow.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - # File: # include/add-on/add-on-workflow.ycp # @@ -11,7 +9,7 @@ # # Authors: # Jiri Srain -# Lukas Ocilka +# Lukas Ocilka # # @@ -116,9 +114,9 @@ def MediaSelect aliases = { # true: Skip "type" if it comes from :back and call registartion instead. # bsc#1160501 - "type" => [lambda { media_type_selection }, true ], - "edit" => lambda { EditDialog() }, - "store" => lambda { StoreSource() } + "type" => [-> { media_type_selection }, true], + "edit" => -> { EditDialog() }, + "store" => -> { StoreSource() } } sources_before = Pkg.SourceGetCurrent(false) @@ -127,23 +125,23 @@ def MediaSelect sequence = { "ws_start" => "type", "type" => { - :next => "edit", + next: "edit", # bnc #392083 - :finish => "store", - :abort => :abort, - :skip => :skip + finish: "store", + abort: :abort, + skip: :skip }, "edit" => { - :next => "store", + next: "store", # bnc #392083 - :finish => "store", - :abort => :abort + finish: "store", + abort: :abort }, "store" => { - :next => :next, + next: :next, # bnc #392083 - :finish => :next, - :abort => :abort + finish: :next, + abort: :abort } } @@ -166,7 +164,7 @@ def MediaSelect def SetAddOnProductName(src_id) @new_addon_name = "" - if src_id == nil + if src_id.nil? Builtins.y2error("Cannot set name, no ID!") return end @@ -174,7 +172,7 @@ def SetAddOnProductName(src_id) @new_addon_name = SourceDialogs.GetRepoName # no name to change to - if @new_addon_name == nil || @new_addon_name == "" + if @new_addon_name.nil? || @new_addon_name == "" Builtins.y2milestone("No special name set") return end @@ -236,7 +234,7 @@ def CatalogSelect Builtins.y2warning("Already in base dialog!") else Builtins.y2error("Error in packager, closing current dialog!") - while !UI.WidgetExists(:contents) + until UI.WidgetExists(:contents) Builtins.y2milestone("Calling UI::CloseDialog") UI.CloseDialog end @@ -278,8 +276,8 @@ def CatalogSelect title = _("Software Repository Selection") # help text help_text = _( - "

Software Repository Selection
\n" + - "Multiple repositories were found on the selected medium.\n" + + "

Software Repository Selection
\n" \ + "Multiple repositories were found on the selected medium.\n" \ "Select the repository to use.

\n" ) @@ -295,19 +293,21 @@ def CatalogSelect Wizard.SetContents(title, contents, help_text, true, true) ret = nil selected = nil - while ret == nil + while ret.nil? ret = Convert.to_symbol(UI.UserInput) - if ret == :abort || ret == :cancel + case ret + when :abort, :cancel ret = :abort break if Popup.YesNo(_("Really abort add-on product installation?")) + next - elsif ret == :back + when :back break - elsif ret == :next + when :next selected = Convert.to_integer( UI.QueryWidget(Id(:catalogs), :CurrentItem) ) - if selected == nil + if selected.nil? ret = nil # popup message Popup.Message(_("Select a repository.")) @@ -358,6 +358,7 @@ def InstallProduct all_products.each do |product| # Product doesn't match the new source ID next unless @added_repos.include?(product.source) + # Product is not available (either `installed or `selected or ...) if product.status != :available log.info("Skipping product #{product.name} with status " \ @@ -384,12 +385,13 @@ def ProductSelect # getting all source urls and product_dirs Builtins.foreach(all_products) do |p| one_src_id = Builtins.tointeger(Ops.get(p, "source")) - next if one_src_id == nil + next if one_src_id.nil? # the last source (just added) next if one_src_id == AddOnProduct.src_id + src_general_data = Pkg.SourceGeneralData(one_src_id) source_url = Ops.get_string(src_general_data, "url", "") - if source_url != "" && source_url != nil + if source_url != "" && !source_url.nil? Ops.set( already_used_urls, source_url, @@ -445,16 +447,15 @@ def ProductSelect AddOnProduct.add_on_products = Builtins.add( AddOnProduct.add_on_products, - { - "media" => AddOnProduct.src_id, - # table cell - "product" => @new_addon_name != "" && - @new_addon_name != nil ? - @new_addon_name : - _("No product found in the repository."), - "media_url" => url, - "product_dir" => product_dir - } + "media" => AddOnProduct.src_id, + # table cell + "product" => if [nil, ""].include?(@new_addon_name) + _("No product found in the repository.") + else + @new_addon_name + end, + "media_url" => url, + "product_dir" => product_dir ) if Mode.config @@ -485,16 +486,11 @@ def ProductSelect # there is only one product on the given url if Builtins.size(products) == 1 - # bugzilla #227605 - # this product with this url has been already installed or selected for installation - src_general_data = Pkg.SourceGeneralData(AddOnProduct.src_id) - current_url = Ops.get_string(src_general_data, "url", "") - Builtins.y2milestone("Only one product available - skipping dialog") prod = Ops.get(products, 0, {}) if !AddOnProduct.CheckProductDependencies( - [Ops.get_string(prod, "name", "")] - ) + [Ops.get_string(prod, "name", "")] + ) Pkg.ResolvableRemove(Ops.get_string(prod, "name", ""), :product) # message popup Popup.Message( @@ -510,9 +506,9 @@ def ProductSelect Builtins.foreach(all_products) do |p| if Ops.get_string(p, "name", "") == Ops.get_string(prod, "name", "") && Ops.get_string(p, "version", "") == - Ops.get_string(prod, "version", "") && + Ops.get_string(prod, "version", "") && Ops.get_integer(p, "media", -2) != - Ops.get_integer(prod, "media", -3) + Ops.get_integer(prod, "media", -3) Builtins.y2milestone( "Product %1 already available on media %2", p, @@ -538,24 +534,23 @@ def ProductSelect AddOnProduct.add_on_products = Builtins.add( AddOnProduct.add_on_products, - { - "media" => AddOnProduct.src_id, - "product" => @new_addon_name != "" && - @new_addon_name != nil ? - @new_addon_name : - Ops.get_string( - prod, - "display_name", - Ops.get_string( - prod, - "short_name", - Ops.get_string(prod, "name", "") - ) - ), - "autoyast_product" => Ops.get_string(prod, "name", ""), - "media_url" => url, - "product_dir" => product_dir - } + "media" => AddOnProduct.src_id, + "product" => if [nil, ""].include?(@new_addon_name) != "" + Ops.get_string( + prod, + "display_name", + Ops.get_string( + prod, + "short_name", + Ops.get_string(prod, "name", "") + ) + ) + else + @new_addon_name + end, + "autoyast_product" => Ops.get_string(prod, "name", ""), + "media_url" => url, + "product_dir" => product_dir ) if found_source == -1 && Mode.config @@ -592,32 +587,25 @@ def ProductSelect ) # help text help_text = _( - "

Product Selection
\n" + - "Multiple products were found in the repository. Select the products\n" + + "

Product Selection
\n" \ + "Multiple products were found in the repository. Select the products\n" \ "to install.

\n" ) Wizard.SetContents(title, contents, help_text, true, true) - while ret == nil + while ret.nil? ret = Convert.to_symbol(UI.UserInput) - if ret == :cancel || ret == :abort - ret = :abort - # if (Stage::initial()) - # { - # if (Popup::ConfirmAbort (`painless)) - # break; - # } - # else - # { + ret = :abort if ret == :cancel + if ret == :abort # yes-no popup break if Popup.YesNo(_("Really abort add-on product installation?")) - # } + next end if ret == :next selected = Convert.convert( UI.QueryWidget(Id(:products), :SelectedItems), - :from => "any", - :to => "list " + from: "any", + to: "list " ) # check whether the product is already available on some media - it is similar as above prods = Builtins.filter(products) do |p| @@ -625,25 +613,25 @@ def ProductSelect end all_found = true prod2src = {} - Builtins.foreach(prods) do |prod| + Builtins.foreach(prods) do |product| product_found = false Builtins.foreach(all_products) do |p| if Ops.get_string(p, "name", "") == - Ops.get_string(prod, "name", "") && + Ops.get_string(product, "name", "") && Ops.get_string(p, "version", "") == - Ops.get_string(prod, "version", "") && + Ops.get_string(product, "version", "") && Ops.get_integer(p, "media", -2) != - Ops.get_integer(prod, "media", -3) + Ops.get_integer(product, "media", -3) product_found = true Ops.set( prod2src, - Ops.get_string(prod, "name", ""), + Ops.get_string(product, "name", ""), Ops.get_integer(p, "media", -3) ) raise Break end end - all_found = all_found && product_found + all_found &&= product_found end if all_found Builtins.y2milestone("Deleting source %1", AddOnProduct.src_id) @@ -671,21 +659,24 @@ def ProductSelect product_dir = Ops.get_string(data, "product_dir", "") Builtins.foreach(selected) do |product| - src_id = AddOnProduct.src_id == -1 ? - Ops.get(prod2src, product, -1) : + src_id = if AddOnProduct.src_id == -1 + Ops.get(prod2src, product, -1) + else AddOnProduct.src_id + end # bugzilla #304659 SetAddOnProductName(AddOnProduct.src_id) AddOnProduct.add_on_products = Builtins.add( AddOnProduct.add_on_products, - { - "media" => src_id, - "product" => @new_addon_name != "" && - @new_addon_name != nil ? @new_addon_name : product, - "autoyast_prouduct" => product, - "media_url" => url, - "product_dir" => product_dir - } + "media" => src_id, + "product" => if [nil, ""].include?(@new_addon_name) + product + else + @new_addon_name + end, + "autoyast_prouduct" => product, + "media_url" => url, + "product_dir" => product_dir ) end if AddOnProduct.src_id != -1 && Mode.config @@ -714,33 +705,33 @@ def ProductSelect # Check new product compliance; may abort the installation def CheckCompliance - compliant = @added_repos.all?{ |src_id| ProductProfile.CheckCompliance(src_id) } + compliant = @added_repos.all? { |src_id| ProductProfile.CheckCompliance(src_id) } compliant ? :next : :abort end def RunWizard aliases = { - "media" => lambda { MediaSelect() }, - "install_product" => lambda { InstallProduct() }, - "check_compliance" => lambda { CheckCompliance() } + "media" => -> { MediaSelect() }, + "install_product" => -> { InstallProduct() }, + "check_compliance" => -> { CheckCompliance() } } sequence = { - "ws_start" => "media", - "media" => { - :abort => :abort, - :next => "check_compliance", - :finish => "check_compliance", - :skip => :skip + "ws_start" => "media", + "media" => { + abort: :abort, + next: "check_compliance", + finish: "check_compliance", + skip: :skip }, "check_compliance" => { - :abort => :abort, - :next => "install_product" + abort: :abort, + next: "install_product" }, - "install_product" => { - :abort => :abort, - :next => :next, - :finish => :next + "install_product" => { + abort: :abort, + next: :next, + finish: :next } } Sequencer.Run(aliases, sequence) @@ -748,14 +739,14 @@ def RunWizard def RunAutorunWizard aliases = { - "catalog" => lambda { CatalogSelect() }, - "product" => lambda { ProductSelect() } + "catalog" => -> { CatalogSelect() }, + "product" => -> { ProductSelect() } } sequence = { "ws_start" => "catalog", - "catalog" => { :abort => :abort, :next => "product", :finish => :next }, - "product" => { :abort => :abort, :next => :next, :finish => :next } + "catalog" => { abort: :abort, next: "product", finish: :next }, + "product" => { abort: :abort, next: :next, finish: :next } } Sequencer.Run(aliases, sequence) end @@ -767,9 +758,9 @@ def Redraw(enable_back, enable_next, enable_abort, back_button, next_button, abo # Help for add-on products help = _( - "

Add-On Product Installation
\n" + - "Here see all add-on products that are selected for installation.\n" + - "To add a new product, click Add. To remove an already added one,\n" + + "

Add-On Product Installation
\n" \ + "Here see all add-on products that are selected for installation.\n" \ + "To add a new product, click Add. To remove an already added one,\n" \ "select it and click Delete.

" ) @@ -786,9 +777,7 @@ def Redraw(enable_back, enable_next, enable_abort, back_button, next_button, abo data = Pkg.SourceGeneralData(Ops.get_integer(product, "media", -1)) else data = deep_copy(product) - if Builtins.haskey(data, "media_url") - Ops.set(data, "url", Ops.get_string(data, "media_url", "")) - end + Ops.set(data, "url", Ops.get_string(data, "media_url", "")) if Builtins.haskey(data, "media_url") end # placeholder for unknown path dir = Ops.get_locale(data, "product_dir", _("Unknown")) @@ -880,7 +869,7 @@ def RemoveSelectedAddOn(selected) Ops.set(AddOnProduct.add_on_products, selected, nil) AddOnProduct.add_on_products = Builtins.filter( AddOnProduct.add_on_products - ) { |prod| prod != nil } + ) { |prod| !prod.nil? } # Remove product from add-ons AddOnProduct.Disintegrate(media) @@ -891,8 +880,6 @@ def RemoveSelectedAddOn(selected) nil end - - # bugzilla #221377 # the original control file is stored as /control.xml # the other (added) control files are under the @@ -944,7 +931,6 @@ def RunAddOnMainDialog(enable_back, enable_next, enable_abort, back_button, next ) end - # store the initial settings, only once WorkflowManager.SetBaseWorkflow(false) @@ -955,26 +941,23 @@ def RunAddOnMainDialog(enable_back, enable_next, enable_abort, back_button, next ret = Convert.to_symbol(UI.UserInput) unless ret == :skip_to_add # aborting - if ret == :abort || ret == :cancel + case ret + when :abort, :cancel # User should confirm that - if confirm_abort == true - if Popup.ConfirmAbort(:incomplete) - ret = :abort - break - else - ret = nil - end - # Running system - else + break unless confirm_abort + + if Popup.ConfirmAbort(:incomplete) + ret = :abort break end + ret = nil # removing add-on - elsif ret == :delete + when :delete selected = Convert.to_integer( UI.QueryWidget(Id(:summary), :CurrentItem) ) - if selected == nil + if selected.nil? # message report Report.Message(_("Select a product to delete.")) next @@ -1001,7 +984,7 @@ def RunAddOnMainDialog(enable_back, enable_next, enable_abort, back_button, next ) # adding new add-on - elsif ret == :add || ret == :skip_to_add + when :add, :skip_to_add # Show the checkbox only the first time in installation when there is no # other addon present, allow to quickly skip adding addons. In the # following runs it makes no sense as user explicitly wants to add an addon. @@ -1059,7 +1042,7 @@ def RunAddOnMainDialog(enable_back, enable_next, enable_abort, back_button, next Pkg.SourceDelete(src_id) AddOnProduct.add_on_products.reject! do |add_on_product| - add_on_product["media"] == src_id + add_on_product["media"] == src_id end end @@ -1170,7 +1153,7 @@ def ReturnCurrentlySelectedProductInfo ) # no items - return nil if item_id == nil + return nil if item_id.nil? if !Builtins.regexpmatch(item_id, "product_") Builtins.y2error("Wrong product ID '%1'", item_id) @@ -1184,7 +1167,7 @@ def ReturnCurrentlySelectedProductInfo def AdjustInfoWidget pi = ReturnCurrentlySelectedProductInfo() - if pi == nil || pi == {} + if pi.nil? || pi == {} UI.ChangeWidget(Id("product_details"), :Value, "") return end @@ -1203,22 +1186,26 @@ def AdjustInfoWidget ), Builtins.sformat( _("Repository URL: %1
"), - Ops.greater_than( + if Ops.greater_than( Builtins.size(Ops.get_list(pi, ["info", "URLs"], [])), 0 - ) ? - Builtins.mergestring(Ops.get_list(pi, ["info", "URLs"], []), ",") : + ) + Builtins.mergestring(Ops.get_list(pi, ["info", "URLs"], []), ",") + else _("Unknown repository URL") + end ), - Ops.greater_than( + if Ops.greater_than( Builtins.size(Ops.get_list(pi, ["info", "aliases"], [])), 0 - ) ? + ) Builtins.sformat( _("Repository Alias: %1
"), Builtins.mergestring(Ops.get_list(pi, ["info", "aliases"], []), ",") - ) : + ) + else "" + end ) UI.ChangeWidget(Id("product_details"), :Value, rt_description) @@ -1231,27 +1218,25 @@ def AdjustRepositoryInfo(info) Builtins.foreach( Convert.convert( Ops.get(info.value, "IDs", []), - :from => "list", - :to => "list " + from: "list", + to: "list " ) ) do |one_repo| - if one_repo == nil || one_repo == -1 + if one_repo.nil? || one_repo == -1 Builtins.y2warning("Wrong repo ID: %1", one_repo) next end source_data = Pkg.SourceGeneralData(one_repo) - if source_data != nil && Builtins.haskey(source_data, "base_urls") + if !source_data.nil? && Builtins.haskey(source_data, "base_urls") urls = source_data["base_urls"] # Add the product directory if it is present - if ![nil, "", "/"].include?(source_data["product_dir"]) - urls.map! { |u| "#{u} (#{source_data["product_dir"]})" } - end + urls.map! { |u| "#{u} (#{source_data["product_dir"]})" } if ![nil, "", "/"].include?(source_data["product_dir"]) Ops.set(info.value, "URLs", urls) else Builtins.y2error("No URLs for repo ID %1", one_repo) end - if source_data != nil && Builtins.haskey(source_data, "alias") + if !source_data.nil? && Builtins.haskey(source_data, "alias") Ops.set( info.value, "aliases", @@ -1282,6 +1267,7 @@ def GetRepoInfo(this_product, all_products) next if one_product.arch != product_arch || one_product.name != product_name || one_product.version != product_version + if one_product.source != -1 Ops.set( ret, @@ -1309,6 +1295,7 @@ def GetInstalledProducts installed_products = Builtins.filter(GetAllProductsInfo()) do |one_product| # Do not list the base product next false if one_product.category == "base" + # BNC #475591: Only those `installed or `selected ones should be actually visible one_product.status == :installed || one_product.status == :selected end @@ -1340,23 +1327,23 @@ def GetProductInfos one_product.name, repository_info ) - if repository_info == nil + if repository_info.nil? Builtins.y2warning( "No matching repository found for product listed above" ) end repository_info = ( - one_product_ref = arg_ref(one_product); - all_products_ref = arg_ref(all_products); - _GetRepoInfo_result = GetRepoInfo(one_product_ref, all_products_ref); - one_product = one_product_ref.value; - all_products = all_products_ref.value; + one_product_ref = arg_ref(one_product) + all_products_ref = arg_ref(all_products) + _GetRepoInfo_result = GetRepoInfo(one_product_ref, all_products_ref) + one_product = one_product_ref.value + all_products = all_products_ref.value _GetRepoInfo_result ) Ops.set( @product_infos, Builtins.tostring(counter), - { "product" => one_product, "info" => repository_info } + "product" => one_product, "info" => repository_info ) end @@ -1383,29 +1370,39 @@ def ReadFromSystem product_infos = Convert.convert( GetProductInfos(), - :from => "map", - :to => "map " + from: "map", + to: "map " ) - if product_infos == nil || product_infos == {} + if product_infos.nil? || product_infos == {} Builtins.y2warning("No add-on products have been found") return true end src_id = nil - Builtins.foreach(product_infos) do |index, product_desc| + Builtins.foreach(product_infos) do |_index, product_desc| src_id = Ops.get_integer(product_desc, ["info", "IDs", 0], -1) - if src_id == nil || src_id == -1 + if src_id.nil? || src_id == -1 Builtins.y2error("Cannot get source ID from %1", product_desc) next end repo_data = Pkg.SourceGeneralData(src_id) AddOnProduct.add_on_products = Builtins.add( AddOnProduct.add_on_products, - { - "media" => src_id, - "product_dir" => Ops.get_string(repo_data, "product_dir", "/"), - "product" => Ops.get_locale( + "media" => src_id, + "product_dir" => Ops.get_string(repo_data, "product_dir", "/"), + "product" => Ops.get_locale( + repo_data, + "name", + Ops.get_locale( + repo_data, + "alias", + _("No product found in the repository.") + ) + ), + "autoyast_product" => Ops.get_locale( + product_desc["product"].name, + Ops.get_locale( repo_data, "name", Ops.get_locale( @@ -1413,21 +1410,9 @@ def ReadFromSystem "alias", _("No product found in the repository.") ) - ), - "autoyast_product" => Ops.get_locale( - product_desc["product"].name, - Ops.get_locale( - repo_data, - "name", - Ops.get_locale( - repo_data, - "alias", - _("No product found in the repository.") - ) - ) - ), - "media_url" => Pkg.SourceURL(src_id) - } + ) + ), + "media_url" => Pkg.SourceURL(src_id) ) end @@ -1443,8 +1428,7 @@ def RedrawAddOnsOverviewTable products = product_infos.map do |index, product_desc| Item(Id("product_#{index}"), ui_product_name(product_desc["product"]), - product_desc["info"]["URLs"].first || _("Unknown URL") - ) + product_desc["info"]["URLs"].first || _("Unknown URL")) end UI.ChangeWidget(Id("list_of_addons"), :Items, products) @@ -1458,7 +1442,7 @@ def RunPackageSelector solve_ret = Pkg.PkgSolve(false) Builtins.y2milestone("Calling Solve() returned: %1", solve_ret) - result = PackagesUI.RunPackageSelector({ "mode" => :summaryMode }) + result = PackagesUI.RunPackageSelector("mode" => :summaryMode) return false if result != :accept @@ -1478,27 +1462,27 @@ def RunPackageSelector # @return [Boolean] whether something has changed its state def RemoveProductWithDependencies pi = ReturnCurrentlySelectedProductInfo() - if pi == nil || pi == {} + if pi.nil? || pi == {} Builtins.y2error("Cannot remove unknown product") return nil end product_name = ui_product_name(pi["product"]) if !Popup.AnyQuestion( - Label.WarningMsg, - Builtins.sformat( - _( - "Deleting the add-on product %1 may result in removing all the packages\n" + - "installed from this add-on.\n" + - "\n" + - "Are sure you want to delete it?" - ), - product_name + Label.WarningMsg, + Builtins.sformat( + _( + "Deleting the add-on product %1 may result in removing all the packages\n" \ + "installed from this add-on.\n" \ + "\n" \ + "Are sure you want to delete it?" ), - Label.DeleteButton, - Label.CancelButton, - :focus_no - ) + product_name + ), + Label.DeleteButton, + Label.CancelButton, + :focus_no + ) Builtins.y2milestone("Deleting '%1' canceled", product_name) return nil end @@ -1510,7 +1494,6 @@ def RemoveProductWithDependencies src_ids = Ops.get_list(pi, ["info", "IDs"], []) # Temporary definitions - pack_ret = false package_string = "" # ["pkg1 version release arch", "pkg2 version release arch", ... ] @@ -1530,11 +1513,12 @@ def RemoveProductWithDependencies packages_from_repo = Builtins.filter(packages_from_repo) do |one_package| # Package is not at the repositories to be deleted if !Builtins.contains( - src_ids, - one_package.source - ) + src_ids, + one_package.source + ) next false end + # Package *is* at the repository to delete # "name version-release arch", "version" already contains a release @@ -1542,7 +1526,7 @@ def RemoveProductWithDependencies "%1 %2 %3", one_package.name, one_package.version, - one_package.arch, + one_package.arch ) # The very same package (which is avaliable at the source) is also installed Builtins.contains(installed_packages, package_string) @@ -1626,12 +1610,12 @@ def RemoveProductWithDependencies # but if another version is present, select if for installation if Builtins.contains( - available_package_names, - one_package.name - ) + available_package_names, + one_package.name + ) Builtins.y2milestone( "Installing another version of %1", - one_package.name, + one_package.name ) Pkg.ResolvableInstall( one_package.name, @@ -1741,23 +1725,24 @@ def RunAddOnsOverviewDialog userret = nil - while true + loop do userret = UI.UserInput # Abort - if userret == :abort || userret == :cancel + case userret + when :abort, :cancel Builtins.y2warning("Aborting...") ret = :abort break # Closing - elsif userret == :next || userret == :finish + when :next, :finish Builtins.y2milestone("Finishing...") ret = :next break # Addin new product - elsif userret == :add + when :add Builtins.y2milestone("Using new Add-On...") RunAddProductWorkflow() if RunWizard() == :next @@ -1765,22 +1750,20 @@ def RunAddOnsOverviewDialog # Something has disabled all the repositories or finished # libzypp, reload it current_repos = Pkg.SourceGetCurrent(true) - if current_repos == nil || Builtins.size(current_repos) == 0 - LoadLibzyppNow() - end + LoadLibzyppNow() if current_repos.nil? || Builtins.size(current_repos) == 0 CreateAddOnsOverviewDialog() RedrawAddOnsOverviewTable() # Removing product - elsif userret == :delete + when :delete Builtins.y2milestone("Removing selected product...") rpwd = RemoveProductWithDependencies() Builtins.y2milestone("RPWD result was: %1", rpwd) # nil == user decided not to remove the product - if rpwd == nil + if rpwd.nil? Builtins.y2milestone( "User decided not to remove the selected product" ) @@ -1810,11 +1793,11 @@ def RunAddOnsOverviewDialog RedrawAddOnsOverviewTable() # Redrawing info widget - elsif userret == "list_of_addons" + when "list_of_addons" AdjustInfoWidget() # Calling packager directly - elsif userret == :packager + when :packager Builtins.y2milestone("Calling packager...") RunPackageSelector() @@ -1867,10 +1850,10 @@ def activate_addon_changes(sources_before) # BNC #468449 # It may happen that the add-on control file contains some code that # would drop the changes made, so it's better to save the soruces now - if Mode.normal - Builtins.y2milestone("Saving all sources") - Pkg.SourceSaveAll - end + return unless Mode.normal + + Builtins.y2milestone("Saving all sources") + Pkg.SourceSaveAll end # Display the media type selection dialog, in the offline mode it is skipped @@ -1909,9 +1892,7 @@ def media_type_selection # @return [Boolean] `true` if the addons should be offered automatically # def offer_media_addons? - if !AddOnProduct.add_on_products.empty? || !Stage.initial || !Y2Packager::MediumType.offline? - return false - end + return false if !AddOnProduct.add_on_products.empty? || !Stage.initial || !Y2Packager::MediumType.offline? # check the registration status, be careful that the registration might be # missing in the inst-sys (like on the openSUSE Leap media) @@ -1928,6 +1909,7 @@ def offer_media_addons? # @return [String] a human readable product name def ui_product_name(product) return _("Unknown product") unless product + [product.display_name, product.name, _("Unknown product")].reject(&:empty?).first end @@ -1936,7 +1918,8 @@ def ui_product_name(product) # @return [String] a human readable product name or the original ID if not found def product_label(product) selected_product = Y2Packager::Resolvable.find( - kind: :product, status: :selected, name: product).first + kind: :product, status: :selected, name: product + ).first # fallback to the internal product name selected_product&.display_name || product diff --git a/src/include/add-on/misc.rb b/src/include/add-on/misc.rb index ff6db7a..8cf717f 100644 --- a/src/include/add-on/misc.rb +++ b/src/include/add-on/misc.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - # File: # include/add-on/misc.ycp # @@ -15,8 +13,7 @@ # module Yast module AddOnMiscInclude - def initialize_add_on_misc(include_target) - + def initialize_add_on_misc(_include_target) textdomain "add-on" Yast.import "AddOnProduct" @@ -45,13 +42,13 @@ def HasInsufficientMemory ) # something is wrong - if totalmem == nil + if totalmem.nil? # using only RAM if possible - if Ops.get(meminfo, "memtotal") != nil - totalmem = Ops.get_integer(meminfo, "memtotal", 0) + totalmem = if Ops.get(meminfo, "memtotal") + Ops.get_integer(meminfo, "memtotal", 0) # can't do anything, just assume we enough else - totalmem = enough_memory + enough_memory end end @@ -68,17 +65,17 @@ def ContinueIfInsufficientMemory AddOnProduct.low_memory_already_reported = true if Popup.YesNoHeadline( - # TRANSLATORS: pop-up headline - _("Warning: Not enough memory!"), - # TRANSLATORS: pop-up question - _( - "Your system does not seem to have enough memory to use add-on products\n" + - "during installation. You can enable add-on products later when the\n" + - "system is running.\n" + - "\n" + - "Do you want to skip using add-on products?" - ) + # TRANSLATORS: pop-up headline + _("Warning: Not enough memory!"), + # TRANSLATORS: pop-up question + _( + "Your system does not seem to have enough memory to use add-on products\n" \ + "during installation. You can enable add-on products later when the\n" \ + "system is running.\n" \ + "\n" \ + "Do you want to skip using add-on products?" ) + ) Builtins.y2milestone("User decided to skip Add-Ons") AddOnProduct.skip_add_ons = true diff --git a/src/lib/add-on/clients/add-on_auto.rb b/src/lib/add-on/clients/add-on_auto.rb index 8fd0abe..3158a38 100644 --- a/src/lib/add-on/clients/add-on_auto.rb +++ b/src/lib/add-on/clients/add-on_auto.rb @@ -118,7 +118,12 @@ def change end def export - AddOnProduct.Export.merge(AddOnOthers.Export()) + res = AddOnProduct.Export.merge(AddOnOthers.Export()) + + # cleaning of empty values + res.delete_if { |_k, v| v.empty? } + + res end # Creates sources from add on products @@ -261,7 +266,7 @@ def expand_url_for(add_on, media_url) def retry_again?(product, media_url) Popup.ContinueCancel( # TRANSLATORS: The placeholders are for the product name and the URL. - _("Make the add-on \"%{name}\" available via \"%{url}\".") % { name: product, url: media_url } + format(_("Make the add-on \"%{name}\" available via \"%{url}\"."), name: product, url: media_url) ) end @@ -273,10 +278,10 @@ def report_error_for(product, media_url) error_msg = if product.nil? || product.empty? # TRANSLATORS: The placeholder is for the URL. - _("Failed to add product from \n%{url}") % { url: media_url } + format(_("Failed to add product from \n%{url}"), url: media_url) else # TRANSLATORS: The placeholders are for the product name and the URL. - _("Failed to add product \"%{name}\" from \n%{url}") % { name: product, url: media_url } + format(_("Failed to add product \"%{name}\" from \n%{url}"), name: product, url: media_url) end Report.Error(error_msg) diff --git a/src/lib/add-on/clients/inst_add-on.rb b/src/lib/add-on/clients/inst_add-on.rb index ed754f0..a6b5ff1 100644 --- a/src/lib/add-on/clients/inst_add-on.rb +++ b/src/lib/add-on/clients/inst_add-on.rb @@ -1,9 +1,7 @@ -# encoding: utf-8 - -# File: clients/inst_add-on.ycp -# Package: yast2-add-on -# Summary: Select add-on products for installation -# Authors: Jiri Srain +# File: clients/inst_add-on.ycp +# Package: yast2-add-on +# Summary: Select add-on products for installation +# Authors: Jiri Srain # require "tempfile" @@ -51,7 +49,7 @@ def main addon_opt = Linuxrc.InstallInf("addon") # the "addon" boot option is present - if addon_opt != nil + if !addon_opt.nil? missing_addons = addon_opt.split(",") - current_addons # add the add-ons just once, skip adding if all add-ons are @@ -67,12 +65,16 @@ def main ret = NetworkSetupForAddons(missing_addons) return ret if Builtins.contains([:back, :abort], ret) - plaindir, download, name, alias_ = false, true, "", "" + plaindir = false + download = true + name = "" + alias_ = "" missing_addons.each do |url| sources_before = Pkg.SourceGetCurrent(false) Builtins.y2milestone("Sources before adding new one: %1", sources_before) next if instsys_dvd?(url) && !AddOnProduct.AskForCD(url, name) + createSourceImpl(url, plaindir, download, name, alias_) activate_addon_changes(sources_before) @@ -124,23 +126,22 @@ def NetworkSetupForAddons(addon_urls) # is this CD/DVD/HDD installation? if Builtins.contains( - local_protocols, - Builtins.tolower(Linuxrc.InstallInf("InstMode")) - ) + local_protocols, + Builtins.tolower(Linuxrc.InstallInf("InstMode")) + ) # is there any remote addon requiring network setup? network_needed = false Builtins.foreach(addon_urls) do |url| # is it a remote protocol? if !Builtins.contains( - local_protocols, - Builtins.tolower(Ops.get_string(URL.Parse(url), "scheme", "")) - ) + local_protocols, + Builtins.tolower(Ops.get_string(URL.Parse(url), "scheme", "")) + ) network_needed = true raise Break end end - if network_needed # check and setup network ret = Convert.to_symbol(WFM.CallFunction("inst_network_check", [])) @@ -182,6 +183,7 @@ def instsys_dvd?(url) # determined (for instance, when using a network based installation media) def instsys_device return @instsys_device if @instsys_device + @instsys_device = devices_from_url(InstURL.installInf2Url).first end @@ -196,14 +198,15 @@ def devices_from_url(url) parsed = URL.Parse(url) params = URL.MakeMapFromParams(parsed["query"]) return [] unless params["devices"] + devices = params["devices"].split(",") # MakeMapFromParams unescapes %2C devices.each_with_object([]) do |device, all| - begin - # File.realpath resolves symlinks (e.g. /dev/by-* to real devices like /dev/srX) - all << File.realpath(device) - rescue Errno::ENOENT - end + + # File.realpath resolves symlinks (e.g. /dev/by-* to real devices like /dev/srX) + all << File.realpath(device) + rescue Errno::ENOENT => e + log.error "realpath failed with #{e}" end end end diff --git a/src/modules/AddOnOthers.rb b/src/modules/AddOnOthers.rb index 84f875b..b8da190 100644 --- a/src/modules/AddOnOthers.rb +++ b/src/modules/AddOnOthers.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 require "yast" require "y2packager/resolvable" @@ -8,7 +7,6 @@ module Yast # Usually custom or 3rd party repositories. class AddOnOthersClass < Module - include Yast::Logger # add_on_others = [ @@ -39,7 +37,7 @@ def Read installed_src_ids = installed_available_products.map(&:source).uniq other_repo_ids = Pkg.SourceGetCurrent(true) - installed_src_ids - @add_on_others = other_repo_ids.map{ |id| Pkg.SourceGeneralData(id) } + @add_on_others = other_repo_ids.map { |id| Pkg.SourceGeneralData(id) } end # Returns all enabled user added repos which are not base products or add-on products. @@ -77,4 +75,3 @@ def Export AddOnOthers = AddOnOthersClass.new AddOnOthers.main end - diff --git a/test/add-on-workflow_test.rb b/test/add-on-workflow_test.rb old mode 100644 new mode 100755 index 40c390e..a3f6c22 --- a/test/add-on-workflow_test.rb +++ b/test/add-on-workflow_test.rb @@ -39,14 +39,14 @@ class AddOnAddOnWorkflowIncludeTest expect(Yast::SourceDialogs).to receive(:SetURL) subject.media_type_selection end - + it "returns the :finish symbol" do expect(subject.media_type_selection).to eq(:finish) subject.media_type_selection end end - + context "registered" do let(:registered?) { true } @@ -55,7 +55,7 @@ class AddOnAddOnWorkflowIncludeTest expect(Yast::SourceDialogs).to_not receive(:SetURL) subject.media_type_selection end - + it "returns the user input" do allow(subject).to receive(:TypeDialogOpts).and_return(:next) expect(subject.media_type_selection).to eq(:next) diff --git a/test/addon_others_test.rb b/test/addon_others_test.rb index 4b3d661..9ad0766 100755 --- a/test/addon_others_test.rb +++ b/test/addon_others_test.rb @@ -5,43 +5,41 @@ describe Yast::AddOnOthers do subject { Yast::AddOnOthers } - + let(:available_products) do - [ Y2Packager::Resolvable.new(kind: :product, - name: "SLE_RT", status: :available, source: 2 ), - Y2Packager::Resolvable.new(kind: :product, - name: "SLE_HPC", status: :available, source: 2 ), - Y2Packager::Resolvable.new(kind: :product, - name: "SLE_SAP", status: :available, source: 2 ), - Y2Packager::Resolvable.new(kind: :product, - name: "SLE_BCL", status: :available, source: 2 ), - Y2Packager::Resolvable.new(kind: :product, - name: "SLED", status: :available, source: 2 ), - Y2Packager::Resolvable.new(kind: :product, - name: "SUSE-Manager-Server", status: :available, source: 2 ), - Y2Packager::Resolvable.new(kind: :product, - name: "SUSE-Manager-Proxy", status: :available, source: 2 ), - Y2Packager::Resolvable.new(kind: :product, - name: "sle-module-desktop-applications", status: :available, source: 1 ), - Y2Packager::Resolvable.new(kind: :product, - name: "sle-module-basesystem", status: :available, source: 0 ), - Y2Packager::Resolvable.new(kind: :product, - name: "SLES", status: :available, source: 3 ), - Y2Packager::Resolvable.new(kind: :product, - name: "SLES", status: :available, source: 2 ), - Y2Packager::Resolvable.new(kind: :product, - name: "SUSE-Manager-Retail-Branch-Server", status: :available, source: 2 ) - ] + [Y2Packager::Resolvable.new(kind: :product, + name: "SLE_RT", status: :available, source: 2), + Y2Packager::Resolvable.new(kind: :product, + name: "SLE_HPC", status: :available, source: 2), + Y2Packager::Resolvable.new(kind: :product, + name: "SLE_SAP", status: :available, source: 2), + Y2Packager::Resolvable.new(kind: :product, + name: "SLE_BCL", status: :available, source: 2), + Y2Packager::Resolvable.new(kind: :product, + name: "SLED", status: :available, source: 2), + Y2Packager::Resolvable.new(kind: :product, + name: "SUSE-Manager-Server", status: :available, source: 2), + Y2Packager::Resolvable.new(kind: :product, + name: "SUSE-Manager-Proxy", status: :available, source: 2), + Y2Packager::Resolvable.new(kind: :product, + name: "sle-module-desktop-applications", status: :available, source: 1), + Y2Packager::Resolvable.new(kind: :product, + name: "sle-module-basesystem", status: :available, source: 0), + Y2Packager::Resolvable.new(kind: :product, + name: "SLES", status: :available, source: 3), + Y2Packager::Resolvable.new(kind: :product, + name: "SLES", status: :available, source: 2), + Y2Packager::Resolvable.new(kind: :product, + name: "SUSE-Manager-Retail-Branch-Server", status: :available, source: 2)] end let(:installed_products) do - [ Y2Packager::Resolvable.new(kind: :product, - name: "sle-module-desktop-applications", status: :installed, source: -1 ), - Y2Packager::Resolvable.new(kind: :product, - name: "sle-module-basesystem", status: :installed, source: -1 ), - Y2Packager::Resolvable.new(kind: :product, - name: "SLES", status: :installed, source: -1 ), - ] + [Y2Packager::Resolvable.new(kind: :product, + name: "sle-module-desktop-applications", status: :installed, source: -1), + Y2Packager::Resolvable.new(kind: :product, + name: "sle-module-basesystem", status: :installed, source: -1), + Y2Packager::Resolvable.new(kind: :product, + name: "SLES", status: :installed, source: -1)] end let(:repo_hash) do @@ -49,8 +47,7 @@ "url" => "http://xxx.url", "name" => "user_defined", "priority" => 19, - "product_dir" => "/" - } + "product_dir" => "/" } end before do @@ -59,13 +56,13 @@ allow(Y2Packager::Resolvable).to receive(:find).with(kind: :product, status: :installed) .and_return(installed_products) allow(Yast::Pkg).to receive(:SourceGetCurrent).with(true) - .and_return([0,1,2,3,4]) + .and_return([0, 1, 2, 3, 4]) end - + describe "#Read" do - + context "installed products and add-ons are available" do - + it "returns user defined repo only" do expect(Yast::Pkg).to receive(:SourceGeneralData).with(4) .and_return(repo_hash) @@ -75,22 +72,22 @@ end describe "#Export" do - + context "installed products and add-ons are available" do let(:ret) do { "media_url" => repo_hash["url"], "alias" => repo_hash["alias"], "priority" => repo_hash["priority"], "name" => repo_hash["name"], - "product_dir" => repo_hash["product_dir"] } + "product_dir" => repo_hash["product_dir"] } end - + it "returns an array of user defined repos in AY format" do allow(Yast::Pkg).to receive(:SourceGeneralData).with(4) .and_return(repo_hash) Yast::AddOnOthers.Read() - expect(Yast::AddOnOthers.Export).to eq({ "add_on_others" => [ret] }) + expect(Yast::AddOnOthers.Export).to eq("add_on_others" => [ret]) end end - end + end end diff --git a/test/repositories_include_test.rb b/test/repositories_include_test.rb index f2337a2..3be5544 100644 --- a/test/repositories_include_test.rb +++ b/test/repositories_include_test.rb @@ -40,7 +40,7 @@ def main it "refreshes all added repositories and loads the available packages" do # no initial repository, then 2 repositories added - allow(Yast::Pkg).to receive(:SourceGetCurrent).and_return([], [42,43]) + allow(Yast::Pkg).to receive(:SourceGetCurrent).and_return([], [42, 43]) expect(Yast::Pkg).to receive(:SourceRefreshNow).with(42) expect(Yast::Pkg).to receive(:SourceRefreshNow).with(43) expect(Yast::Pkg).to receive(:SourceLoad) @@ -82,7 +82,8 @@ def main it "selects the available products from the added repositories" do expect(Y2Packager::Resolvable).to receive(:find).and_return( - [Y2Packager::Resolvable.new(p1), Y2Packager::Resolvable.new(p2)]) + [Y2Packager::Resolvable.new(p1), Y2Packager::Resolvable.new(p2)] + ) expect(Yast::Pkg).to receive(:ResolvableInstall).with("product1", :product) expect(Yast::Pkg).to receive(:ResolvableInstall).with("product2", :product) @@ -91,7 +92,8 @@ def main it "ignores the products from other repositories" do expect(Y2Packager::Resolvable).to receive(:find).and_return( - [Y2Packager::Resolvable.new(p1.merge("source" => 1)), Y2Packager::Resolvable.new(p2.merge("source" => 2))]) + [Y2Packager::Resolvable.new(p1.merge("source" => 1)), Y2Packager::Resolvable.new(p2.merge("source" => 2))] + ) expect(Yast::Pkg).to_not receive(:ResolvableInstall) AddonIncludeTester.InstallProduct @@ -100,7 +102,8 @@ def main it "ignores the already selected repositories" do expect(Y2Packager::Resolvable).to receive(:find).and_return( [Y2Packager::Resolvable.new(p1.merge("status" => :selected)), - Y2Packager::Resolvable.new(p2.merge("status" => :selected))]) + Y2Packager::Resolvable.new(p2.merge("status" => :selected))] + ) expect(Yast::Pkg).to_not receive(:ResolvableInstall) AddonIncludeTester.InstallProduct diff --git a/test/test_helper.rb b/test/test_helper.rb index ee58423..735bf83 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,4 @@ -srcdir = File.expand_path("../../src", __FILE__) +srcdir = File.expand_path("../src", __dir__) y2dirs = ENV.fetch("Y2DIR", "").split(":") ENV["Y2DIR"] = y2dirs.unshift(srcdir).join(":") @@ -12,7 +12,7 @@ # # Useful for modules from different YaST packages, to avoid build dependencies def stub_module(name) - Yast.const_set name.to_sym, Class.new { def self.fake_method; end } + Yast.const_set(name.to_sym, Class.new { def self.fake_method; end }) end # Stub classes from other modules to speed up a build diff --git a/test/y2add_on/clients/add-on_auto_test.rb b/test/y2add_on/clients/add-on_auto_test.rb old mode 100644 new mode 100755 index 72d9bd1..b098d51 --- a/test/y2add_on/clients/add-on_auto_test.rb +++ b/test/y2add_on/clients/add-on_auto_test.rb @@ -9,8 +9,7 @@ describe "#import" do let(:params) do { "add_on_products" => add_on_products, - "add_on_others" => add_on_others - } + "add_on_others" => add_on_others } end context "when 'add_on_products' param is NOT given" do @@ -48,7 +47,8 @@ it "imports all add-on products given" do expect(Yast::AddOnProduct).to receive(:Import).with( - { "add_on_products" => add_on_products + add_on_others}) + "add_on_products" => add_on_products + add_on_others + ) subject.import(params) end @@ -118,7 +118,7 @@ "media_url" => "dvd:///product", "name" => "updated_repo", "priority" => 20, - "product_dir" => "", + "product_dir" => "" }, { "alias" => "valid_add_on", @@ -222,23 +222,44 @@ describe "#export" do let(:add_on_products) do - {"add_on_products"=> [ - { "product_dir"=>"/Module-Desktop-Applications", - "product"=>"sle-module-desktop-applications", - "media_url"=>"dvd:/?devices=/dev/sr1" }, - { "product_dir"=>"/Module-Basesystem", - "product"=>"sle-module-basesystem", - "media_url"=>"dvd:/?devices=/dev/sr1" } - ]} + { "add_on_products" => [ + { "product_dir" => "/Module-Desktop-Applications", + "product" => "sle-module-desktop-applications", + "media_url" => "dvd:/?devices=/dev/sr1" }, + { "product_dir" => "/Module-Basesystem", + "product" => "sle-module-basesystem", + "media_url" => "dvd:/?devices=/dev/sr1" } + ] } end - let(:add_on_others) { {"add_on_others"=>[]} } + let(:add_on_others) do + { "add_on_others" => [ + { "product_dir" => "/Module-Desktop-Applications", + "product" => "sle-module-desktop-applications", + "media_url" => "dvd:/?devices=/dev/sr1" } - it "returns add-on products and other user defined add-ons" do + ] } + end + + it "returns add-on products merged with other add-ons if they are non empty" do expect(Yast::AddOnProduct).to receive(:Export).and_return(add_on_products) expect(Yast::AddOnOthers).to receive(:Export).and_return(add_on_others) expect(subject.export).to eq(add_on_products.merge(add_on_others)) end + + it "returns just non empty type of addons" do + expect(Yast::AddOnProduct).to receive(:Export).and_return(add_on_products) + expect(Yast::AddOnOthers).to receive(:Export).and_return({}) + + expect(subject.export).to eq(add_on_products) + end + + it "returns empty hash if all types are empty" do + expect(Yast::AddOnProduct).to receive(:Export).and_return({}) + expect(Yast::AddOnOthers).to receive(:Export).and_return({}) + + expect(subject.export).to eq({}) + end end describe "#write" do