Skip to content

Commit

Permalink
PackageAI relies on the PackagesProposal
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Nov 26, 2021
1 parent e510b1f commit d5cc5c8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 53 deletions.
63 changes: 10 additions & 53 deletions library/packages/src/modules/PackageAI.rb
Expand Up @@ -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 <string>"
)
@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 <string>"
)
@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

Expand All @@ -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.
Expand Down Expand Up @@ -144,8 +103,6 @@ def InstallKernel(_kernel_modules)
publish function: :RemoveAll, type: "boolean (list <string>)"
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 <string>)"
Expand Down
39 changes: 39 additions & 0 deletions 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

0 comments on commit d5cc5c8

Please sign in to comment.