Skip to content

Commit

Permalink
Merge pull request #157 from yast/sort_addons
Browse files Browse the repository at this point in the history
Sort displayed addons (bnc#888567)
  • Loading branch information
lslezak committed Sep 5, 2014
2 parents 78d5375 + 50cdbed commit 8ad90d6
Show file tree
Hide file tree
Showing 14 changed files with 610 additions and 181 deletions.
10 changes: 10 additions & 0 deletions package/yast2-registration.changes
@@ -1,3 +1,13 @@
-------------------------------------------------------------------
Thu Sep 4 14:13:20 UTC 2014 - lslezak@suse.cz

- sort displayed addons to have requested order (bnc#888567)
- use the custom URL also in upgrade (bnc#894592)
- don't run SLP discovery if the system has been registered
using the public SCC server
- added missing "require" in Autoyast client (bnc#895147)
- 3.1.118

-------------------------------------------------------------------
Thu Sep 4 12:24:30 UTC 2014 - mvidner@suse.com

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


Name: yast2-registration
Version: 3.1.117
Version: 3.1.118
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
5 changes: 5 additions & 0 deletions src/clients/inst_scc.rb
Expand Up @@ -95,6 +95,8 @@ def initialize_regcodes
end

def register_base_system
log.info "The system is not registered, diplaying registration dialog"

show_scc_credentials_dialog

ret = nil
Expand Down Expand Up @@ -141,6 +143,7 @@ def register_base_system
register_base_product: !options.base_registered, disable_updates: !install_updates?)

if success
ret = :next
options.base_registered = true
# save the config if running in installed system
# (in installation/upgrade it's written in _finish client)
Expand Down Expand Up @@ -438,6 +441,8 @@ def registered_dialog
end

def display_registered_dialog
log.info "The system is already registered, displaying registered dialog"

Wizard.SetContents(
# dialog title
_("Registration"),
Expand Down
1 change: 1 addition & 0 deletions src/clients/scc_auto.rb
Expand Up @@ -32,6 +32,7 @@
require "registration/storage"
require "registration/sw_mgmt"
require "registration/registration"
require "registration/registration_ui"
require "registration/helpers"
require "registration/connect_helpers"
require "registration/ssl_certificate"
Expand Down
1 change: 1 addition & 0 deletions src/lib/registration/addon.rb
Expand Up @@ -77,6 +77,7 @@ def create_addon_with_deps(root)
:friendly_name,
:identifier,
:name,
:product_type,
:release_type,
:version

Expand Down
30 changes: 30 additions & 0 deletions src/lib/registration/addon_sorter.rb
@@ -0,0 +1,30 @@

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)
ADDON_SORTER = Proc.new do |x, y|
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
end
elsif x.free != y.free
# paid (non-free) first
x.free ? 1 : -1
else
# sort the groups by name
x.name <=> y.name
end
end

end
1 change: 1 addition & 0 deletions src/lib/registration/registration.rb
Expand Up @@ -104,6 +104,7 @@ def get_addon_list
end

def activated_products
log.info "Reading activated products..."
activated = SUSE::Connect::YaST.status(connect_params({})).activated_products || []
log.info "Activated products: #{activated.map(&:id)}"
activated
Expand Down
5 changes: 5 additions & 0 deletions src/lib/registration/ui/addon_selection_dialog.rb
@@ -1,6 +1,7 @@

require "yast"
require "registration/addon"
require "registration/addon_sorter"

module Registration
module UI
Expand Down Expand Up @@ -28,6 +29,10 @@ def self.run(registration)
def initialize(registration)
textdomain "registration"
@addons = Addon.find_all(registration)

# sort the addons
@addons.sort!(&::Registration::ADDON_SORTER)

log.info "Available addons: #{@addons}"
end

Expand Down
9 changes: 7 additions & 2 deletions src/lib/registration/url_helpers.rb
Expand Up @@ -125,6 +125,9 @@ def self.reg_url_at_installation

# get registration URL in upgrade mode
def self.reg_url_at_upgrade
custom_url = ::Registration::Storage::InstallationOptions.instance.custom_url
return custom_url if custom_url && !custom_url.empty?

# boot command line if present
boot_url = boot_reg_url
return boot_url if boot_url
Expand Down Expand Up @@ -159,8 +162,10 @@ def self.reg_url_at_runnig_system
return custom_url if custom_url && !custom_url.empty?

# check for previously saved config value
config = SUSE::Connect::Config.new
return config.url if config.url
if File.exist?(SUSE::Connect::Config::DEFAULT_CONFIG_FILE)
config = SUSE::Connect::Config.new
return config.url
end

# try SLP if not registered yet
slp_url = slp_service_url
Expand Down
30 changes: 30 additions & 0 deletions test/addon_sorter_spec.rb
@@ -0,0 +1,30 @@
#! /usr/bin/env rspec

require_relative "spec_helper"

require "yaml"
require "registration/addon"
require "registration/addon_sorter"

describe "Registration::ADDON_SORTER" do
let(:available_addons) { YAML.load_file(fixtures_file("available_addons.yml")) }
let(:unknown_addons) { YAML.load_file(fixtures_file("available_unknown_addons.yml")) }

it "sorts the addons in display order" do
expected = ["sle-ha", "sle-ha-geo", "sle-sdk", "sle-we",
"sle-module-adv-systems-management", "sle-module-legacy",
"sle-module-public-cloud", "sle-module-web-scripting"]

expect(available_addons.sort(&Registration::ADDON_SORTER).map(&:identifier)).to eql(expected)
end

it "moves the unknown product types at the end" do
# AdvMgmt and Legacy have undefined type => at the end
expected = ["sle-sdk", "sle-we", "sle-module-public-cloud",
"sle-module-web-scripting", "sle-module-legacy",
"sle-module-adv-systems-management"]

expect(unknown_addons.sort(&Registration::ADDON_SORTER).map(&:identifier)).to eql(expected)
end

end
13 changes: 13 additions & 0 deletions test/exceptions_spec.rb
@@ -0,0 +1,13 @@
#! /usr/bin/env rspec

require_relative "spec_helper"

require "registration/exceptions"

describe Registration::ServiceError do

it "is a PkgError exception" do
expect(Registration::ServiceError.new("failed", "ServiceFoo")).to be_a(Registration::PkgError)
end

end

0 comments on commit 8ad90d6

Please sign in to comment.