Skip to content

Commit

Permalink
Update from review
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Moravec committed Dec 17, 2013
1 parent 132c1ba commit 8dcac0f
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 53 deletions.
14 changes: 11 additions & 3 deletions src/autoyast-rnc/online_update_configuration.rnc
Expand Up @@ -2,15 +2,23 @@ default namespace = "http://www.suse.com/1.0/yast2ns"
namespace a = "http://relaxng.org/ns/compatibility/annotations/1.0"
namespace config = "http://www.suse.com/1.0/configns"

online_update_configuration = element online_update_configuration { enable_automatic_online_update? & skip_interactive_patches? & auto_agree_with_licenses? & include_recommends? & update_interval? & category_filter? }
online_update_configuration =
element online_update_configuration {
enable_automatic_online_update? &
skip_interactive_patches? &
auto_agree_with_licenses? &
include_recommends? &
update_interval? &
category_filter? &
use_deltarpm?
}


enable_automatic_online_update = element enable_automatic_online_update { BOOLEAN }
skip_interactive_patches = element skip_interactive_patches { BOOLEAN }
auto_agree_with_licenses = element auto_agree_with_licenses { BOOLEAN }
include_recommends = element include_recommends { BOOLEAN }
use_delta_rpm = element use_delta_rpm { BOOLEAN }
use_deltarpm = element use_deltarpm { BOOLEAN }
update_interval = element update_interval { text }

category_filter = element category_filter { LIST, category* }
category = element category { text }
8 changes: 3 additions & 5 deletions src/clients/online_update_configuration.rb
Expand Up @@ -151,9 +151,9 @@ def main
)

UI.ChangeWidget(
Id(:use_delta_rpm),
Id(:use_deltarpm),
:Value,
OnlineUpdateConfiguration.use_delta_rpm
OnlineUpdateConfiguration.use_deltarpm
)

UI.ChangeWidget(
Expand Down Expand Up @@ -187,9 +187,7 @@ def main
UI.QueryWidget(Id(:includeRecommends), :Value)
)

OnlineUpdateConfiguration.use_delta_rpm = Convert.to_boolean(
UI.QueryWidget(Id(:use_delta_rpm), :Value)
)
OnlineUpdateConfiguration.use_deltarpm = UI.QueryWidget(Id(:use_deltarpm), :Value)

OnlineUpdateConfiguration.enableAOU = Convert.to_boolean(
UI.QueryWidget(Id(:automaticOnlineUpdate), :Value)
Expand Down
12 changes: 5 additions & 7 deletions src/clients/online_update_configuration_auto.rb
Expand Up @@ -197,10 +197,10 @@ def Summary
OnlineUpdateConfiguration.includeRecommends ? @enabledMsg : @disabledMsg
)

summary = Summary.AddHeader(summary, @use_delta_rpm)
summary = Summary.AddHeader(summary, @use_deltarpm)
summary = Summary.AddLine(
summary,
OnlineUpdateConfiguration.use_delta_rpm ? @enabledMsg : @disabledMsg
OnlineUpdateConfiguration.use_deltarpm ? @enabledMsg : @disabledMsg
)
summary = Summary.AddHeader(summary, @filterByCategory)
summary = Summary.AddLine(
Expand Down Expand Up @@ -258,9 +258,9 @@ def OUC_configure
OnlineUpdateConfiguration.includeRecommends
)
UI.ChangeWidget(
Id(:use_delta_rpm),
Id(:use_deltarpm),
:Value,
OnlineUpdateConfiguration.use_delta_rpm
OnlineUpdateConfiguration.use_deltarpm
)
UI.ChangeWidget(
Id(:category),
Expand Down Expand Up @@ -294,9 +294,7 @@ def OUC_configure
OnlineUpdateConfiguration.includeRecommends = Convert.to_boolean(
UI.QueryWidget(Id(:includeRecommends), :Value)
)
OnlineUpdateConfiguration.use_delta_rpm = Convert.to_boolean(
UI.QueryWidget(Id(:use_delta_rpm), :Value)
)
OnlineUpdateConfiguration.use_deltarpm = UI.QueryWidget(Id(:use_deltarpm), :Value)
# reset categories to disable the filter
catFilter = Convert.to_boolean(UI.QueryWidget(Id(:category), :Value))
OnlineUpdateConfiguration.currentCategories = [] if !catFilter
Expand Down
8 changes: 4 additions & 4 deletions src/include/online-update-configuration/OUCDialogs.rb
Expand Up @@ -69,7 +69,7 @@ def initialize_online_update_configuration_OUCDialogs(include_target)
@skipInteractivePatches = _("Skip Interactive Patches")
@autoAgreeWithLicenses = _("Agree with Licenses")
@includeRecommends = _("Include Recommended Packages")
@use_delta_rpm = _("Use delta rpms")
@use_deltarpm = _("Use delta rpms")
@currentUpdateRepo = _("Current Update Repository:")
@needToRegister = _(
"In order to add the default update repository\nyou have to register this product."
Expand Down Expand Up @@ -216,9 +216,9 @@ def getOUCDialog(type)
VSpacing(0.2),
Left(
CheckBox(
Id(:use_delta_rpm),
@use_delta_rpm,
OnlineUpdateConfiguration.use_delta_rpm
Id(:use_deltarpm),
@use_deltarpm,
OnlineUpdateConfiguration.use_deltarpm
)
),
VSpacing(0.8),
Expand Down
20 changes: 10 additions & 10 deletions src/lib/online-update-configuration/zypp_config.rb
@@ -1,35 +1,35 @@
class ZyppConfig
SCR_TARGET = '.etc.zypp_conf'
CONFIG_USE_DELTA_RPM = "#{SCR_TARGET}.value.main.\"download.use_deltarpm\""
CONFIG_USE_DELTA_RPM = Yast::Path.new(".etc.zypp_conf.value.main.\"download.use_deltarpm\"")

def initialize
@use_deltarpm = true
current_config = get_delta_rpm_config_value
# Default config for delta rpms in zypp.conf is true
@use_delta_rpm = current_config == nil || current_config == 'true'
@use_deltarpm = !['0', 'no', 'false', 'off', '-'].include?(current_config.downcase) if current_config
end

def use_delta_rpm?
@use_delta_rpm
def use_deltarpm?
@use_deltarpm
end

def activate_delta_rpm
def activate_deltarpm
Yast::Builtins.y2milestone("Activating delta rpms for online update..")
set_delta_rpm_config_value(true)
end

def deactivate_delta_rpm
def deactivate_deltarpm
Yast::Builtins.y2milestone("Deactivating delta rpms for online update..")
set_delta_rpm_config_value(false)
end

private

def set_delta_rpm_config_value new_value
return if new_value == use_delta_rpm?
Yast::SCR.Write(Yast::Path.new(CONFIG_USE_DELTA_RPM), new_value)
return if new_value == use_deltarpm?
Yast::SCR.Write(CONFIG_USE_DELTA_RPM, new_value)
end

def get_delta_rpm_config_value
Yast::SCR.Read(Yast::Path.new(CONFIG_USE_DELTA_RPM))
Yast::SCR.Read(CONFIG_USE_DELTA_RPM)
end
end
14 changes: 5 additions & 9 deletions src/modules/OnlineUpdateConfiguration.rb
Expand Up @@ -48,7 +48,7 @@ def main
@skipInteractivePatches = true
@autoAgreeWithLicenses = false
@includeRecommends = false
@use_delta_rpm = zypp_config.use_delta_rpm?
@use_deltarpm = zypp_config.use_deltarpm?
@updateInterval = :weekly
@currentCategories = []
@OUCmodified = false
Expand Down Expand Up @@ -587,11 +587,7 @@ def Import(settings)
"include_recommends",
@includeRecommends
)
@use_delta_rpm = Ops.get_boolean(
settings,
"use_delta_rpm",
@use_delta_rpm
)
@use_deltarpm = settings.fetch('use_deltarpm', @use_deltarpm)
@currentCategories = Convert.convert(
Ops.get(settings, ["category_filter", "category"], @currentCategories),
:from => "any",
Expand Down Expand Up @@ -627,7 +623,7 @@ def Write
path(".sysconfig.automatic_online_update.AOU_INCLUDE_RECOMMENDS"),
@includeRecommends == true ? "true" : "false"
)
@use_delta_rpm ? zypp_config.activate_delta_rpm : zypp_config.deactivate_delta_rpm
@use_deltarpm ? zypp_config.activate_deltarpm : zypp_config.deactivate_deltarpm
catConf = ""
if Ops.greater_than(Builtins.size(@currentCategories), 0)
catConf = Builtins.mergestring(@currentCategories, " ")
Expand Down Expand Up @@ -664,7 +660,7 @@ def Export
"skip_interactive_patches" => @skipInteractivePatches,
"auto_agree_with_licenses" => @autoAgreeWithLicenses,
"include_recommends" => @includeRecommends,
"use_delta_rpm" => @use_delta_rpm,
"use_deltarpm" => @use_deltarpm,
"update_interval" => intervalSymbolToString(
@updateInterval,
:name
Expand All @@ -677,7 +673,7 @@ def Export
publish :variable => :skipInteractivePatches, :type => "boolean"
publish :variable => :autoAgreeWithLicenses, :type => "boolean"
publish :variable => :includeRecommends, :type => "boolean"
publish :variable => :use_delta_rpm, :type => "boolean"
publish :variable => :use_deltarpm, :type => "boolean"
publish :variable => :updateInterval, :type => "symbol"
publish :variable => :currentCategories, :type => "list <string>"
publish :variable => :OUCmodified, :type => "boolean"
Expand Down
47 changes: 32 additions & 15 deletions test/zypp_config_test.rb
Expand Up @@ -3,31 +3,48 @@
require_relative 'test_helper'

describe ZyppConfig do
attr_reader :config
describe "#use_deltarpm?" do
it "returns true if explicitly activated" do
ZyppConfig.any_instance.stub(:get_delta_rpm_config_value).and_return('true')
expect(ZyppConfig.new.use_deltarpm?).to eq(true)

it "provides config value for delta rpms if explicitly activated" do
ZyppConfig.any_instance.stub(:get_delta_rpm_config_value).and_return('true')
expect(ZyppConfig.new.use_delta_rpm?).to eq(true)
end
ZyppConfig.any_instance.stub(:get_delta_rpm_config_value).and_return('yes')
expect(ZyppConfig.new.use_deltarpm?).to eq(true)

it "provides config value for delta rpms if using default settings" do
ZyppConfig.any_instance.stub(:get_delta_rpm_config_value).and_return(nil)
expect(ZyppConfig.new.use_delta_rpm?).to eq(true)
end
ZyppConfig.any_instance.stub(:get_delta_rpm_config_value).and_return('1')
expect(ZyppConfig.new.use_deltarpm?).to eq(true)
end

it "returns true if using default configuration" do
ZyppConfig.any_instance.stub(:get_delta_rpm_config_value).and_return(nil)
expect(ZyppConfig.new.use_deltarpm?).to eq(true)
end

it "returns false if explicitly deactivated" do
ZyppConfig.any_instance.stub(:get_delta_rpm_config_value).and_return('false')
expect(ZyppConfig.new.use_deltarpm?).to eq(false)

ZyppConfig.any_instance.stub(:get_delta_rpm_config_value).and_return('no')
expect(ZyppConfig.new.use_deltarpm?).to eq(false)

it "provides config value for delta rpms if explicitly deactivated" do
ZyppConfig.any_instance.stub(:get_delta_rpm_config_value).and_return('false')
expect(ZyppConfig.new.use_delta_rpm?).to eq(false)
ZyppConfig.any_instance.stub(:get_delta_rpm_config_value).and_return('0')
expect(ZyppConfig.new.use_deltarpm?).to eq(false)
end
end

it "can activate and deactivate use of delta rpms in zypp config" do
it "can activate delta rpm option in zypp config" do
ZyppConfig.any_instance.stub(:get_delta_rpm_config_value)
ZyppConfig.any_instance.stub(:set_delta_rpm_config_value)
config = ZyppConfig.new
expect(config).to receive(:set_delta_rpm_config_value).with(true)
expect(config.activate_delta_rpm)
expect(config.activate_deltarpm)
end

it "can deactivate delta rpm option in zypp config" do
ZyppConfig.any_instance.stub(:get_delta_rpm_config_value)
ZyppConfig.any_instance.stub(:set_delta_rpm_config_value)
config = ZyppConfig.new
expect(config).to receive(:set_delta_rpm_config_value).with(false)
expect(config.deactivate_delta_rpm)
expect(config.deactivate_deltarpm)
end
end

0 comments on commit 8dcac0f

Please sign in to comment.