Skip to content

Commit

Permalink
Decreasing required memory (#88)
Browse files Browse the repository at this point in the history
* Decreasing required memory
  • Loading branch information
schubi2 committed Nov 28, 2019
1 parent e9661d1 commit 40aadf8
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 86 deletions.
8 changes: 8 additions & 0 deletions package/yast2-add-on.changes
@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Thu Nov 21 13:36:10 UTC 2019 - schubi@suse.de

- Using Y2Packager::Resolvable.any? and Y2Packager::Resolvable.find
in order to decrease the required memory (bsc#1132650,
bsc#1140037).
- 4.2.10

-------------------------------------------------------------------
Thu Nov 21 12:36:10 UTC 2019 - David Diaz <dgonzalez@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-add-on.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-add-on
Version: 4.2.9
Version: 4.2.10
Release: 0
Summary: YaST2 - Add-On media installation code
License: GPL-2.0-only
Expand Down
15 changes: 5 additions & 10 deletions src/clients/vendor.rb
Expand Up @@ -98,18 +98,13 @@ def main
else
Pkg.TargetInit("/", false)

@products = Pkg.ResolvableProperties("", :product, "")
@products = Y2Packager::Resolvable.find(kind: :product,
status: :installed,
category: "base")
@products = [] if @products == nil
@products = Builtins.filter(@products) do |p|
Ops.get(p, "status") == :installed
end
@base = Builtins.filter(@products) do |p|
Ops.get_string(p, "category", "") == "base"
end
@base = deep_copy(@products) if Builtins.size(@base) == 0
@product = Ops.get(@base, 0, {})
@version = Ops.get_string(@product, "version", "")
@version = Ops.get(Builtins.splitstring(@version, "-"), 0, "") # split off release
@product = @base[0]
@version = @product ? @product.version_version : ""

Builtins.y2milestone("Trying %1", @cdpath)
@dirlist2 = Convert.to_list(SCR.Read(path(".target.dir"), @cdpath))
Expand Down
129 changes: 60 additions & 69 deletions src/include/add-on/add-on-workflow.rb
Expand Up @@ -354,26 +354,30 @@ def InstallProduct
return :next
end

all_products = Pkg.ResolvableProperties("", :product, "")
all_products = Y2Packager::Resolvable.find(kind: :product)
all_products.each do |product|
# Product doesn't match the new source ID
next unless @added_repos.include?(product["source"])
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"].inspect} with status " \
"#{product["status"].inspect}")
if product.status != :available
log.info("Skipping product #{product.name} with status " \
"#{product.status}")
next
end

success = Pkg.ResolvableInstall(product["name"], :product)
success = Pkg.ResolvableInstall(product.name, :product)

log.info("Selecting product '#{product["name"]}' for installation -> #{success}")
log.info("Selecting product '#{product.name}' for installation -> #{success}")
end

:next
end

def ProductSelect
# Do not use Y2Packager::Resolvable.find(kind: :product) because the
# returned Resolvables have not the variable "media".
# It is not so important because this function will be called in an
# installed system with the command "/sbin/yast2 add-on URL" only
all_products = Pkg.ResolvableProperties("", :product, "")

already_used_urls = {}
Expand Down Expand Up @@ -1185,15 +1189,17 @@ def AdjustInfoWidget
return
end

vendor = pi["product"].vendor.empty? ? _("Unknown vendor") : pi["product"].vendor
version = pi["product"].version.empty? ? _("Unknown version") : pi["product"].version
rt_description = Builtins.sformat(
"<p>%1\n%2\n%3\n%4</p>",
Builtins.sformat(
_("<b>Vendor:</b> %1<br>"),
Ops.get_locale(pi, ["product", "vendor"], _("Unknown vendor"))
vendor
),
Builtins.sformat(
_("<b>Version:</b> %1<br>"),
Ops.get_locale(pi, ["product", "version"], _("Unknown version"))
version
),
Builtins.sformat(
_("<b>Repository URL:</b> %1<br>"),
Expand Down Expand Up @@ -1268,23 +1274,21 @@ def AdjustRepositoryInfo(info)
def GetRepoInfo(this_product, all_products)
ret = { "IDs" => [], "URLs" => [], "aliases" => [] }

product_arch = Ops.get_string(this_product.value, "arch", "")
product_name = Ops.get_string(this_product.value, "name", "")
product_version = Ops.get_string(this_product.value, "version", "")
product_arch = this_product.value.arch
product_name = this_product.value.name
product_version = this_product.value.version

Builtins.foreach(all_products.value) do |one_product|
# if (one_product["status"]:`unknown != `available) return;
next if Ops.get_string(one_product, "arch", "") != product_arch
next if Ops.get_string(one_product, "name", "") != product_name
next if Ops.get_string(one_product, "version", "") != product_version
if Builtins.haskey(one_product, "source") &&
Ops.get_integer(one_product, "source", -1) != -1
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,
"IDs",
Builtins.add(
Ops.get(ret, "IDs", []),
Ops.get_integer(one_product, "source", -1)
one_product.source
)
)
end
Expand All @@ -1298,22 +1302,13 @@ def GetRepoInfo(this_product, all_products)
end

def GetAllProductsInfo
all_products = Pkg.ResolvableProperties("", :product, "")
all_products = Y2Packager::Resolvable.find(:product)

all_products = Builtins.maplist(all_products) do |one_product|
# otherwise it fills the log too much
Builtins.foreach(["license", "description"]) do |key|
if Builtins.haskey(one_product, key)
Ops.set(
one_product,
key,
Ops.add(
Builtins.substring(Ops.get_string(one_product, key, ""), 0, 40),
"..."
)
)
end
end
one_product.license = one_product.license[0..40] + "..."
one_product.description = one_product.description[0..40] + "..."

deep_copy(one_product)
end

Expand All @@ -1323,10 +1318,9 @@ def GetAllProductsInfo
def GetInstalledProducts
installed_products = Builtins.filter(GetAllProductsInfo()) do |one_product|
# Do not list the base product
next false if Ops.get_string(one_product, "category", "addon") == "base"
next false if one_product.category == "base"
# BNC #475591: Only those `installed or `selected ones should be actually visible
Ops.get_symbol(one_product, "status", :unknown) == :installed ||
Ops.get_symbol(one_product, "status", :unknown) == :selected
one_product.status == :installed || one_product.status == :selected
end

deep_copy(installed_products)
Expand All @@ -1343,22 +1337,17 @@ def GetProductInfos

Builtins.foreach(installed_products) do |one_product|
# only add-on products should be listed
if Builtins.haskey(one_product, "type") &&
Ops.get_string(one_product, "type", "addon") != "addon"
if one_product.type != "addon"
Builtins.y2milestone(
"Skipping product: %1",
Ops.get_string(
one_product,
"display_name",
Ops.get_string(one_product, "name", "")
)
one_product.display_name.empty? ? one_product.name : one_product.display_name
)
next
end
counter = Ops.add(counter, 1)
Builtins.y2milestone(
"Product: %1, Info: %2",
one_product,
one_product.name,
repository_info
)
if repository_info == nil
Expand Down Expand Up @@ -1436,8 +1425,7 @@ def ReadFromSystem
)
),
"autoyast_product" => Ops.get_locale(
product_desc,
["product", "name"],
product_desc["product"].name,
Ops.get_locale(
repo_data,
"name",
Expand All @@ -1464,7 +1452,7 @@ def RedrawAddOnsOverviewTable

products = product_infos.map do |index, product_desc|
Item(Id("product_#{index}"),
product_desc["product"]["display_name"] || product_desc["product"]["name"] || _("Unknown product"),
ui_product_name(product_desc["product"]),
product_desc["info"]["URLs"].first || _("Unknown URL")
)
end
Expand Down Expand Up @@ -1505,12 +1493,7 @@ def RemoveProductWithDependencies
return nil
end

product_name = Ops.get_locale(
pi,
["product", "display_name"],
Ops.get_locale(pi, ["product", "name"], _("Unknown product"))
)

product_name = ui_product_name(pi["product"])
if !Popup.AnyQuestion(
Label.WarningMsg,
Builtins.sformat(
Expand Down Expand Up @@ -1552,13 +1535,13 @@ def RemoveProductWithDependencies
# y2milestone ("Installed packages: %1", installed_packages);

# All packages from Add-On / Repository
packages_from_repo = Pkg.ResolvableProperties("", :package, "")
packages_from_repo = Y2Packager::Resolvable.find(kind: :package)

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,
Ops.get_integer(one_package, "source", -1)
one_package.source
)
next false
end
Expand All @@ -1567,9 +1550,9 @@ def RemoveProductWithDependencies
# "name version-release arch", "version" already contains a release
package_string = Builtins.sformat(
"%1 %2 %3",
Ops.get_string(one_package, "name", ""),
Ops.get_string(one_package, "version", ""),
Ops.get_string(one_package, "arch", "")
one_package.name,
one_package.version,
one_package.arch,
)
# The very same package (which is avaliable at the source) is also installed
Builtins.contains(installed_packages, package_string)
Expand All @@ -1582,15 +1565,15 @@ def RemoveProductWithDependencies

# Removing selected product, whatever it means
# It might remove several products when they use the same name
if (Ops.get_symbol(pi, ["product", "status"], :unknown) == :installed ||
Ops.get_symbol(pi, ["product", "status"], :unknown) == :selected) &&
Ops.get_string(pi, ["product", "name"], "") != ""
if (pi["product"].status == :installed ||
pi["product"].status == :selected) &&
pi["product"].name != ""
Builtins.y2milestone(
"Removing product: '%1'",
Ops.get_string(pi, ["product", "name"], "")
pi["product"].name
)
Pkg.ResolvableRemove(
Ops.get_string(pi, ["product", "name"], ""),
pi["product"].name,
:product
)
else
Expand Down Expand Up @@ -1636,9 +1619,9 @@ def RemoveProductWithDependencies
# "name version-release arch", "version" already contains a release
package_string = Builtins.sformat(
"%1 %2 %3",
Ops.get_string(one_package, "name", ""),
Ops.get_string(one_package, "version", ""),
Ops.get_string(one_package, "arch", "")
one_package.name,
one_package.version,
one_package.arch
)
# installed package is not available anymore
if !Builtins.contains(available_packages, package_string)
Expand All @@ -1647,21 +1630,21 @@ def RemoveProductWithDependencies
# it must be removed
Builtins.y2milestone("Removing: %1", package_string)
Pkg.ResolvableRemove(
Ops.get_string(one_package, "name", "~~~"),
one_package.name,
:package
)

# but if another version is present, select if for installation
if Builtins.contains(
available_package_names,
Ops.get_string(one_package, "name", "~~~")
one_package.name
)
Builtins.y2milestone(
"Installing another version of %1",
Ops.get_string(one_package, "name", "")
one_package.name,
)
Pkg.ResolvableInstall(
Ops.get_string(one_package, "name", ""),
one_package.name,
:package
)
end
Expand Down Expand Up @@ -1924,6 +1907,14 @@ def media_type_selection

private

# Find the human readable product name from the product
# @param [Y2Packager::Resolvable] the product
# @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

# Find the human readable product name for the product ID
# @param product [String] the product name (ID)
# @return [String] a human readable product name or the original ID if not found
Expand Down
14 changes: 8 additions & 6 deletions test/repositories_include_test.rb
Expand Up @@ -75,30 +75,32 @@ def main
end

it "returns :next" do
allow(Yast::Pkg).to receive(:ResolvableProperties).and_return([])
allow(Y2Packager::Resolvable).to receive(:find).and_return([])
allow(Yast::Pkg).to receive(:ResolvableInstall)
expect(AddonIncludeTester.InstallProduct).to eq(:next)
end

it "selects the available products from the added repositories" do
expect(Yast::Pkg).to receive(:ResolvableProperties).and_return([p1, p2])
expect(Y2Packager::Resolvable).to receive(:find).and_return(
[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)

AddonIncludeTester.InstallProduct
end

it "ignores the products from other repositories" do
expect(Yast::Pkg).to receive(:ResolvableProperties).and_return(
[p1.merge("source" => 1), p2.merge("source" => 2)])
expect(Y2Packager::Resolvable).to receive(:find).and_return(
[Y2Packager::Resolvable.new(p1.merge("source" => 1)), Y2Packager::Resolvable.new(p2.merge("source" => 2))])
expect(Yast::Pkg).to_not receive(:ResolvableInstall)

AddonIncludeTester.InstallProduct
end

it "ignores the already selected repositories" do
expect(Yast::Pkg).to receive(:ResolvableProperties).and_return(
[p1.merge("status" => :selected), p2.merge("status" => :selected)])
expect(Y2Packager::Resolvable).to receive(:find).and_return(
[Y2Packager::Resolvable.new(p1.merge("status" => :selected)),
Y2Packager::Resolvable.new(p2.merge("status" => :selected))])
expect(Yast::Pkg).to_not receive(:ResolvableInstall)

AddonIncludeTester.InstallProduct
Expand Down

0 comments on commit 40aadf8

Please sign in to comment.