Skip to content

Commit

Permalink
update rubocop and run rubocop -a
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed May 31, 2024
1 parent 5c48651 commit d03c2f6
Show file tree
Hide file tree
Showing 102 changed files with 407 additions and 424 deletions.
10 changes: 5 additions & 5 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# use the shared Yast defaults
inherit_from:
/usr/share/YaST2/data/devtools/data/rubocop_yast_style.yml
/usr/share/YaST2/data/devtools/data/rubocop-1.24.1_yast_style.yml

AllCops:
TargetRubyVersion: 2.3
TargetRubyVersion: 2.7

Style/FrozenStringLiteralComment:
Enabled: false
Expand All @@ -24,7 +24,7 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Max: 25

Metrics/LineLength:
Layout/LineLength:
Max: 100

# TODO: this need some non-trivial refactoring...
Expand All @@ -42,7 +42,7 @@ Lint/ShadowedException:
- 'src/lib/registration/connect_helpers.rb'

# Offense count: 5
Style/AccessorMethodName:
Naming/AccessorMethodName:
Enabled: false

# Offense count: 29
Expand All @@ -51,7 +51,7 @@ Style/Documentation:

# Offense count: 1
# Configuration parameters: NamePrefix, NamePrefixBlacklist.
Style/PredicateName:
Naming/PredicateName:
Enabled: false

# Let lslezak decide what to do with it. In general jreidinger does not see it as such big violence of style
Expand Down
6 changes: 3 additions & 3 deletions src/bin/install_ssl_certificates
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require "registration/ssl_certificate"

dir = Registration::SslCertificate::INSTSYS_CERT_DIR
if Dir.empty?(dir)
$stderr.puts "ERROR: Empty #{dir} directory, put your SSL certificate there."
warn "ERROR: Empty #{dir} directory, put your SSL certificate there."
exit 1
end

Expand All @@ -38,7 +38,7 @@ if ENV["YAST_IS_RUNNING"] != "instsys"
if $CHILD_STATUS.success?
puts "Done"
else
$stderr.puts "Failed!"
warn "Failed!"
end

exit $CHILD_STATUS.exitstatus
Expand All @@ -49,6 +49,6 @@ puts "Updating the inst-sys SSL certificates..."
if Registration::SslCertificate.update_instsys_ca
puts "Done"
else
$stderr.puts "Failed!"
warn "Failed!"
exit 1
end
55 changes: 28 additions & 27 deletions src/clients/discover_registration_services.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@

require "yast/suse_connect"

require "registration/helpers"
require "registration/url_helpers"
require "registration/ui/regservice_selection_dialog"

module Yast
class DiscoverRegistrationServicesClient < Client
include Yast::Logger

# @return [Array<SlpServiceClass::Service>] list of candidate services
attr_reader :services
unless defined?(DiscoverRegistrationServicesClient)
class DiscoverRegistrationServicesClient < Client
include Yast::Logger

def initialize
@services = []
end
# @return [Array<SlpServiceClass::Service>] list of candidate services
attr_reader :services

def main
textdomain "registration"
@services = ::Registration::UrlHelpers.slp_discovery_feedback
services.empty? ? nil : select_registration_service
end
def initialize
@services = []
end

private
def main
textdomain "registration"
@services = ::Registration::UrlHelpers.slp_discovery_feedback
services.empty? ? nil : select_registration_service
end

def select_registration_service
service = ::Registration::UI::RegserviceSelectionDialog.run(services: services)
case service
when :scc
nil
when :cancel
:cancel
else
url = ::Registration::UrlHelpers.service_url(service.slp_url)
log.info "Selected service URL: #{url}"
url
private

def select_registration_service
service = ::Registration::UI::RegserviceSelectionDialog.run(services: services)
case service
when :scc
nil
when :cancel
:cancel
else
url = ::Registration::UrlHelpers.service_url(service.slp_url)
log.info "Selected service URL: #{url}"
url
end
end
end
end unless defined?(DiscoverRegistrationServicesClient)
end
DiscoverRegistrationServicesClient.new.main
end
118 changes: 59 additions & 59 deletions src/clients/scc.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

# ------------------------------------------------------------------------------
# Copyright (c) 2013 Novell, Inc. All Rights Reserved.
#
Expand Down Expand Up @@ -30,70 +28,72 @@
require "cgi/util"

module Yast
class SccClient < Client
include Yast::Logger

Yast.import "CommandLine"
Yast.import "Pkg"
Yast.import "Report"
Yast.import "Wizard"

def main
textdomain "registration"

if WFM.Args.include?("help")
print_help
else
Wizard.CreateDialog

begin
::Registration::SwMgmt.init

return WFM.call("inst_scc", WFM.Args)
rescue Registration::SourceRestoreError => e
retry if fix_repositories(e.message)
rescue Registration::PkgAborted => e
# Libzypp init has failed because another application
# has already locked the zypp stack. The user has already
# decided to exit the module. So nothing more has to be
# done here.
log.info "User abort..."
ensure
Wizard.CloseDialog
unless defined?(SccClient)
class SccClient < Client
include Yast::Logger

Yast.import "CommandLine"
Yast.import "Pkg"
Yast.import "Report"
Yast.import "Wizard"

def main
textdomain "registration"

if WFM.Args.include?("help")
print_help
else
Wizard.CreateDialog

begin
::Registration::SwMgmt.init

WFM.call("inst_scc", WFM.Args)
rescue Registration::SourceRestoreError => e
retry if fix_repositories(e.message)
rescue Registration::PkgAborted => e
# Libzypp init has failed because another application
# has already locked the zypp stack. The user has already
# decided to exit the module. So nothing more has to be
# done here.
log.info "User abort..."
ensure
Wizard.CloseDialog
end
end
end
end

private
private

# Print help in command line mode
def print_help
cmdline_description = {
"id" => "scc",
# Command line help text for the repository module, %1 is "SUSEconnect"
"help" => _("Use '%s' instead of this YaST module.") % "SUSEconnect"
}
# Print help in command line mode
def print_help
cmdline_description = {
"id" => "scc",
# Command line help text for the repository module, %1 is "SUSEconnect"
"help" => _("Use '%s' instead of this YaST module.") % "SUSEconnect"
}

CommandLine.Run(cmdline_description)
end
CommandLine.Run(cmdline_description)
end

# Let the user manually fix the broken repositories
# @return [Boolean] true if the repository manager was successfuly closed,
# false after pressing [Cancel]
def fix_repositories(details)
# TRANSLATORS: Error message in RichText format, %s contains the details from libzypp
Report.LongError(_("<p>The repository initialization failed. " \
"Disable (or remove) the offending service or repository " \
"in the repository manager.</p><p>Details:</p><p>%s</p>") % CGI.escapeHTML(details))

ret = WFM.call("repositories", WFM.Args)
log.info "repository manager result: #{ret}"

# drop all loaded repos, force complete reloading
Pkg.SourceFinishAll
ret == :next
# Let the user manually fix the broken repositories
# @return [Boolean] true if the repository manager was successfuly closed,
# false after pressing [Cancel]
def fix_repositories(details)
# TRANSLATORS: Error message in RichText format, %s contains the details from libzypp
Report.LongError(_("<p>The repository initialization failed. " \
"Disable (or remove) the offending service or repository " \
"in the repository manager.</p><p>Details:</p><p>%s</p>") % CGI.escapeHTML(details))

ret = WFM.call("repositories", WFM.Args)
log.info "repository manager result: #{ret}"

# drop all loaded repos, force complete reloading
Pkg.SourceFinishAll
ret == :next
end
end
end unless defined?(SccClient)
end
end

Yast::SccClient.new.main
2 changes: 0 additions & 2 deletions src/clients/scc_auto.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

# ***************************************************************************
#
# Copyright (c) 2014 SUSE LLC
Expand Down
9 changes: 5 additions & 4 deletions src/lib/registration/addon.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

# ------------------------------------------------------------------------------
# Copyright (c) 2014 SUSE LLC
#
Expand Down Expand Up @@ -58,6 +56,7 @@ def find_all(registration)
# @return [Addon,nil] The addon with the given ID or nil if it was not found
def find_by_id(id)
raise AddonsNotLoaded unless @cached_addons

@cached_addons.find { |a| a.id == id }
end

Expand Down Expand Up @@ -117,6 +116,7 @@ def registration_order(list)

loop do
break if to_process.empty?

next_addon = to_process.find do |addon|
addon.depends_on.nil? || !to_process.include?(addon.depends_on)
end
Expand Down Expand Up @@ -145,6 +145,7 @@ def create_addon_with_deps(root)
to_process.each do |(pure, dependency)|
# this avoid endless loop if there is circular dependency.
next if processed.include?(pure)

processed << pure
addon = Addon.new(pure)
result << addon
Expand Down Expand Up @@ -378,8 +379,8 @@ def self.dump_addons

require "yaml"
header = "# see " \
"https://github.com/yast/yast-registration/tree/master/devel/dump_reader.rb\n" \
"# for an example how to read this dump file\n"
"https://github.com/yast/yast-registration/tree/master/devel/dump_reader.rb\n" \
"# for an example how to read this dump file\n"
File.write("/var/log/YaST2/registration_addons.yml",
header + @cached_addons.to_yaml)
end
Expand Down
23 changes: 11 additions & 12 deletions src/lib/registration/addon_sorter.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@

module Registration
# Sorter for sorting Addons in required display order
# (first paid extensions, then free extensions, modules at the end
# see https://bugzilla.novell.com/show_bug.cgi?id=888567#c21)
# @param x [Registration::Addon] the first item to compare
# @param y [Registration::Addon] the second item to compare
ADDON_SORTER = proc do |x, y|

# if empty or nil move at the end
if x.product_type != y.product_type
begin
# if empty or nil move at the end
if !x.product_type || x.product_type.empty?
1
elsif !y.product_type || y.product_type.empty?
-1
else
# simplification: "extension" is lexicographically before "module"
# as requested in the display order so take advantage of this...
x.product_type <=> y.product_type
end
if !x.product_type || x.product_type.empty?
1
elsif !y.product_type || y.product_type.empty?
-1
else
# simplification: "extension" is lexicographically before "module"
# as requested in the display order so take advantage of this...
x.product_type <=> y.product_type
end

elsif x.free != y.free
# paid (non-free) first
x.free ? 1 : -1
Expand Down
Loading

0 comments on commit d03c2f6

Please sign in to comment.