Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rubocop #176

Merged
merged 6 commits into from Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 1 addition & 13 deletions .rubocop.yml
@@ -1,6 +1,6 @@
# use the shared Yast defaults
inherit_from:
/usr/share/YaST2/data/devtools/data/rubocop-0.71.0_yast_style.yml
/usr/share/YaST2/data/devtools/data/rubocop-1.24.1_yast_style.yml

Metrics/AbcSize:
Max: 129
Expand Down Expand Up @@ -65,10 +65,6 @@ Metrics/PerceivedComplexity:
Metrics/ParameterLists:
Max: 4

# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/AndOr:
EnforcedStyle: conditionals

Style/Documentation:
Include:
- 'src/lib/**/*.rb' # force well documented code only for new code
Expand All @@ -77,10 +73,6 @@ Naming/FileName:
Include:
- 'src/lib/**/*.rb' # force correct names on new code

# JR: I found lambda easier to read and understand than ->()
Style/Lambda:
Enabled: false

Naming/MethodName:
Include:
- 'src/lib/**/*.rb' # force correct names on new code
Expand All @@ -89,10 +81,6 @@ Naming/VariableName:
Include:
- 'src/lib/**/*.rb' # force known variables only for new code

# method_alias is safer and more predictable
Style/Alias:
EnforcedStyle: prefer_alias_method

# this needs more testing if we can have frozen string literals
Style/FrozenStringLiteralComment:
Enabled: false
Expand Down
16 changes: 9 additions & 7 deletions src/clients/ntp-client_proposal.rb
Expand Up @@ -521,9 +521,10 @@ def ui_handle(input)
end
when :ntp_now
rv = Write("ntpdate_only" => true)
if rv == :invalid_hostname
case rv
when :invalid_hostname
handle_invalid_hostname(UI.QueryWidget(Id(:ntp_address), :Value))
elsif rv == :success
when :success
redraw = true # update time widgets
else
Report.Error(_("Connection to selected NTP server failed."))
Expand Down Expand Up @@ -565,10 +566,11 @@ def ui_try_save
# we get [ "address", :<type> ], we need only address here
server = @sources_table.sources.first[0]
Builtins.y2milestone("ui_try_save argmap %1", argmap)
if rv == :invalid_hostname
case rv
when :invalid_hostname
handle_invalid_hostname(server)
return false # loop on
elsif rv == :ntpdate_failed
when :ntpdate_failed
# Translators: yes-no popup,
# ntpdate is a command, %1 is the server address
if Popup.YesNo(
Expand Down Expand Up @@ -649,11 +651,11 @@ def fallback_ntp_items
return @cached_fallback_ntp_items if @cached_fallback_ntp_items

@cached_fallback_ntp_items = dhcp_ntp_items
if !@cached_fallback_ntp_items.empty?
log.info("Proposing NTP server list provided by DHCP")
else
if @cached_fallback_ntp_items.empty?
log.info("Proposing current timezone-based NTP server list")
@cached_fallback_ntp_items = timezone_ntp_items
else
log.info("Proposing NTP server list provided by DHCP")
end
@cached_fallback_ntp_items
end
Expand Down
6 changes: 3 additions & 3 deletions src/include/ntp-client/wizards.rb
Expand Up @@ -25,9 +25,9 @@ def initialize_ntp_client_wizards(include_target)
# @return sequence result
def NtpClientSequence
aliases = {
"read" => [lambda { ReadDialog() }, true],
"main" => lambda { Y2NtpClient::Dialog::Main.run },
"write" => [lambda { WriteDialog() }, true]
"read" => [-> { ReadDialog() }, true],
"main" => -> { Y2NtpClient::Dialog::Main.run },
"write" => [-> { WriteDialog() }, true]
}

sequence = {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/cfa/chrony_conf.rb
Expand Up @@ -138,14 +138,14 @@ def sources(source)
when String
[entry, {}]
when AugeasTreeValue
options = Hash[entry.tree.data.map { |e| [e[:key], e[:value]] }]
options = entry.tree.data.map { |e| [e[:key], e[:value]] }.to_h
[entry.value, options]
else
raise "invalid source data #{entry.inspect}"
end
end

Hash[sources_map]
sources_map.to_h
end

def add_source(type, address, options = :default)
Expand All @@ -159,7 +159,7 @@ def add_source(type, address, options = :default)
else
# place after the last pool available
Matcher.new(key: existing.last[:key],
value_matcher: existing.last[:value])
value_matcher: existing.last[:value])
end
placer = AfterPlacer.new(matcher)

Expand Down
1 change: 1 addition & 0 deletions src/lib/y2ntp_client/client/auto.rb
Expand Up @@ -13,6 +13,7 @@ module Client
# Does not do any changes to the configuration.
class Auto < ::Installation::AutoClient
def initialize
super
textdomain "ntp-client"
end

Expand Down
1 change: 1 addition & 0 deletions src/lib/y2ntp_client/client/finish.rb
Expand Up @@ -11,6 +11,7 @@ class Finish < Installation::FinishClient
include Yast::I18n

def initialize
super
textdomain "ntp-client"
end

Expand Down
1 change: 1 addition & 0 deletions src/lib/y2ntp_client/dialog/add_pool.rb
Expand Up @@ -29,6 +29,7 @@ class AddPool < ::CWM::Popup
# @param address_widget [CWM::InputField]
# @param pool_type [Symbol]
def initialize(address_widget, pool_type)
super()
textdomain "ntp-client"

@address_widget = address_widget
Expand Down
1 change: 1 addition & 0 deletions src/lib/y2ntp_client/dialog/main.rb
Expand Up @@ -12,6 +12,7 @@ module Dialog
# Main entry point for Ntp Client
class Main < CWM::Dialog
def initialize
super
textdomain "ntp-client"
end

Expand Down
1 change: 1 addition & 0 deletions src/lib/y2ntp_client/dialog/pool.rb
Expand Up @@ -16,6 +16,7 @@ class Pool < CWM::Dialog
# key is option and value is string for key value options
# or nil for keyword options
def initialize(address = "", options = {})
super()
textdomain "ntp-client"
@address = address
@options = options
Expand Down
14 changes: 11 additions & 3 deletions src/lib/y2ntp_client/widgets/main_widgets.rb
Expand Up @@ -14,6 +14,7 @@ module Widgets
# Widget for netconfig policy
class PolicyCombo < CWM::ComboBox
def initialize
super
textdomain "ntp-client"
end

Expand All @@ -27,9 +28,10 @@ def help
# TRANSLATORS: configuration source combo box help, %{manual} is a
# manual page reference, e.g. "man 8 netconfig"
format(_("<p>The NTP configuration may be provided by the local network over DHCP. " \
"<b>Configuration Source</b> can simply enable or disable using that configuration. " \
"In cases where there may be multiple DHCP sources, it can prioritize them: " \
"see '%{manual}'.</p>"), manual: "man 8 netconfig")
"<b>Configuration Source</b> can simply enable or disable " \
"using that configuration. " \
"In cases where there may be multiple DHCP sources, it can prioritize them: " \
"see '%{manual}'.</p>"), manual: "man 8 netconfig")
end

def opt
Expand Down Expand Up @@ -76,6 +78,7 @@ def store
# Widget to configure how ntp will be started
class NtpStart < CWM::RadioButtons
def initialize(replace_point)
super()
textdomain "ntp-client"

@replace_point = replace_point
Expand Down Expand Up @@ -137,6 +140,7 @@ def store
# Widget representing how often synchronize via cron
class SyncInterval < CWM::IntField
def initialize
super
textdomain "ntp-client"
end

Expand Down Expand Up @@ -164,6 +168,7 @@ def store
# Table with ntp pool servers
class ServersTable < CWM::Table
def initialize
super
textdomain "ntp-client"
end

Expand Down Expand Up @@ -205,6 +210,7 @@ def items
# Button to add ntp pool server
class AddPoolButton < CWM::PushButton
def initialize
super
textdomain "ntp-client"
end

Expand All @@ -230,6 +236,7 @@ def handle
# Button to edit ntp pool server
class EditPoolButton < CWM::PushButton
def initialize(table)
super()
textdomain "ntp-client"

@table = table
Expand All @@ -253,6 +260,7 @@ def handle
# Button to delete ntp pool server
class DeletePoolButton < CWM::PushButton
def initialize(table)
super()
textdomain "ntp-client"

@table = table
Expand Down
9 changes: 9 additions & 0 deletions src/lib/y2ntp_client/widgets/pool_widgets.rb
Expand Up @@ -15,6 +15,7 @@ class PoolAddress < CWM::InputField

# @macro seeAbstractWidget
def initialize(initial_value)
super()
textdomain "ntp-client"

@address = initial_value
Expand Down Expand Up @@ -49,6 +50,7 @@ def store
# Button that tests if server is reachable
class TestButton < CWM::PushButton
def initialize(address_widget)
super()
textdomain "ntp-client"

@address_widget = address_widget
Expand All @@ -69,6 +71,7 @@ def handle
# Enable iburst option
class Iburst < CWM::CheckBox
def initialize(options)
super()
textdomain "ntp-client"

@options = options
Expand Down Expand Up @@ -104,6 +107,7 @@ class Offline < CWM::CheckBox
#
# @param options [Hash] current ntp server address options
def initialize(options)
super()
textdomain "ntp-client"
@options = options
end
Expand Down Expand Up @@ -151,6 +155,7 @@ class SelectFrom < CWM::MenuButton
#
# @param address_widget [PoolAddress] the dialog pool address widget
def initialize(address_widget)
super()
textdomain "ntp-client"
@address_widget = address_widget
end
Expand Down Expand Up @@ -207,6 +212,7 @@ class LocalList < CWM::SelectionBox
#
# @param address [String] current NTP pool address
def initialize(address)
super()
textdomain "ntp-client"

@address = address
Expand Down Expand Up @@ -273,6 +279,7 @@ class PublicList < CWM::CustomWidget
#
# @param address [String] current NTP pool address
def initialize(address)
super()
textdomain "ntp-client"

@country_pools = CountryPools.new
Expand Down Expand Up @@ -323,6 +330,7 @@ def country_for(address)
# Country chooser
class Country < CWM::ComboBox
def initialize(country, country_pools)
super()
textdomain "ntp-client"

@country = country
Expand Down Expand Up @@ -373,6 +381,7 @@ def country_names
# Ntp sources selector filtered by country
class CountryPools < CWM::ComboBox
def initialize
super
textdomain "ntp-client"
end

Expand Down
4 changes: 4 additions & 0 deletions src/lib/y2ntp_client/widgets/sources_table.rb
Expand Up @@ -34,6 +34,7 @@ class SourcesTable < CWM::Table
# @param sources [Hash<String, Symbol>] hash of ntp sources address (ip or url)
# and type (pool or server)
def initialize(sources = {})
super()
textdomain "ntp-client"

# TODO: validation of the input
Expand Down Expand Up @@ -78,6 +79,7 @@ def remove_item(id)
# A button for adding an item into @see SourcesTable
class SourcesAdd < CWM::PushButton
def initialize
super
textdomain "ntp-client"
end

Expand All @@ -93,6 +95,7 @@ def handle
# A button for removing an item from @see SourcesTable
class SourcesRemove < CWM::PushButton
def initialize
super
textdomain "ntp-client"
end

Expand All @@ -108,6 +111,7 @@ def handle
# A ComboBox containing varius supported types of NTP Sources
class SourcesType < CWM::ComboBox
def initialize
super
textdomain "ntp-client"
end

Expand Down
16 changes: 7 additions & 9 deletions src/modules/NtpClient.rb
Expand Up @@ -261,13 +261,13 @@ def GetCountryNames
def GetNtpServersByCountry(country, terse_output)
country_names = {}
servers = GetNtpServers()
if country.to_s != ""
if country.to_s == ""
country_names = GetCountryNames()
else
servers.select! { |_server, attrs| attrs["country"] == country }
# bnc#458917 add country, in case data/country.ycp does not have it
pool_country_record = MakePoolRecord(country, "")
servers[pool_country_record["address"]] = pool_country_record
else
country_names = GetCountryNames()
end

default = false
Expand Down Expand Up @@ -512,9 +512,7 @@ def Summary
result = Yast::Summary.AddLine(result, policy_line)
# TRANSLATORS: summary line. %s is formatted list of addresses.
servers_line = format(_("Servers: %s."), GetUsedNtpServers().join(", "))
result = Yast::Summary.AddLine(result, servers_line)

result
Yast::Summary.AddLine(result, servers_line)
end

# Dump the ntp-client settings to a single map
Expand Down Expand Up @@ -604,7 +602,9 @@ def DetectNtpServers(method)

# if package is not installed (in the inst-sys, it is: bnc#399659)
if !Stage.initial && !Package.Installed(required_package)
if !Package.CheckAndInstallPackages([required_package])
if Package.CheckAndInstallPackages([required_package])
SCR.RegisterAgent(path(".slp"), term(:ag_slp, term(:SlpAgent)))
else
Report.Error(
Builtins.sformat(
_(
Expand All @@ -615,8 +615,6 @@ def DetectNtpServers(method)
)
Builtins.y2warning("Not searching for local NTP servers via SLP")
return []
else
SCR.RegisterAgent(path(".slp"), term(:ag_slp, term(:SlpAgent)))
end
end

Expand Down