Skip to content

Commit

Permalink
rubocop enablement, manual changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Dec 14, 2018
1 parent cb5a156 commit ad7f178
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 315 deletions.
103 changes: 50 additions & 53 deletions src/clients/kdump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,7 @@ def main

# Command line function for display options from kdump
#
def cmdKdumpShow(options)
options = deep_copy(options)
def cmdKdumpShow(_options)
CommandLine.Print("")
# TRANSLATORS: CommandLine printed text
CommandLine.Print(String.UnderlinedHeader(_("Display Settings:"), 0))
Expand Down Expand Up @@ -647,9 +646,11 @@ def cmdKdumpShow(options)
CommandLine.Print(
Builtins.sformat(
_("Kdump immediate reboots: %1"),
Ops.get(Kdump.KDUMP_SETTINGS, "KDUMP_IMMEDIATE_REBOOT") == "yes" ?
_("Enabled") :
if Ops.get(Kdump.KDUMP_SETTINGS, "KDUMP_IMMEDIATE_REBOOT") == "yes"
_("Enabled")
else
_("Disabled")
end
)
)

Expand Down Expand Up @@ -737,8 +738,8 @@ def cmdKdumpShow(options)

def cmdKdumpStartup(options)
options = deep_copy(options)
if Ops.get(options, "enable") != nil &&
Ops.get(options, "alloc_mem") != nil
if Ops.get(options, "enable") &&
Ops.get(options, "alloc_mem")
alloc_mem_low, alloc_mem_high = options["alloc_mem"].split(",")
unless alloc_mem_low =~ ALLOC_MEM_REGEXP &&
(alloc_mem_high.nil? || alloc_mem_high =~ ALLOC_MEM_REGEXP)
Expand All @@ -760,7 +761,7 @@ def cmdKdumpStartup(options)
end
CommandLine.Print(_("To apply changes a reboot is necessary."))
return true
elsif Ops.get(options, "disable") != nil
elsif Ops.get(options, "disable")
Kdump.add_crashkernel_param = false
# TRANSLATORS: CommandLine printed text
CommandLine.Print(_("To apply changes a reboot is necessary."))
Expand All @@ -774,7 +775,7 @@ def cmdKdumpStartup(options)

def cmdKdumpDumpLevel(options)
options = deep_copy(options)
if Ops.get(options, "dump_level") != nil
if Ops.get(options, "dump_level")
if Ops.less_than(Ops.get(options, "dump_level"), 32) &&
Ops.greater_than(Ops.get(options, "dump_level"), -1)
Ops.set(
Expand All @@ -799,7 +800,7 @@ def cmdKdumpDumpLevel(options)

def cmdKdumpDumpFormat(options)
options = deep_copy(options)
if Ops.get(options, "dump_format") != nil
if Ops.get(options, "dump_format")
if Ops.get(options, "dump_format") == "ELF" ||
Ops.get(options, "dump_format") == "compressed"
Ops.set(
Expand Down Expand Up @@ -843,12 +844,12 @@ def cmdParsePassPath(path_file)

def cmdKdumpDumpTarget(options)
options = deep_copy(options)
if Ops.get(options, "target") != nil
if Ops.get(options, "target")
target = Builtins.tostring(Ops.get(options, "target"))
case target
when "file"
Ops.set(@KDUMP_SAVE_TARGET, "target", "file")
if Ops.get(options, "dir") != nil
if Ops.get(options, "dir")
Ops.set(
@KDUMP_SAVE_TARGET,
"dir",
Expand All @@ -862,7 +863,7 @@ def cmdKdumpDumpTarget(options)
when "ftp"
Ops.set(@KDUMP_SAVE_TARGET, "target", "ftp")

if Ops.get(options, "server") != nil
if Ops.get(options, "server")
Ops.set(
@KDUMP_SAVE_TARGET,
"server",
Expand All @@ -874,15 +875,15 @@ def cmdKdumpDumpTarget(options)
return false
end

if Ops.get(options, "port") != nil
if Ops.get(options, "port")
Ops.set(
@KDUMP_SAVE_TARGET,
"port",
Builtins.tostring(Ops.get(options, "port"))
)
end

if Ops.get(options, "dir") != nil
if Ops.get(options, "dir")
Ops.set(
@KDUMP_SAVE_TARGET,
"dir",
Expand All @@ -894,15 +895,15 @@ def cmdKdumpDumpTarget(options)
return false
end

if Ops.get(options, "user") != nil
if Ops.get(options, "user")
Ops.set(
@KDUMP_SAVE_TARGET,
"user_name",
Builtins.tostring(Ops.get(options, "user"))
)
end

if Ops.get(options, "pass") != nil
if Ops.get(options, "pass")
password = cmdParsePassPath(
Builtins.tostring(Ops.get(options, "pass"))
)
Expand All @@ -912,7 +913,7 @@ def cmdKdumpDumpTarget(options)
when "ssh", "sftp"
@KDUMP_SAVE_TARGET["target"] = target

if Ops.get(options, "server") != nil
if Ops.get(options, "server")
Ops.set(
@KDUMP_SAVE_TARGET,
"server",
Expand All @@ -924,15 +925,15 @@ def cmdKdumpDumpTarget(options)
return false
end

if Ops.get(options, "port") != nil
if Ops.get(options, "port")
Ops.set(
@KDUMP_SAVE_TARGET,
"port",
Builtins.tostring(Ops.get(options, "port"))
)
end

if Ops.get(options, "dir") != nil
if Ops.get(options, "dir")
Ops.set(
@KDUMP_SAVE_TARGET,
"dir",
Expand All @@ -943,7 +944,7 @@ def cmdKdumpDumpTarget(options)
return false
end

if Ops.get(options, "user") != nil
if Ops.get(options, "user")
Ops.set(
@KDUMP_SAVE_TARGET,
"user_name",
Expand All @@ -953,7 +954,7 @@ def cmdKdumpDumpTarget(options)
when "nfs"
Ops.set(@KDUMP_SAVE_TARGET, "target", "nfs")

if Ops.get(options, "server") != nil
if Ops.get(options, "server")
Ops.set(
@KDUMP_SAVE_TARGET,
"server",
Expand All @@ -965,7 +966,7 @@ def cmdKdumpDumpTarget(options)
return false
end

if Ops.get(options, "dir") != nil
if Ops.get(options, "dir")
Ops.set(
@KDUMP_SAVE_TARGET,
"dir",
Expand All @@ -979,7 +980,7 @@ def cmdKdumpDumpTarget(options)
when "cifs"
Ops.set(@KDUMP_SAVE_TARGET, "target", "cifs")

if Ops.get(options, "server") != nil
if Ops.get(options, "server")
Ops.set(
@KDUMP_SAVE_TARGET,
"server",
Expand All @@ -991,7 +992,7 @@ def cmdKdumpDumpTarget(options)
return false
end

if Ops.get(options, "share") != nil
if Ops.get(options, "share")
Ops.set(
@KDUMP_SAVE_TARGET,
"share",
Expand All @@ -1003,15 +1004,15 @@ def cmdKdumpDumpTarget(options)
return false
end

if Ops.get(options, "port") != nil
if Ops.get(options, "port")
Ops.set(
@KDUMP_SAVE_TARGET,
"port",
Builtins.tostring(Ops.get(options, "port"))
)
end

if Ops.get(options, "dir") != nil
if Ops.get(options, "dir")
Ops.set(
@KDUMP_SAVE_TARGET,
"dir",
Expand All @@ -1023,15 +1024,15 @@ def cmdKdumpDumpTarget(options)
return false
end

if Ops.get(options, "user") != nil
if Ops.get(options, "user")
Ops.set(
@KDUMP_SAVE_TARGET,
"user_name",
Builtins.tostring(Ops.get(options, "user"))
)
end

if Ops.get(options, "pass") != nil
if Ops.get(options, "pass")
password = cmdParsePassPath(
Builtins.tostring(Ops.get(options, "pass"))
)
Expand All @@ -1058,7 +1059,7 @@ def cmdKdumpDumpTarget(options)

def cmdKdumpCustomKernel(options)
options = deep_copy(options)
if Ops.get(options, "kernel") != nil
if Ops.get(options, "kernel")
Ops.set(
Kdump.KDUMP_SETTINGS,
"KDUMP_KERNELVER",
Expand All @@ -1074,7 +1075,7 @@ def cmdKdumpCustomKernel(options)

def cmdKdumpKernelCommandLine(options)
options = deep_copy(options)
if Ops.get(options, "command") != nil
if Ops.get(options, "command")
Ops.set(
Kdump.KDUMP_SETTINGS,
"KDUMP_COMMANDLINE",
Expand All @@ -1090,7 +1091,7 @@ def cmdKdumpKernelCommandLine(options)

def cmdKdumpKernelCommandLineAppend(options)
options = deep_copy(options)
if Ops.get(options, "command") != nil
if Ops.get(options, "command")
Ops.set(
Kdump.KDUMP_SETTINGS,
"KDUMP_COMMANDLINE_APPEND",
Expand All @@ -1106,10 +1107,10 @@ def cmdKdumpKernelCommandLineAppend(options)

def cmdKdumpImmediateReboot(options)
options = deep_copy(options)
if Ops.get(options, "enable") != nil
if Ops.get(options, "enable")
Ops.set(Kdump.KDUMP_SETTINGS, "KDUMP_IMMEDIATE_REBOOT", "yes")
return true
elsif Ops.get(options, "disable") != nil
elsif Ops.get(options, "disable")
Ops.set(Kdump.KDUMP_SETTINGS, "KDUMP_IMMEDIATE_REBOOT", "no")
return true
else
Expand All @@ -1121,10 +1122,10 @@ def cmdKdumpImmediateReboot(options)

def cmdKdumpCopyKernel(options)
options = deep_copy(options)
if Ops.get(options, "enable") != nil
if Ops.get(options, "enable")
Ops.set(Kdump.KDUMP_SETTINGS, "KDUMP_COPY_KERNEL", "yes")
return true
elsif Ops.get(options, "disable") != nil
elsif Ops.get(options, "disable")
Ops.set(Kdump.KDUMP_SETTINGS, "KDUMP_COPY_KERNEL", "no")
return true
else
Expand All @@ -1136,7 +1137,7 @@ def cmdKdumpCopyKernel(options)

def cmdKdumpKeepOldDumps(options)
options = deep_copy(options)
if Ops.get(options, "no") != nil
if Ops.get(options, "no")
if Ops.greater_than(Ops.get(options, "no"), -1)
Ops.set(
Kdump.KDUMP_SETTINGS,
Expand All @@ -1158,7 +1159,7 @@ def cmdKdumpKeepOldDumps(options)

def cmdKdumpSMTPServer(options)
options = deep_copy(options)
if Ops.get(options, "server") != nil
if Ops.get(options, "server")
server = Builtins.tostring(Ops.get(options, "server"))

if server != "" && !server.nil?
Expand All @@ -1178,7 +1179,7 @@ def cmdKdumpSMTPServer(options)

def cmdKdumpSMTPUser(options)
options = deep_copy(options)
if Ops.get(options, "user") != nil
if Ops.get(options, "user")
user = Builtins.tostring(Ops.get(options, "user"))

if user != "" && !user.nil?
Expand All @@ -1198,7 +1199,7 @@ def cmdKdumpSMTPUser(options)

def cmdKdumpSMTPPass(options)
options = deep_copy(options)
if Ops.get(options, "pass") != nil
if Ops.get(options, "pass")
password = cmdParsePassPath(Builtins.tostring(Ops.get(options, "pass")))
return false if password.nil? || password == ""
Ops.set(Kdump.KDUMP_SETTINGS, "KDUMP_SMTP_PASSWORD", password)
Expand All @@ -1213,7 +1214,7 @@ def cmdKdumpSMTPPass(options)

def cmdKdumpSMTPNotifTo(options)
options = deep_copy(options)
if Ops.get(options, "email") != nil
if Ops.get(options, "email")
email = Builtins.tostring(Ops.get(options, "email"))

if email != "" && !email.nil?
Expand All @@ -1233,7 +1234,7 @@ def cmdKdumpSMTPNotifTo(options)

def cmdKdumpSMTPNotifCC(options)
options = deep_copy(options)
if Ops.get(options, "email") != nil
if Ops.get(options, "email")
email = Builtins.tostring(Ops.get(options, "email"))

if email != "" && !email.nil?
Expand All @@ -1254,25 +1255,21 @@ def cmdKdumpSMTPNotifCC(options)
def show_fadump_status
CommandLine.Print(
_("Firmware-assisted dump: %{status}") %
{ :status => Kdump.using_fadump? ?
_("Enabled") :
_("Disabled") }
{ :status => Kdump.using_fadump? ? _("Enabled") : _("Disabled") }
)
end

def cmd_handle_fadump(options)
if options["enable"]
return Kdump.use_fadump(true)
elsif options["disable"]
return Kdump.use_fadump(false)
elsif options["status"]
return Kdump.use_fadump(true) if options["enable"]
return Kdump.use_fadump(false) if options["disable"]
if options["status"]
show_fadump_status
return true
else
# TRANSLATORS: CommandLine error message
CommandLine.Error(_("No option has been defined."))
return false
end

# TRANSLATORS: CommandLine error message
CommandLine.Error(_("No option has been defined."))
false
end
end
end
Expand Down

0 comments on commit ad7f178

Please sign in to comment.