Skip to content

Commit

Permalink
Merge e00f78a into 7f793e0
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Nov 14, 2016
2 parents 7f793e0 + e00f78a commit 9a87dc4
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 1 deletion.
8 changes: 8 additions & 0 deletions package/yast2-packager.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Mon Nov 14 11:40:56 UTC 2016 - lslezak@suse.cz

- Software proposal: display an error when a package or a pattern
required by YaST has been deselected by user, implement a generic
solution for bsc#885496
- 3.2.6

-------------------------------------------------------------------
Mon Oct 24 14:54:59 CEST 2016 - schubi@suse.de

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-packager.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-packager
Version: 3.2.5
Version: 3.2.6
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
60 changes: 60 additions & 0 deletions src/modules/Packages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,19 @@ def Summary(flags, use_cache)
end
end

# Check the YaST required packages.
missing_resolvables = check_missing_resolvables
if !missing_resolvables.empty?
texts = missing_resolvables.map{ |type, list| format_missing_resolvables(type, list) }
texts << _("Please manually select the needed items to install.")

# include the existing warning if defined
texts.unshift(ret["warning"]) if ret["warning"]

ret["warning"] = texts.join("<br>")
ret["warning_level"] = :blocker
end

# add failed mounts
ret = AddFailedMounts(ret)

Expand Down Expand Up @@ -2766,6 +2779,53 @@ def kept_products(products)
def has_window_manager?
Pkg.IsSelected("windowmanager") || Pkg.IsProvided("windowmanager")
end

# Check whether all packages needed by YaST will be installed (the user can
# override the YaST settings)
# @return [Hash<Symbol,Array<String>>] The key is resolvable type (:pattern or
# :package), the value is list of names.
# If nothing is missing an empty Hash is returned.
def check_missing_resolvables
missing = {}
proposed = PackagesProposal.GetAllResolvablesForAllTypes

proposed.each do |type, list|
list.each do |item|
statuses = Pkg.ResolvableProperties(item, type, "")

# :selected = selected to install/update, :installed = keep installed (at upgrade)
if statuses.nil? || !statuses.find { |s| s["status"] == :selected || s["status"] == :installed }
missing[type] = [] unless missing[type]
# use quoted "summary" value for patterns as they usually contain spaces
name = (type == :pattern) ? statuses.first["summary"].inspect : item
missing[type] << name
end
end
end

missing
end

# Build a human readable string describing missing resolvables.
# @param [Symbol] type resolvable type, either :pattern or :packages
# @param [Array<String>] list of names
# @return [String] Translated message containing missing resolvables
def format_missing_resolvables(type, list)
list_str = list.join(", ")

case type
when :package
# TRANSLATORS: %s is a package list
_("These packages need to be selected to install: %s") % list_str
when :pattern
# TRANSLATORS: %s is a pattern list
_("These patterns need to be selected to install: %s") % list_str
else
# TRANSLATORS: %{type} is a resolvable type, %{list} is a list of names
# This is a fallback message for unknown types, normally it should not be displayed
_("These items (%{type}) need to be selected to install: %{list}") % {type: type, list: list}
end
end
end

Packages = PackagesClass.new
Expand Down
59 changes: 59 additions & 0 deletions test/packages_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -993,4 +993,63 @@ def product(properties = {})
end
end

describe "#Summary" do
before do
# mock disk space calculation
allow(subject).to receive(:CheckDiskSize).and_return(true)
allow(Yast::SpaceCalculation).to receive(:CheckDiskFreeSpace).and_return([])
allow(Yast::SpaceCalculation).to receive(:GetFailedMounts).and_return([])

allow(Yast::PackagesProposal).to receive(:GetAllResolvablesForAllTypes)
.and_return({package: ["grub2"], pattern: ["kde"]})
end

context "YaST preselected items are deselected by user" do
before do
expect(Yast::Pkg).to receive(:ResolvableProperties).with("grub2", :package, "")
.and_return(["status" => :available])
expect(Yast::Pkg).to receive(:ResolvableProperties).with("kde", :pattern, "")
.and_return(["status" => :available, "summary" => "KDE Desktop Environment"])
end

it "Reports missing pre-selected packages" do
summary = subject.Summary([:package], false)
expect(summary["warning"]).to include("grub2")
end

it "Reports missing pre-selected patterns" do
summary = subject.Summary([:package], false)
expect(summary["warning"]).to include("KDE Desktop Environment")
end

it "Installation/upgrade is blocked" do
summary = subject.Summary([:package], false)
expect(summary["warning_level"]).to eq(:blocker)
end
end

context "YaST preselected items are not deselected by user" do
before do
expect(Yast::Pkg).to receive(:ResolvableProperties).with("grub2", :package, "")
.and_return(["status" => :selected])
expect(Yast::Pkg).to receive(:ResolvableProperties).with("kde", :pattern, "")
.and_return(["status" => :selected])
end

it "Does not report missing pre-selected packages" do
summary = subject.Summary([:package], false)
expect(summary["warning"]).to be_nil
end

it "Does not report missing pre-selected patterns" do
summary = subject.Summary([:package], false)
expect(summary["warning"]).to be_nil
end

it "Installation/upgrade is not blocked" do
summary = subject.Summary([:package], false)
expect(summary["warning_level"]).to_not eq(:blocker)
end
end
end
end

0 comments on commit 9a87dc4

Please sign in to comment.