Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Mar 21, 2014
1 parent d1c47aa commit a9c889e
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 76 deletions.
1 change: 1 addition & 0 deletions src/Makefile.am
Expand Up @@ -17,6 +17,7 @@ ylib_DATA = \
lib/registration/sw_mgmt.rb \
lib/registration/storage.rb \
lib/registration/repo_state.rb \
lib/registration/registration.rb \
lib/registration/helpers.rb

schemafilesdir = $(schemadir)/autoyast/rnc
Expand Down
101 changes: 28 additions & 73 deletions src/clients/inst_scc.rb
Expand Up @@ -32,6 +32,7 @@
require "registration/sw_mgmt"
require "registration/repo_state"
require "registration/storage"
require "registration/registration"

module Yast
class InstSccClient < Client
Expand Down Expand Up @@ -60,6 +61,7 @@ def main
SccApi::GlobalLogger.instance.log = Y2Logger.instance

@selected_addons = []
@registration = Registration::Registration.new

initialize_regkeys

Expand Down Expand Up @@ -97,7 +99,7 @@ def register_base_system

ret = nil

continue_buttons = [:next, :back, :close, :abort]
continue_buttons = [:next, :back, :cancel, :abort]
while !continue_buttons.include?(ret) do
ret = UI.UserInput

Expand All @@ -111,7 +113,22 @@ def register_base_system
ret = nil

catch_registration_errors do
register(email, reg_code)
product_services = Registration::Helpers::run_with_feedback(_("Registering the System..."), _("Contacting the SUSE Customer Center server")) do
@registration.register(email, reg_code)
end

# then register the product(s)
products = ::Registration::SwMgmt.products_to_register
product_services = Registration::Helpers::run_with_feedback(n_("Registering Product...", "Registering Products...", products.size), _("Contacting the SUSE Customer Center server")) do
@registration.register_products(products)
end

# remember the base products for later (to get the respective addons)
::Registration::Storage::BaseProducts.instance.products = products

# select repositories to use in installation (e.g. enable/disable Updates)
select_repositories(product_services) if Mode.installation

return :next
end
end
Expand Down Expand Up @@ -161,72 +178,6 @@ def catch_registration_errors(&block)
end
end

def register(email, reg_code)
@scc = SccApi::Connection.new(email, reg_code)

# set the current language to receive translated error messages
@scc.language = ::Registration::Helpers.language

reg_url = ::Registration::Helpers.registration_url

if reg_url
log.info "Using custom registration URL: #{reg_url.inspect}"
@scc.url = reg_url
end

# announce (register the system) first
@credentials = Registration::Helpers::run_with_feedback(_("Registering the System..."), _("Contacting the SUSE Customer Center server")) do
@scc.announce
end

# ensure the zypp config directories are writable in inst-sys
::Registration::SwMgmt.zypp_config_writable!

# write the global credentials
@credentials.write

# then register the product(s)
products = ::Registration::SwMgmt.products_to_register
register_products(products)

# remember the base products for later (to get the respective addons)
::Registration::Storage::BaseProducts.instance.products = products
end

def register_products(products)
product_services = Registration::Helpers::run_with_feedback(n_("Registering Product...", "Registering Products...", products.size), _("Contacting the SUSE Customer Center server")) do
products.map do |product|
log.info("Registering product: #{product["name"]}")

begin
orig_reg_code = @scc.reg_code
# use product specific reg. key (e.g. for addons)
@scc.reg_code = product["reg_key"] if product["reg_key"]

ret = @scc.register(product)
ensure
# restore the original base product key
@scc.reg_code = orig_reg_code
end

ret
end
end

log.info "registered product_services: #{product_services.inspect}"

if !product_services.empty?
add_product_services(product_services)

# select repositories to use in installation (e.g. enable/disable Updates)
select_repositories(product_services) if Mode.installation
end
end

def add_product_services(product_services)
::Registration::SwMgmt.add_services(product_services, @credentials)
end

# content for the main registration dialog
def scc_credentials_dialog
VBox(
Expand Down Expand Up @@ -540,10 +491,7 @@ def get_available_addons
@available_addons = Registration::Helpers::run_with_feedback(_("Loading Available Add-on Products and Extensions..."),
_("Contacting the SUSE Customer Center server")) do

# extensions for base product
::Registration::Storage::BaseProducts.instance.products.reduce([]) do |acc, product|
acc.concat(@scc.extensions_for(product["name"]).extensions)
end
@registration.get_addon_list
end

log.info "Received product extensions: #{@available_addons}"
Expand Down Expand Up @@ -608,7 +556,13 @@ def register_selected_addons
end

catch_registration_errors do
register_products(products)
product_services = Registration::Helpers::run_with_feedback(n_("Registering Product...", "Registering Products...", products.size), _("Contacting the SUSE Customer Center server")) do
@registration.register_products(products)
end

# select repositories to use in installation (e.g. enable/disable Updates)
select_repositories(product_services) if Mode.installation

return true
end

Expand Down Expand Up @@ -683,6 +637,7 @@ def start_workflow
"ws_start" => "register",
"register" => {
:abort => :abort,
:cancel => :abort,
:skip => :next,
:next => "select_addons"
},
Expand Down
4 changes: 2 additions & 2 deletions src/lib/registration/helpers.rb
Expand Up @@ -111,10 +111,10 @@ def self.service_description(service)
end

def self.run_with_feedback(header, label, &block)
Popup.ShowFeedback(header, label)
Yast::Popup.ShowFeedback(header, label)
yield
ensure
Popup.ClearFeedback
Yast::Popup.ClearFeedback
end

def self.run_network_configuration
Expand Down
98 changes: 98 additions & 0 deletions src/lib/registration/registration.rb
@@ -0,0 +1,98 @@
# encoding: utf-8

# ------------------------------------------------------------------------------
# Copyright (c) 2014 SUSE LLC
#
# 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 Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail, you may find
# current contact information at www.novell.com.
# ------------------------------------------------------------------------------
#

require "scc_api"
require "yast"

require "registration/helpers"
require "registration/sw_mgmt"
require "registration/storage"

module Registration
class Registration
include Yast::Logger

attr_reader :scc, :credentials

def register(email, reg_code)
@scc = SccApi::Connection.new(email, reg_code)

# set the current language to receive translated error messages
@scc.language = ::Registration::Helpers.language

reg_url = ::Registration::Helpers.registration_url

if reg_url
log.info "Using custom registration URL: #{reg_url.inspect}"
@scc.url = reg_url
end

# announce (register the system) first
@credentials = @scc.announce

# ensure the zypp config directories are writable in inst-sys
::Registration::SwMgmt.zypp_config_writable!

# write the global credentials
@credentials.write
end


def register_products(products)
product_services = products.map do |product|
log.info("Registering product: #{product["name"]}")

begin
orig_reg_code = @scc.reg_code
# use product specific reg. key (e.g. for addons)
@scc.reg_code = product["reg_key"] if product["reg_key"]

ret = @scc.register(product)
ensure
# restore the original base product key
@scc.reg_code = orig_reg_code
end

ret
end

log.info "registered product_services: #{product_services.inspect}"

if !product_services.empty?
add_product_services(product_services)
end

product_services
end

def add_product_services(product_services)
::Registration::SwMgmt.add_services(product_services, @credentials)
end

def get_addon_list
# extensions for base product
::Registration::Storage::BaseProducts.instance.products.reduce([]) do |acc, product|
acc.concat(@scc.extensions_for(product["name"]).extensions)
end
end

end
end
2 changes: 1 addition & 1 deletion src/lib/registration/sw_mgmt.rb
Expand Up @@ -71,7 +71,7 @@ def self.zypp_config_writable!

def self.products_to_register
# just for debugging:
# return [{"name" => "SLES", "arch" => "x86_64", "version" => "12-1.47"}]
return [{"name" => "SLES", "arch" => "x86_64", "version" => "12-1.47"}]

# during installation the products are :selected,
# on a running system the products are :installed
Expand Down

0 comments on commit a9c889e

Please sign in to comment.