Skip to content

Commit

Permalink
Merge f34d972 into c567782
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidner committed Mar 29, 2016
2 parents c567782 + f34d972 commit 9589746
Show file tree
Hide file tree
Showing 6 changed files with 430 additions and 1 deletion.
1 change: 1 addition & 0 deletions library/packages/src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ylibdir = "${yast2dir}/lib/packages"
ylib_DATA = \
lib/packages/commit_result.rb \
lib/packages/dummy_callbacks.rb \
lib/packages/file_conflict_callbacks.rb \
lib/packages/update_message.rb \
lib/packages/update_messages_view.rb

Expand Down
171 changes: 171 additions & 0 deletions library/packages/src/lib/packages/file_conflict_callbacks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@

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

require "yast"

module Packages
# Default file conflicts callbacks for package bindings. To register the
# callbacks in Yast::Pkg just call {Package::FileConflictCallbacks.register}
class FileConflictCallbacks
class << self
include Yast::Logger
include Yast::I18n
include Yast::UIShortcuts

# register the file conflict callbacks
def register
Yast.import "Pkg"
Yast.import "UI"
Yast.import "Progress"
Yast.import "Mode"
Yast.import "CommandLine"
Yast.import "Report"
Yast.import "Label"
Yast.import "PackageCallbacks"

textdomain "base"

register_file_conflict_callbacks
end

private

def fun_ref(*args)
Yast::FunRef.new(*args)
end

def register_file_conflict_callbacks
Yast::Pkg.CallbackFileConflictStart(fun_ref(method(:start), "void ()"))
Yast::Pkg.CallbackFileConflictProgress(fun_ref(method(:progress),
"boolean (integer)"))
Yast::Pkg.CallbackFileConflictReport(fun_ref(method(:report),
"boolean (list<string>, list<string>)"))
Yast::Pkg.CallbackFileConflictFinish(fun_ref(method(:finish), "void ()"))

nil
end

# handle the file conflict detection start callback
def start
log.info "Starting the file conflict check..."
# TRANSLATORS: progress bar label
label = _("Checking file conflicts...")

if Yast::Mode.commandline
Yast::CommandLine.PrintVerbose(label)
elsif Yast::UI.WidgetExists(:progressCurrentPackage)
# package slideshow with progress already present
Yast::UI.ChangeWidget(Id(:progressCurrentPackage), :Value, 0)
Yast::UI.ChangeWidget(Id(:progressCurrentPackage), :Label, label)
else
# TRANSLATORS: help text for the file conflict detection progress
help = _("<p>Detecting the file conflicts is in progress.</p>")
Yast::Progress.Simple(label, "", 100, help)
# Set also the progress bar widget label
Yast::Progress.Title(label)
end
end

# Handle the file conflict detection progress callback.
# @param [Fixnum] progress progress in percents
# @return [Boolean] true = continue, false = abort
def progress(progress)
log.debug "File conflict progress: #{progress}%"

if Yast::Mode.commandline
Yast::CommandLine.PrintVerboseNoCR("#{Yast::PackageCallbacksClass::CLEAR_PROGRESS_TEXT}#{progress}%")
elsif Yast::UI.WidgetExists(:progressCurrentPackage)
Yast::UI.ChangeWidget(Id(:progressCurrentPackage), :Value, progress)
else
Yast::UI.ChangeWidget(Id(:pb), :Value, progress)
end

ui = Yast::UI.PollInput unless Yast::Mode.commandline
ui != :abort && ui != :cancel
end

# Handle the file conflict detection result callback.
# Ask to user whether to continue. In the AutoYaST mode an error is reported
# but the installation will continue ignoring the confliucts.
# @param excluded_packages [Array<String>] packages ignored in the check
# (e.g. not available for check in the download-as-needed mode)
# @param conflicts [Array<String>] list of translated descriptions of
# the detected file conflicts
# @return [Boolean] true = continue, false = abort
def report(excluded_packages, conflicts)
log.info "Excluded #{excluded_packages.size} packages in file conflict check"
log.debug "Excluded packages: #{excluded_packages.inspect}"
log.info "Found #{conflicts.size} conflicts: #{conflicts.join("\n\n")}"

# just continue installing packages if there is no conflict
return true if conflicts.empty?

# don't ask in autoyast or command line mode, just report/log the issues and continue
if Yast::Mode.auto || Yast::Mode.commandline
# TRANSLATORS: An error message, %s is the actual list of detected conflicts
Yast::Report.Error(_("File conflicts detected, these conflicting files will " \
"be overwritten:\n\n%s") % conflicts.join("\n"))
return true
end

Yast::UI.OpenDialog(dialog(conflicts))

begin
Yast::UI.SetFocus(Id(:continue))
ret = Yast::UI.UserInput
log.info "User Input: #{ret}"
ret == :continue
ensure
Yast::UI.CloseDialog
end
end

# Handle the file conflict detection finish callback.
def finish
log.info "File conflict check finished"
return if Yast::Mode.commandline

Yast::Progress.Finish unless Yast::UI.WidgetExists(:progressCurrentPackage)
end

# Construct the file conflicts dialog.
# @param [Array<String>] conflicts file conflicts reported by libzypp
# (in human readable form)
# @return [Term] UI term
def dialog(conflicts)
button_box = ButtonBox(
PushButton(Id(:continue), Opt(:default, :okButton), Yast::Label.ContinueButton),
PushButton(Id(:abort), Opt(:cancelButton), Yast::Label.AbortButton)
)

# TRANSLATORS: A popup label, use max. 70 chars per line, use more lines if needed
label = _("File conflicts happen when two packages attempt to install\n" \
"files with the same name but different contents. If you continue,\n" \
"the conflicting files will be replaced losing the previous content.")

# TRANSLATORS: Popup heading
heading = n_("A File Conflict Detected", "File Conflicts Detected", conflicts.size)

VBox(
Left(Heading(heading)),
VSpacing(0.2),
Left(Label(label)),
MinSize(65, 15, RichText(Opt(:plainText), conflicts.join("\n\n"))),
button_box
)
end
end
end
end
9 changes: 9 additions & 0 deletions library/packages/src/modules/PackageCallbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
require "yast"
require "uri"
require "packages/dummy_callbacks"
require "packages/file_conflict_callbacks"

module Yast
# Provides the default Callbacks for Pkg::
Expand Down Expand Up @@ -2759,8 +2760,14 @@ def SetProgressReportCallbacks
nil
end

def SetFileConflictCallbacks
log.warn "Registering file conflict callbacks"
::Packages::FileConflictCallbacks.register
end

# Register package manager callbacks
def InitPackageCallbacks
log.warn "*** INIT Registering callbacks"
SetProcessCallbacks()

SetProvideCallbacks()
Expand All @@ -2775,6 +2782,8 @@ def InitPackageCallbacks

SetProgressReportCallbacks()

SetFileConflictCallbacks()

# authentication callback
Pkg.CallbackAuthentication(
fun_ref(
Expand Down
1 change: 1 addition & 0 deletions library/packages/test/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
TESTS = \
commit_result_test.rb \
dummy_callbacks_test.rb \
file_conflict_callbacks_test.rb \
package_callbacks_test.rb \
packages_ui_test.rb \
product_test.rb \
Expand Down

0 comments on commit 9589746

Please sign in to comment.