diff --git a/library/packages/src/modules/PackageAI.rb b/library/packages/src/modules/PackageAI.rb index 537982d01..06f75a8a3 100644 --- a/library/packages/src/modules/PackageAI.rb +++ b/library/packages/src/modules/PackageAI.rb @@ -29,70 +29,29 @@ # $Id$ require "yast" +Yast.import "PackagesProposal" + module Yast class PackageAIClass < Module def main textdomain "base" - @toinstall = [] - @toremove = [] - @last_op_canceled = false Yast.include self, "packages/common.rb" - - # default value of settings modified - @modified = false - end - - # Function sets internal variable, which indicates, that any - # settings were modified, to "true" - def SetModified - @modified = true - - nil - end - - # Functions which returns if the settings were modified - # @return [Boolean] settings were modified - def GetModified - @modified end - def DoInstall(packages) - packages = deep_copy(packages) - @toinstall = Convert.convert( - Builtins.union(@toinstall, packages), - from: "list", - to: "list " - ) - @toremove = Builtins.filter(@toremove) do |p| - !Builtins.contains(packages, p) + def DoInstallAndRemove(toinst, torem) + if !toinst.empty? + Yast::PackagesProposal.AddResolvables("autoyast", :package, toinst) + Yast::PackagesProposal.RemoveTaboos("autoyast", toinst) # FIXME: should be done by PackagesProposal end - @modified = true - true - end - def DoRemove(packages) - packages = deep_copy(packages) - @toremove = Convert.convert( - Builtins.union(@toremove, packages), - from: "list", - to: "list " - ) - @toinstall = Builtins.filter(@toinstall) do |p| - !Builtins.contains(packages, p) + if !torem.empty? + Yast::PackagesProposal.AddTaboos("autoyast", torem) + Yast::PackagesProposal.RemoveResolvables("autoyast", :package, torem) end - @modified = true - true - end - def DoInstallAndRemove(toinst, torem) - toinst = deep_copy(toinst) - torem = deep_copy(torem) - DoInstall(toinst) - DoRemove(torem) - @modified = true true end @@ -101,7 +60,7 @@ def Available(_package) end def Installed(package) - Builtins.contains(@toinstall, package) + PackagesProposal.GetResolvables("autoyast").include?(package) end # Is a package installed? Checks only the package name in contrast to Installed() function. @@ -144,8 +103,6 @@ def InstallKernel(_kernel_modules) publish function: :RemoveAll, type: "boolean (list )" publish function: :LastOperationCanceled, type: "boolean ()" publish variable: :modified, type: "boolean" - publish function: :SetModified, type: "void ()" - publish function: :GetModified, type: "boolean ()" publish function: :PackageInstalled, type: "boolean (string)" publish function: :PackageAvailable, type: "boolean (string)" publish function: :InstallKernel, type: "boolean (list )" diff --git a/library/packages/test/package_ai_test.rb b/library/packages/test/package_ai_test.rb new file mode 100644 index 000000000..5eaca84f8 --- /dev/null +++ b/library/packages/test/package_ai_test.rb @@ -0,0 +1,39 @@ +# Copyright (c) [2021] SUSE LLC +# +# All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2 of the GNU General Public License as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, contact SUSE LLC. +# +# 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" + +Yast.import "PackageAI" + +describe Yast::PackageAI do + subject { Yast::PackageAI } + + before do + Yast::PackagesProposal.ResetAll + end + + describe "#DoInstallAndRemove" do + it "updates the packages proposal according to the given lists" do + subject.DoInstallAndRemove(["yast2"], ["ntpd"]) + + expect(Yast::PackagesProposal.GetResolvables("autoyast", :package)).to eq(["yast2"]) + expect(Yast::PackagesProposal.GetTaboos("autoyast")).to eq(["ntpd"]) + end + end +end