Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into xml_parser
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed May 14, 2020
2 parents d7fdc41 + b9acd33 commit 283f46b
Show file tree
Hide file tree
Showing 12 changed files with 870 additions and 2 deletions.
5 changes: 5 additions & 0 deletions doc/desktop_file.md
Expand Up @@ -112,3 +112,8 @@ Auto prefix:
* *X-SuSE-YaST-AutoLogResource* Specifies whether data in profile can be logged.
Useful if data contains sensitive information. Possible values are `true` and
`false`. By default `true`.

## Miscellaneous Keys

* *X-SuSE-DocTeamID* Specifies the identifier to be used when translating
the module's name. To be used by `Yast::Builtins.dpgettext`.
51 changes: 51 additions & 0 deletions library/general/src/lib/installation/autoinst_issues/issue.rb
@@ -0,0 +1,51 @@
module Installation
module AutoinstIssues
# Base class for autoinstallation problems.
#
# Installation::AutoinstIssues offers an API to register and report
# AutoYaST problems.
class Issue
include Yast::I18n

# @return [#parent,#section_name] Section where it was detected (see {AutoinstProfile})
attr_reader :section

# Return problem severity
#
# * :fatal: abort the installation.
# * :warn: display a warning.
#
# @return [Symbol] Issue severity (:warn, :fatal)
# @raise NotImplementedError
def severity
raise NotImplementedError
end

# Return the error message to be displayed
#
# @return [String] Error message
# @raise NotImplementedError
def message
raise NotImplementedError
end

# Determine whether an error is fatal
#
# This is just a convenience method.
#
# @return [Boolean]
def fatal?
severity == :fatal
end

# Determine whether an error is just a warning
#
# This is just a convenience method.
#
# @return [Boolean]
def warn?
severity == :warn
end
end
end
end
@@ -0,0 +1,154 @@
# Copyright (c) [2020] 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.

Yast.import "HTML"
Yast.import "RichText"

module Installation
module AutoinstIssues
# This class converts a list of issues into a message to be shown to users
#
# The message will summarize the list of issues, separating them into non-fatal
# and fatal issues.
class IssuesPresenter
include Yast::I18n

# @return [Installation::AutoinstIssues::List] List of issues
attr_reader :issues_list

# Constructor
#
# @param issues_list [Installation::AutoinstIssues::List] List of issues
def initialize(issues_list)
textdomain "base"
@issues_list = issues_list
end

# Return the text to be shown to the user regarding the list of issues
#
# @return [String] Plain text
def to_plain
Yast::RichText.Rich2Plain(to_html)
end

# Return the text to be shown to the user regarding the list of issues
#
# @return [String] HTML formatted text
def to_html
fatal, non_fatal = issues_list.partition(&:fatal?)

parts = []
parts << error_text(fatal) unless fatal.empty?
parts << warning_text(non_fatal) unless non_fatal.empty?
parts << Yast::HTML.Newline

parts <<
if fatal.empty?
_("Do you want to continue?")
else
_("Please, correct these problems and try again.")
end

parts.join
end

# Return warning message with a list of issues
#
# @param issues [Array<Installation::AutoinstIssues::Issue>] Array containing issues
# @return [String] Message
def warning_text(issues)
Yast::HTML.Para(
_("Minor issues were detected:")
) + issues_list_content(issues)
end

# Return error message with a list of issues
#
# @param issues [Array<Installation::AutoinstIssues::Issue>] Array containing issues
# @return [String] Message
def error_text(issues)
Yast::HTML.Para(
_("Important issues were detected:")
) + issues_list_content(issues)
end

# Return an HTML representation for a list of issues
#
# The issues are grouped by the section of the profile where they were detected.
# General issues (with no section) are listed first.
#
# @return [String] Issues list content
#
# @see issues_by_section
def issues_list_content(issues)
all_issues = []
issues_map = issues_by_section(issues)

if issues_map[:nosection]
all_issues += issues_map[:nosection].map(&:message)
issues_map.delete(:nosection)
end

issues_map.each do |section, items|
messages = Yast::HTML.List(items.map(&:message))
all_issues << "#{location(section)}:#{messages}"
end

Yast::HTML.List(all_issues)
end

# Return issues grouped by section where they were found
#
# @return [Hash<(#parent,#section_name),Installation::AutoinstIssues::Issue>]
# Issues grouped by AutoYaST profile section
def issues_by_section(issues)
issues.each_with_object({}) do |issue, all|
section = issue.section || :nosection
all[section] ||= []
all[section] << issue
end
end

# Return a human string identifying in which section was detected
#
# For instance: "drive[0] > partitions[2] > raid_options"
#
# @param section [#parent,#section_name] Section where the problem was detected
# @return [String]
#
# @see Y2Storage::AutoinstProfile
def location(section)
return section.section_name if section.parent.nil?

value = section.parent.send(section.section_name)
text =
if value.is_a?(Array)
index = value.index(section)
"#{section.section_name}[#{index + 1}]"
else
section.section_name
end

prefix = location(section.parent)
prefix << " > " unless prefix.empty?
prefix + text
end
end
end
end
90 changes: 90 additions & 0 deletions library/general/src/lib/installation/autoinst_issues/list.rb
@@ -0,0 +1,90 @@
# Copyright (c) [2020] 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 "forwardable"

module Installation
module AutoinstIssues
# List of AutoYaST problems
#
# @example Registering some partition problems
# section = PartitionSection.new({})
# list = List.new
# list.add(:missing_root)
# list.add(:invalid_value, section, :size, "auto")
#
# @example Adding a problem with additional arguments
# list = List.new
# list.add(:ay_invalid_value, "firewall", "FW_DEV_INT", "1",
# _("Is not supported anymore."))
# list.empty? #=> false
#
# @example Iterating through the list of problems
# list.map(&:severity) #=> [:warn]
class List
include Enumerable
extend Forwardable

def_delegators :@items, :each, :empty?, :<<

# Constructor
def initialize
@items = []
end

# Add a problem to the list
#
# The type of the problem is identified as a symbol which name is the
# underscore version of the class which implements it. For instance,
# `MissingRoot` would be referred as `:missing_root`.
#
# If a given type of problem requires some additional arguments, they
# should be added when calling this method. See the next example.
#
# @example Adding a problem with additional arguments
# list = List.new
# list.add(:ay_invalid_value, "firewall", "FW_DEV_INT", "1",
# _("Is not supported anymore."))
# list.empty? #=> false
#
# @param type [Symbol] Issue type
# @param extra_args [Array] Additional arguments for the given problem
# @return [Array<Issue>] List of problems
def add(type, *extra_args)
class_name = type.to_s.split("_").map(&:capitalize).join
klass = Installation::AutoinstIssues.const_get(class_name)
self << klass.new(*extra_args)
end

# Determine whether any of the problem on the list is fatal
#
# @return [Boolean] true if any of them is a fatal problem
def fatal?
any?(&:fatal?)
end

# Returns an array containing registered problems
#
# @return [Array<Issue>] List of problems
def to_a
@items
end
end
end
end

0 comments on commit 283f46b

Please sign in to comment.