-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a method to PackagesUI to show libzypp's update messages
- Loading branch information
Showing
9 changed files
with
218 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require "packages/update_message" | ||
|
||
module Packages | ||
class CommitResult | ||
# Commit results coming from libzypp | ||
attr_reader :committed, :successful, :failed, :remaining, :srcremaining, :update_messages | ||
|
||
# Constructor | ||
# | ||
# @param successful [Integer] Number of commited resolvables | ||
# @param failed [Array] List of resolvables with error | ||
# @param remaining [Array] List of remaining resolvables (due to wrong media) | ||
# @param srcremaining [Array] List of kind:source remaining resolvables (due to wrong media) | ||
# @param update_messages [Array<Hash>] List of libzypp update messages. | ||
# Check .build_update_messages for more details. | ||
# | ||
# @see build_update_messages | ||
def initialize(successful, failed, remaining, srcremaining, update_messages) | ||
@successful = successful | ||
@failed = failed | ||
@remaining = remaining | ||
@srcremaining = srcremaining | ||
@update_messages = update_messages | ||
end | ||
|
||
# Construct an instance taking as input the Pkg.Commit or Pkg.PkgCommit output | ||
# | ||
# Pkg.Commit and Pkg.PkcCommit return an array with the following | ||
# elements: [successful, failed, remaining, srcremaining, update_messages]. | ||
# | ||
# @param result [Array] Result as returned by Pkg.Commit and Pkg.PkgCommit | ||
def self.from_result(result) | ||
messages = build_update_messages(result[4]) | ||
new(result[0], result[1], result[2], result[3], messages) | ||
end | ||
|
||
private | ||
|
||
# Convert an array of hash into an array of UpdateMessage objects | ||
# | ||
# Each hash contains the following keys/values: | ||
# | ||
# * solvable: solvable name (usually package names). | ||
# * text: message text. | ||
# * installationPath: path to the libzypp's file containing the message | ||
# after installation. | ||
# * currentPath: path to the libzypp's file containing the message | ||
# currently. It will differ from installationPath | ||
# when running inst-sys. | ||
# | ||
# @param messages [Array<Hash>] Hash representing a message from libzypp. | ||
# @return [Array<Packager::UpdateMessage>] List of update messages | ||
def self.build_update_messages(messages) | ||
messages.map do |msg| | ||
Packages::UpdateMessage.new(msg["solvable"], msg["text"], | ||
msg["installationPath"], msg["currentPath"]) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Packages | ||
# Represents an update message from libzypp. | ||
# | ||
# | ||
# @see https://doc.opensuse.org/projects/libzypp/HEAD/classzypp_1_1ZYppCommitResult.html#ae6883415d94d4728e3de0dc9c7c58fd5 | ||
class UpdateMessage < Struct.new(:solvable, :text, :installation_path, :current_path) | ||
# @!attribute [r] solvable | ||
# @return [String] Name of the solvable libzypp element (usually the package's name). | ||
# @!attribute [r] text | ||
# @return [String] Message's text. | ||
# @!attribute [r] installation_path | ||
# @return [String] Path to the file which contains the message in the installed system. | ||
# @!attribute [r] current_path | ||
# @return [String] Path to the file which contains the message in the running system. | ||
# While running inst-sys, it will differ from installation_path. | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require "yast" | ||
|
||
module Packages | ||
class UpdateMessagesView | ||
include Yast::I18n | ||
extend Yast::I18n | ||
|
||
def initialize(commit_results) | ||
textdomain "base" | ||
@commit_results = commit_results | ||
end | ||
|
||
# Convert a list of messages into richtext | ||
# | ||
# @param messages [Array<UpdateMessage>] List of messages | ||
# @return [String] Richtext representation of the list of messages | ||
def richtext | ||
text = "<h1>#{_("Packages messages")}</h1>" | ||
text << @commit_results.map { |m| message_to_richtext(m) }.join("<hr>") | ||
end | ||
|
||
private | ||
|
||
# Convert one message to richtext | ||
# | ||
# @return [String] Message converted to richtext | ||
def message_to_richtext(message) | ||
location = format(_("This message will be available at %s"), message.installation_path) | ||
"<h2>#{message.solvable}</h2><p><em>#{location}</em></p>" \ | ||
"<br>#{message.text.strip.gsub("\n", "<br>")}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env rspec | ||
|
||
require_relative "test_helper" | ||
require "packages/update_message" | ||
require "packages/commit_result" | ||
|
||
describe Packages::CommitResult do | ||
let(:message) do | ||
{ "solvable" => "package", | ||
"text" => "Some cool message!", | ||
"installationPath" => "/var/adm/update-messages/package-1.0", | ||
"currentPath" => "/mnt/var/adm/update-messages/package-1.0" | ||
} | ||
end | ||
|
||
let(:old_result) do | ||
[1, ['pkg1'], ['pkg2'], ['pkg3'], [message]] | ||
end | ||
|
||
describe ".from_result" do | ||
it "builds a new instance from Pkg.Commit/Pkg.PkgCommit return value" do | ||
result = Packages::CommitResult.from_result(old_result) | ||
expect(result.successful).to eq(1) | ||
expect(result.failed).to eq(['pkg1']) | ||
expect(result.remaining).to eq(['pkg2']) | ||
expect(result.srcremaining).to eq(['pkg3']) | ||
expect(result.update_messages) | ||
.to eq([Packages::UpdateMessage.new(message["solvable"], message["text"], message["installationPath"], message["currentPath"])]) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env rspec | ||
|
||
require_relative "test_helper" | ||
require "packages/update_message" | ||
require "packages/update_messages_view" | ||
|
||
describe Packages::UpdateMessagesView do | ||
subject(:view) { Packages::UpdateMessagesView.new(messages) } | ||
|
||
let(:messages) { | ||
[ | ||
Packages::UpdateMessage.new("pkg1", "message 1", "/var/adm/path-1", "/var/adm/path-1"), | ||
Packages::UpdateMessage.new("pkg2", "message 2", "/var/adm/path-2", "/var/adm/path-2") | ||
] | ||
} | ||
|
||
describe "#richtext" do | ||
it "concatenates information of all messages in a richtext string" do | ||
expect(view.richtext) | ||
.to eq("<h1>Packages messages</h1><h2>pkg1</h2><p><em>This message will be available at /var/adm/path-1</em></p><br>message 1<hr>" \ | ||
"<h2>pkg2</h2><p><em>This message will be available at /var/adm/path-2</em></p><br>message 2") | ||
end | ||
end | ||
end |