Skip to content

Commit

Permalink
Merge 79d796b into c84cd6e
Browse files Browse the repository at this point in the history
  • Loading branch information
shundhammer committed Nov 15, 2018
2 parents c84cd6e + 79d796b commit 909a1e9
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 17 deletions.
8 changes: 8 additions & 0 deletions package/yast2-packager.changes
@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Wed Nov 14 13:56:53 UTC 2018 - Stefan Hundhammer <shundhammer@suse.com>

- Support for adding online repos during installation (bsc#1112937)
- Added pop-up dialog to ask user first if he would like to add
online repos during installation and upgrade (only once)
- 4.1.13

-------------------------------------------------------------------
Fri Nov 2 15:34:01 UTC 2018 - lslezak@suse.cz

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


Name: yast2-packager
Version: 4.1.12
Version: 4.1.13
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
88 changes: 78 additions & 10 deletions src/lib/y2packager/clients/inst_productsources.rb
Expand Up @@ -87,29 +87,46 @@ module Yast
# </group>
# </metapackage>
class InstProductsourcesClient < Client
# rubocop:disable Style/ClassVars
include Yast::Logger

# too low memory for using online repositories (in MiB),
# at least 1GiB is recommended
LOW_MEMORY_MIB = 1024
# variable to set target release version ( useful during upgrade when
# we want new target in releaseversion and not old one )
RELEASEVER_ENV = "ZYPP_REPO_RELEASEVER".freeze

@@posted_low_memory_warning = false
@@ask_activate_online_repos_result = nil

def main
textdomain "packager"

if AddOnProduct.skip_add_ons
Builtins.y2milestone("Skipping module (as requested before)")
log.info("Skipping module (as requested before)")
return :auto
end

if GetInstArgs.going_back
Builtins.y2milestone("Going back...")
if GetInstArgs.going_back && Mode.update
log.info("Going back...")
ENV.delete(RELEASEVER_ENV)
return :back
end

if Mode.installation || Mode.update
if !NetworkService.isNetworkRunning
log.info("No network connection - skipping module")
return :auto
end

if !ask_activate_online_repos
log.info("Skipping module")
return :auto
end
end

@args = WFM.Args
Builtins.y2milestone("Script args: %1", @args)
log.info("Script args: #{@args}")

# similar to commandline mode but actually it's called from another YaST script
@script_noncmdline_args = {}
Expand Down Expand Up @@ -1288,7 +1305,6 @@ def SourcesDialog
# bnc #392111
Wizard.RestoreNextButton
Wizard.EnableNextButton
Wizard.DisableBackButton

# from add-ons
if @script_called_from_another
Expand Down Expand Up @@ -1679,19 +1695,71 @@ def RunMain
# with low memory (the installer may crash or freeze, see bnc#854755)
def check_memory_size
return if !Mode.installation
# less than LOW_MEMORY_MIB RAM, the 64MiB buffer is for possible
# rounding in hwinfo memory detection (bsc#1045915)
return if Yast2::HwDetection.memory >= ((LOW_MEMORY_MIB - 64) << 20)
return unless low_memory?

# Warn only once
return if @@posted_low_memory_warning

@@posted_low_memory_warning = true
Report.Warning(_("Low memory detected.\n\nUsing online repositories " \
"during initial installation with less than\n" \
"%dMiB system memory is not recommended.\n\n" \
"%d MiB system memory is not recommended.\n\n" \
"The installer may crash or freeze if the additional package data\n" \
"need too much memory.\n\n" \
"Using the online repositories later in the installed system is\n" \
"recommended in this case.") % LOW_MEMORY_MIB)
end

# Return 'true' if running on a system with low memory, 'false' if not.
#
# @return Boolean
#
def low_memory?
# less than LOW_MEMORY_MIB RAM, the 64MiB buffer is for possible
# rounding in hwinfo memory detection (bsc#1045915)
Yast2::HwDetection.memory < ((LOW_MEMORY_MIB - 64) << 20)
end

# Ask the user if he wishes to activate online repos.
# Return 'true' if the user answered "Yes", 'false' if 'No'.
#
# @return Boolean
#
def ask_activate_online_repos
if GetInstArgs.going_back && @@ask_activate_online_repos_result == false
# If the user previously answered "no" and he is now going back, give
# him a chance to change his mind when he comes here the next time
# going forward again. But for now, since we are going back, prepare to
# skip this step since otherwise it would open the full dialog which he
# has not seen before, so that would be awkward.
@@ask_activate_online_repos_result = nil
return false
end

# Ask only once
return @@ask_activate_online_repos_result unless @@ask_activate_online_repos_result.nil?

default_button = :focus_yes
msg = _("Your system has an active network connection.\n" \
"Additional software is available online.\n" \
"Would you like to activate online repositories?")

if low_memory?
msg += "\n\n"
msg += _("Since your system has less than %d MiB memory,\n" \
"there is a significant risk of running out of memory,\n" \
"and the installer may crash or freeze.\n" \
"\n" \
"Using the online repositories later in the installed\n" \
"system is recommended.") % LOW_MEMORY_MIB
default_button = :focus_no
@@posted_low_memory_warning = true
end

@@ask_activate_online_repos_result = Popup.AnyQuestion(Popup.NoHeadline,
msg, Label.YesButton, Label.NoButton, default_button)
end

# fallback when alias is not defined
def fallback_alias(url)
# create alias in form "<hostname>-<last_path_element>"
Expand Down
6 changes: 0 additions & 6 deletions test/lib/clients/inst_productsources_test.rb
Expand Up @@ -19,12 +19,6 @@
expect(client.main).to eq :auto
end

it "returns :back if going back" do
allow(Yast::GetInstArgs).to receive(:going_back).and_return(true)

expect(client.main).to eq :back
end

context "run as command line" do
before do
allow(Yast::Mode).to receive(:normal).and_return(true)
Expand Down

0 comments on commit 909a1e9

Please sign in to comment.