Skip to content

Commit

Permalink
rubocop auto correct
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Jul 13, 2016
1 parent 49fbfcb commit c9341dd
Show file tree
Hide file tree
Showing 24 changed files with 85 additions and 92 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Expand Up @@ -120,3 +120,7 @@ Style/MethodName:
Style/VariableName:
Include:
- 'src/lib/**/*.rb' # force known variables only for new code

# alias method is safer option
Style/Alias:
EnforcedStyle: prefer_alias_method
14 changes: 7 additions & 7 deletions src/lib/bootloader/autoyast_converter.rb
Expand Up @@ -111,7 +111,7 @@ def import_timeout(data, default)
"boot_boot" => :BootPartitionDevice,
"boot_mbr" => :mbr_disk,
"boot_extended" => :ExtendedPartitionDevice
}
}.freeze
def import_stage1(data, bootloader)
return unless bootloader.name == "grub2"

Expand Down Expand Up @@ -184,7 +184,7 @@ def bootloader_from_data(data)
"boot_boot" => :boot_partition?,
"boot_mbr" => :mbr?,
"boot_extended" => :extended_partition?
}
}.freeze
def export_stage1(res, stage1)
STAGE1_MAPPING.each do |key, method|
res[key] = stage1.public_send(method) ? "true" : "false"
Expand All @@ -200,7 +200,7 @@ def export_stage1(res, stage1)
# only for grub2, not for others
GRUB2_BOOLEAN_MAPPING = {
"trusted_grub" => :trusted_boot
}
}.freeze
def export_grub2(res, bootloader)
GRUB2_BOOLEAN_MAPPING.each do |key, method|
val = bootloader.public_send(method)
Expand All @@ -210,23 +210,23 @@ def export_grub2(res, bootloader)

DEFAULT_BOOLEAN_MAPPING = {
"os_prober" => :os_prober
}
}.freeze

DEFAULT_STRING_MAPPING = {
"gfxmode" => :gfxmode,
"serial" => :serial_console,
"terminal" => :terminal
}
}.freeze

DEFAULT_KERNEL_PARAMS_MAPPING = {
"append" => :kernel_params,
"xen_append" => :xen_kernel_params,
"xen_kernel_append" => :xen_hypervisor_params
}
}.freeze

SYMBOL_PARAM = [
"terminal"
]
].freeze
def export_default(res, default)
DEFAULT_BOOLEAN_MAPPING.each do |key, method|
val = default.public_send(method)
Expand Down
5 changes: 2 additions & 3 deletions src/lib/bootloader/boot_record_backup.rb
Expand Up @@ -9,7 +9,7 @@ class BootRecordBackup
BASH_PATH = Yast::Path.new(".target.bash")
BASH_OUTPUT_PATH = Yast::Path.new(".target.bash_output")
TARGET_SIZE = Yast::Path.new(".target.size")
MAIN_BACKUP_DIR = "/var/lib/YaST2/backup_boot_sectors/"
MAIN_BACKUP_DIR = "/var/lib/YaST2/backup_boot_sectors/".freeze
KEPT_BACKUPS = 10

attr_reader :device
Expand Down Expand Up @@ -120,8 +120,7 @@ def rotate
Yast::SCR.Execute(
BASH_PATH,
format("/bin/mv %{path} %{path}-%{date}",
path: device_file_path, date: change_date
)
path: device_file_path, date: change_date)
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/lib/bootloader/bootloader_factory.rb
Expand Up @@ -15,7 +15,7 @@ class BootloaderFactory
"none", # allows user to manage bootloader itself
"grub2",
"grub2-efi"
]
].freeze

class << self
attr_writer :current
Expand Down
2 changes: 1 addition & 1 deletion src/lib/bootloader/device_map.rb
Expand Up @@ -80,7 +80,7 @@ def propose

def sorted_disks
grub_devices.select { |d| d.start_with?("hd") }
.sort_by { |dev| dev[2..-1].to_i }
.sort_by { |dev| dev[2..-1].to_i }
end

BIOS_LIMIT = 8
Expand Down
2 changes: 1 addition & 1 deletion src/lib/bootloader/disk_change_detector.rb
Expand Up @@ -28,7 +28,7 @@ def changes
# TRANSLATORS: %s stands for partition
ret <<
_("Selected bootloader partition %s is not available any more.") %
device
device
end
end

Expand Down
15 changes: 7 additions & 8 deletions src/lib/bootloader/grub2_widgets.rb
Expand Up @@ -55,16 +55,15 @@ def label

def help
_("<p><b>Timeout in Seconds</b><br>\n" \
"Specifies the time the bootloader will wait until the default kernel is loaded.</p>\n"
)
"Specifies the time the bootloader will wait until the default kernel is loaded.</p>\n")
end

def init
if grub_default.hidden_timeout && grub_default.hidden_timeout.to_i > 0
self.value = grub_default.hidden_timeout.to_i
else
self.value = grub_default.timeout.to_i
end
self.value = if grub_default.hidden_timeout && grub_default.hidden_timeout.to_i > 0
grub_default.hidden_timeout.to_i
else
grub_default.timeout.to_i
end
end

def store
Expand Down Expand Up @@ -316,7 +315,7 @@ def initialize
textdomain "bootloader"
end

MASKED_PASSWORD = "**********"
MASKED_PASSWORD = "**********".freeze

def contents
HBox(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/bootloader/grub2base.rb
Expand Up @@ -161,7 +161,7 @@ def merge_password(other)
@password = other.password
end

KERNEL_FLAVORS_METHODS = [:kernel_params, :xen_hypervisor_params, :xen_kernel_params]
KERNEL_FLAVORS_METHODS = [:kernel_params, :xen_hypervisor_params, :xen_kernel_params].freeze

def merge_grub_default(other)
default = grub_default
Expand Down
7 changes: 3 additions & 4 deletions src/lib/bootloader/grub2pwd.rb
Expand Up @@ -50,7 +50,7 @@ def password?
private

YAST_BASH_PATH = Yast::Path.new(".local.bash_output")
PWD_ENCRYPTION_FILE = "/etc/grub.d/42_password"
PWD_ENCRYPTION_FILE = "/etc/grub.d/42_password".freeze

def propose
@used = false
Expand Down Expand Up @@ -108,7 +108,7 @@ def enable

Yast::SCR.Write(
Yast::Path.new(".target.string"),
[PWD_ENCRYPTION_FILE, 0700],
[PWD_ENCRYPTION_FILE, 0o700],
file_content
)
end
Expand All @@ -125,8 +125,7 @@ def encrypt(password)

quoted_password = Yast::String.Quote(password)
result = Yast::WFM.Execute(YAST_BASH_PATH,
"echo '#{quoted_password}\n#{quoted_password}\n' | LANG=C grub2-mkpasswd-pbkdf2"
)
"echo '#{quoted_password}\n#{quoted_password}\n' | LANG=C grub2-mkpasswd-pbkdf2")

if result["exit"] != 0
raise "Failed to create encrypted password for grub2. Command output: #{result["stderr"]}"
Expand Down
4 changes: 2 additions & 2 deletions src/lib/bootloader/grub_install.rb
Expand Up @@ -78,14 +78,14 @@ def no_device_install?
"s390_64" => "s390x-emu",
"ppc" => "powerpc-ieee1275",
"ppc64" => "powerpc-ieee1275"
}
}.freeze

EFI_TARGETS = {
"i386" => "i386-efi",
"x86_64" => "x86_64-efi",
"arm" => "arm-efi",
"aarch64" => "arm64-efi"
}
}.freeze
def target
return @target if @target

Expand Down
4 changes: 2 additions & 2 deletions src/lib/bootloader/mbr_update.rb
Expand Up @@ -52,8 +52,8 @@ def mbr_is_gpt?
mbr_type == "gpt"
end

GPT_MBR = "/usr/share/syslinux/gptmbr.bin"
DOS_MBR = "/usr/share/syslinux/mbr.bin"
GPT_MBR = "/usr/share/syslinux/gptmbr.bin".freeze
DOS_MBR = "/usr/share/syslinux/mbr.bin".freeze
def generic_mbr_file
@generic_mbr_file ||= mbr_is_gpt? ? GPT_MBR : DOS_MBR
end
Expand Down
19 changes: 7 additions & 12 deletions src/lib/bootloader/proposal_client.rb
Expand Up @@ -30,7 +30,7 @@ def initialize
"disable_boot_root",
"enable_boot_boot",
"disable_boot_boot"
]
].freeze

def make_proposal(attrs)
force_reset = attrs["force_reset"]
Expand Down Expand Up @@ -100,7 +100,7 @@ def description

private

BOOT_SYSCONFIG_PATH = "/etc/sysconfig/bootloader"
BOOT_SYSCONFIG_PATH = "/etc/sysconfig/bootloader".freeze
# read bootloader from /mnt as SCR is not yet switched in proposal
# phase of update (bnc#874646)
def old_bootloader
Expand Down Expand Up @@ -182,20 +182,15 @@ def handle_errors(ret)
end

if !Yast::BootStorage.bootloader_installable?
ret.merge!(
"warning_level" => :error,
# error in the proposal
"warning" => _(
"Because of the partitioning, the bootloader cannot be installed properly"
)
ret["warning_level"] = :error
ret["warning"] = _(
"Because of the partitioning, the bootloader cannot be installed properly"
)
end

if !Yast::BootSupportCheck.SystemSupported
ret.merge!(
"warning_level" => :error,
"warning" => Yast::BootSupportCheck.StringProblems
)
ret["warning_level"] = :error
ret["warning"] = Yast::BootSupportCheck.StringProblems
end

ret
Expand Down
3 changes: 2 additions & 1 deletion src/lib/bootloader/sections.rb
Expand Up @@ -48,7 +48,8 @@ def write

private

# @return [String, nil] return default boot path as string or nil if not set or something goes wrong
# @return [String, nil] return default boot path as string or nil if not set
# or something goes wrong
# @note shows error popup if calling grub2-editenv failed
def read_default_path
# Execute.on_target can return nil if call failed. It shows users error popup, but bootloader
Expand Down
6 changes: 3 additions & 3 deletions src/lib/bootloader/serial_console.rb
Expand Up @@ -11,10 +11,10 @@ class SerialConsole
"n" => "no",
"o" => "odd",
"e" => "even"
}
}.freeze
SPEED_DEFAULT = 9600
PARITY_DEFAULT = "no"
WORD_DEFAULT = ""
PARITY_DEFAULT = "no".freeze
WORD_DEFAULT = "".freeze

# REGEXP that separate usefull parts of kernel parameter for serial console
# matching groups are:
Expand Down
2 changes: 1 addition & 1 deletion src/lib/bootloader/stage1_proposal.rb
Expand Up @@ -260,7 +260,7 @@ def on_gpt?(partition)
"s390_64" => S390,
"ppc" => PPC,
"ppc64" => PPC
}
}.freeze
AVAILABLE_PROPOSALS.default_proc = lambda { |_h, k| raise "unsuported architecture #{k}" }
end
end
24 changes: 11 additions & 13 deletions src/lib/bootloader/sysconfig.rb
Expand Up @@ -11,7 +11,7 @@ class Sysconfig
bootloader: "LOADER_TYPE",
secure_boot: "SECURE_BOOT",
trusted_boot: "TRUSTED_BOOT"
}
}.freeze

# specifies bootloader in sysconfig
attr_accessor :bootloader
Expand All @@ -31,11 +31,11 @@ def self.from_system
bootloader = Yast::SCR.Read(AGENT_PATH + "LOADER_TYPE")
# propose secure boot always to true (bnc#872054), otherwise respect user choice
# but only on architectures that support it (bnc#984895)
if Yast::Arch.x86_64 || Yast::Arch.i386
secure_boot = Yast::SCR.Read(AGENT_PATH + "SECURE_BOOT") != "no"
else
secure_boot = false
end
secure_boot = if Yast::Arch.x86_64 || Yast::Arch.i386
Yast::SCR.Read(AGENT_PATH + "SECURE_BOOT") != "no"
else
false
end

trusted_boot = Yast::SCR.Read(AGENT_PATH + "TRUSTED_BOOT") == "yes"

Expand Down Expand Up @@ -85,7 +85,7 @@ def pre_write
"# Enable Trusted Boot support\n" \
"# Only available for legacy (non-UEFI) boot.\n" \
"#\n"
}
}.freeze

def write
log.info "Saving /etc/sysconfig/bootloader for #{bootloader}"
Expand Down Expand Up @@ -120,14 +120,12 @@ def ensure_file_exists_in_target
return if File.exist?(File.join(destdir, "/etc/sysconfig"))

Yast::WFM.Execute(Yast::Path.new(".local.mkdir"),
File.join(destdir, "/etc/sysconfig")
)
File.join(destdir, "/etc/sysconfig"))
Yast::WFM.Execute(Yast::Path.new(".local.bash"),
"touch #{destdir}/etc/sysconfig/bootloader"
)
"touch #{destdir}/etc/sysconfig/bootloader")
end

def temporary_target_agent(&block)
def temporary_target_agent
old_agent = sys_agent
@sys_agent = Yast::Path.new(".target.sysconfig.bootloader")

Expand All @@ -141,7 +139,7 @@ def temporary_target_agent(&block)
Yast::Term.new(:SysConfigFile, target_sysconfig_path))
)

block.call
yield
ensure
Yast::SCR.UnregisterAgent(@sys_agent)
@sys_agent = old_agent
Expand Down
4 changes: 2 additions & 2 deletions src/lib/bootloader/udev_mapping.rb
Expand Up @@ -128,15 +128,15 @@ def all_devices
id: "udev_id",
path: "udev_path",
label: "label"
}
}.freeze

# Maps udev key in Storage target map to device prefix
UDEV_MAPPING = {
"uuid" => "/dev/disk/by-uuid/",
"udev_id" => "/dev/disk/by-id/",
"udev_path" => "/dev/disk/by-path/",
"label" => "/dev/disk/by-label/"
}
}.freeze

# Maps udev names to kernel names with given mapping from data to device
# @private internall use only
Expand Down
10 changes: 5 additions & 5 deletions src/modules/BootArch.rb
Expand Up @@ -51,11 +51,11 @@ def DefaultKernelParams(resume)
ret << " splash=silent quiet showopts"
return ret
elsif Arch.s390
if ENV["TERM"] == "linux"
termparm = "TERM=linux console=ttyS0 console=ttyS1"
else
termparm = "hvc_iucv=8 TERM=dumb"
end
termparm = if ENV["TERM"] == "linux"
"TERM=linux console=ttyS0 console=ttyS1"
else
"hvc_iucv=8 TERM=dumb"
end
parameters = "#{features} #{termparm}"
parameters << " resume=#{resume}" unless resume.empty?
return parameters
Expand Down
10 changes: 5 additions & 5 deletions src/modules/BootStorage.rb
Expand Up @@ -264,11 +264,11 @@ def available_swap_partitions
end
partitions.each do |s|
# bnc#577127 - Encrypted swap is not properly set up as resume device
if s["crypt_device"] && !s["crypt_device"].empty?
dev = s["crypt_device"]
else
dev = s["device"]
end
dev = if s["crypt_device"] && !s["crypt_device"].empty?
s["crypt_device"]
else
s["device"]
end
ret[dev] = s["size_k"] || 0
end
end
Expand Down

0 comments on commit c9341dd

Please sign in to comment.