Skip to content

Commit

Permalink
Merge 36b09a0 into 80b8040
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Jul 2, 2015
2 parents 80b8040 + 36b09a0 commit 1250d53
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 13 deletions.
127 changes: 127 additions & 0 deletions src/clients/migration_proposal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# encoding: utf-8

# ------------------------------------------------------------------------------
# Copyright (c) 2015 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.
#
# ------------------------------------------------------------------------------
#

module Yast
# migration proposal client
class MigrationProposalClient < Client
include Yast::Logger

# run the proposal
# @return [Hash] the proposal result
def main
init

func = WFM.Args(0)
log.info "Proposal function: #{func}"
ret = handle_function(func)

log.info "Migration proposal result: #{ret.inspect}"
ret
end

private

# initialize the client
def init
Yast.import "Pkg"
Yast.import "HTML"
Yast.import "Packages"
Yast.import "SpaceCalculation"
Yast.import "Popup"
Yast.import "Update"

textdomain "migration"
end

# handle the requested proposal function
# @param [String] func the proposal function
# @return [Hash] the proposal result
def handle_function(func)
case func
when "MakeProposal"
propose
when "AskUser"
ask_user
when "Description"
description
else
log.error "Unknown function: #{func.inspect}"
end
end

# proposal help text
# @return [String] help text
def help
# TRANSLATORS: help text
_(
"<p>This is an overview of the product migration.</p>\n"
)
end

# the proposal description
# @return [Hash] proposal result
def description
{
# TRANSLATORS: a summary heading
"rich_text_title" => _("Migration Summary"),
# TRANSLATORS: a menu entry
"menu_title" => _("&Migration Summary"),
"id" => "migration_proposal"
}
end

# handle the user feedback
# @return [Hash] proposal result
def ask_user
# TRANSLATORS: popup message
Popup.Message(_("There is nothing to configure."))
# optimization: return :abort to avoid complete propsal re-evaluation
{ "workflow_sequence" => :abort }
end

# propose migration - return migration summary
# @return [Hash] proposal result
def propose
# report dependency issues in the Packages proposal
Pkg.PkgSolve(true)
Update.solve_errors = Pkg.PkgSolveErrors

# recalculate the disk space usage data
SpaceCalculation.GetPartitionInfo

products = Pkg.ResolvableProperties("", :product, "")

ret = {
"preformatted_proposal" => product_summary(products),
"help" => help
}

ret.merge(Packages.product_update_warning(products))
end

# @param [Array<Hash>] products the current libzypp products
# @return [String] product summary text (RichText)
def product_summary(products)
summary_text = Packages.product_update_summary(products).map do |item|
"<li>#{item}</li>"
end

HTML.ListStart + summary_text.join + HTML.ListEnd
end
end
end

Yast::MigrationProposalClient.new.main
5 changes: 1 addition & 4 deletions src/lib/migration/main_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ def restore_state
end

def repositories
ret = Yast::WFM.CallFunction("repositories")
Yast::Pkg.SourceLoad if ret != :abort

ret
Yast::WFM.CallFunction("migration_repos")
end

def proposals
Expand Down
2 changes: 1 addition & 1 deletion src/lib/migration/proposal_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ProposalStore < Installation::ProposalStore
include Yast::Logger
include Yast::I18n

PROPOSAL_NAMES = ["update_proposal"]
PROPOSAL_NAMES = ["migration_proposal", "packages_proposal"]
PROPOSAL_PROPERTIES = {
"enable_skip" => "false"
}
Expand Down
7 changes: 1 addition & 6 deletions test/main_workflow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def mock_client(name, res)
end

before do
mock_client("repositories", :next)
mock_client("migration_repos", :next)
mock_client(["migration_proposals", [{ "hide_export" => true }]], :next)
mock_client("inst_prepareprogress", :next)
mock_client("inst_kickoff", :next)
Expand All @@ -65,11 +65,6 @@ def mock_client(name, res)
expect(::Migration::MainWorkflow.run).to eq :next
end

it "reload sources if click next on repositories" do
expect(Yast::Pkg).to receive(:SourceLoad)
::Migration::MainWorkflow.run
end

it "restores repositories when clicking on Cancel" do
expect(Yast::Update).to receive(:clean_backup)
expect(Yast::Update).to receive(:create_backup)
Expand Down
6 changes: 4 additions & 2 deletions test/proposal_store_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ module Yast

describe ".proposal_names" do
it "returns an update proposal" do
expect(subject.proposal_names).to eq ["update_proposal"]
expect(subject.proposal_names).to eq ["migration_proposal",
"packages_proposal"]
end
end

describe ".presentation_order" do
it "returns a presentation order" do
expect(subject.presentation_order).to eq ["update_proposal"]
expect(subject.presentation_order).to eq ["migration_proposal",
"packages_proposal"]
end
end

Expand Down

0 comments on commit 1250d53

Please sign in to comment.