From a34306ce876eea2e4b972bb0537c3ac71f7ec2d5 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Fri, 22 Dec 2023 16:11:04 +0100 Subject: [PATCH 1/3] update to newer rubocop and apply auto corrections --- .rubocop.yml | 2 +- Rakefile | 2 +- src/clients/inst_backup.rb | 16 +-- src/clients/packages_proposal.rb | 2 +- src/clients/update_proposal.rb | 24 ++--- src/include/update/rootpart.rb | 75 +++++++------- src/modules/RootPart.rb | 161 +++++++++++++++---------------- src/modules/SUSERelease.rb | 2 +- src/modules/Update.rb | 4 +- test/update_test.rb | 28 +++--- 10 files changed, 155 insertions(+), 161 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 9a8d2751..07b36878 100644 --- a/.rubocop.yml +++ b/.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 # this needs more testing if we can have frozen string literals Style/FrozenStringLiteralComment: diff --git a/Rakefile b/Rakefile index 1c88cae9..9bddc011 100644 --- a/Rakefile +++ b/Rakefile @@ -11,5 +11,5 @@ end # additionally validate the control XML files as a part of the unit tests task "test:unit" do sh "xmllint --noout --relaxng #{Packaging::Configuration::YAST_DIR.shellescape}"\ - "/control/control.rng control/*.xml" + "/control/control.rng control/*.xml" end diff --git a/src/clients/inst_backup.rb b/src/clients/inst_backup.rb index f678b9fd..994f1449 100644 --- a/src/clients/inst_backup.rb +++ b/src/clients/inst_backup.rb @@ -87,7 +87,7 @@ def main # TRANSLATORS: help text for backup dialog during update 1/7 @help_text = _( "

To avoid any loss of information during update,\n" \ - "create a backup prior to updating.

\n" + "create a backup prior to updating.

\n" ) # TRANSLATORS: help text for backup dialog during update 2/7 @@ -95,7 +95,7 @@ def main @help_text, _( "

Warning: This will not be a complete\n" \ - "backup. Only modified files will be saved.

\n" + "backup. Only modified files will be saved.

\n" ) ) @@ -110,7 +110,7 @@ def main @help_text, _( "

Create a Backup of Modified Files:\n" \ - "Stores only those modified files that will be replaced during update.

\n" + "Stores only those modified files that will be replaced during update.

\n" ) ) @@ -119,8 +119,8 @@ def main @help_text, _( "

Create a Complete Backup of\n" \ - "/etc/sysconfig: This covers all configuration files that are part of the\n" \ - "sysconfig mechanism, even those that will not be replaced.

\n" + "/etc/sysconfig: This covers all configuration files that are part of the\n" \ + "sysconfig mechanism, even those that will not be replaced.

\n" ) ) @@ -129,9 +129,9 @@ def main @help_text, _( "

Remove Old Backups from the Backup\n" \ - "Directory: If your current system already is the result of an earlier\n" \ - "update, there may be old configuration file backups. Select this option to\n" \ - "remove them.

\n" + "Directory: If your current system already is the result of an earlier\n" \ + "update, there may be old configuration file backups. Select this option to\n" \ + "remove them.

\n" ) ) diff --git a/src/clients/packages_proposal.rb b/src/clients/packages_proposal.rb index 0132c574..f0cd899e 100644 --- a/src/clients/packages_proposal.rb +++ b/src/clients/packages_proposal.rb @@ -288,7 +288,7 @@ def orphaned_packages_summary(packages) if packages.size > ORPHANED_MAX_SIZE # TRANSLATORS: %s is replaced by a number of remaining items - summary << _("... and %s more") % (packages.size - ORPHANED_MAX_SIZE) + summary << (_("... and %s more") % (packages.size - ORPHANED_MAX_SIZE)) end summary diff --git a/src/clients/update_proposal.rb b/src/clients/update_proposal.rb index 1f6570c7..b0ca7268 100644 --- a/src/clients/update_proposal.rb +++ b/src/clients/update_proposal.rb @@ -147,9 +147,9 @@ def main # %2 is the version being installed _( "Updating system to another version (%1 -> %2) is not supported on " \ - "the running system.
\n" \ - "Boot from the installation media and use a normal upgrade\n" \ - "or disable software repositories of products with different versions.\n" + "the running system.
\n" \ + "Boot from the installation media and use a normal upgrade\n" \ + "or disable software repositories of products with different versions.\n" ), @update_from, @update_to @@ -196,9 +196,9 @@ def main # TRANSLATORS: proposal dialog help @update_options_help = _( "

Update Options Select how your system will be updated.\n" \ - "Choose if only installed packages should be updated or new ones should be\n" \ - "installed as well (default). Decide whether unmaintained packages should be\n" \ - "deleted.

\n" + "Choose if only installed packages should be updated or new ones should be\n" \ + "installed as well (default). Decide whether unmaintained packages should be\n" \ + "deleted.

\n" ) @ret = { @@ -474,9 +474,9 @@ def init_stuff Update.solve_errors = Pkg.PkgSolve(false) ? 0 : Pkg.PkgSolveErrors log.info "Update compatibility: " \ - "Update.ProductsCompatible: #{Update.ProductsCompatible}, " \ - "Update.products_incompatible: #{Update.products_incompatible}, " \ - "update_not_possible: #{update_not_possible}" + "Update.ProductsCompatible: #{Update.ProductsCompatible}, " \ + "Update.products_incompatible: #{Update.products_incompatible}, " \ + "update_not_possible: #{update_not_possible}" # check product compatibility if !(Update.ProductsCompatible || Update.products_incompatible) || update_not_possible @@ -484,9 +484,9 @@ def init_stuff # TRANSLATORS: continue-cancel popup _( "The installed product is not compatible with the product\n" \ - "on the installation media. If you try to update using the\n" \ - "current installation media, the system may not start or\n" \ - "some applications may not run properly." + "on the installation media. If you try to update using the\n" \ + "current installation media, the system may not start or\n" \ + "some applications may not run properly." ) ) Update.IgnoreProductCompatibility diff --git a/src/include/update/rootpart.rb b/src/include/update/rootpart.rb index 7a9ce65a..c6890a4c 100644 --- a/src/include/update/rootpart.rb +++ b/src/include/update/rootpart.rb @@ -107,7 +107,7 @@ def make_partition_list(withall, flavor) # see bugzilla #288201 # architecture needs to be valid when updating, not booting arch_is_valid = flavor == :boot || Ops.get_boolean(i, :arch_valid, false) - if withall || Ops.get_boolean(i, :valid, false) && arch_is_valid + if withall || (Ops.get_boolean(i, :valid, false) && arch_is_valid) # `ext2, `jfs, ... part_fs = Ops.get_symbol(i, :fs) part_fs_name = Builtins.tostring(part_fs) @@ -211,8 +211,8 @@ def RootPartitionDialog(flavor) # TRANSLATORS: help text for root partition dialog (for boot) help_text = _( "

\n" \ - "Select the partition or system to boot.\n" \ - "

\n" + "Select the partition or system to boot.\n" \ + "

\n" ) else # TRANSLATORS: label for selection of root partition (for update) @@ -221,8 +221,8 @@ def RootPartitionDialog(flavor) # TRANSLATORS: help text for root partition dialog (for update) help_text = _( "

\n" \ - "Select the partition or system to update.\n" \ - "

\n" + "Select the partition or system to update.\n" \ + "

\n" ) if flavor == :update_dialog || flavor == :update_dialog_proposal @@ -236,9 +236,9 @@ def RootPartitionDialog(flavor) help_text, _( "

\n" \ - "Show All Partitions expands the list to a\n" \ - "general overview of your system's partitions.\n" \ - "

\n" + "Show All Partitions expands the list to a\n" \ + "general overview of your system's partitions.\n" \ + "

\n" ) ) @@ -374,15 +374,15 @@ def RootPartitionDialog(flavor) cont = false # TRANSLATORS: error message Report.Error(_("ReiserFS is not supported anymore.\n" \ - "Please migrate your data to another " \ - "filesystem before performing the upgrade.\n\n")) + "Please migrate your data to another " \ + "filesystem before performing the upgrade.\n\n")) elsif (freshman[:name] || "unknown") == "unknown" cont = false Popup.Error( # TRANSLATORS: error popup _( "No installed system that can be upgraded with this product was found\n" \ - "on the selected partition." + "on the selected partition." ) ) elsif !DoArchitecturesMatch( @@ -393,7 +393,7 @@ def RootPartitionDialog(flavor) # TRANSLATORS: continue-cancel popup _( "The architecture of the system installed in the selected partition\n " \ - "is different from the one of this product.\n" + "is different from the one of this product.\n" ) ) end @@ -424,7 +424,7 @@ def RootPartitionDialog(flavor) # TRANSLATORS: pop-up question _( "A possibly incomplete installation has been detected on the selected " \ - "partition.\nAre sure you want to use it anyway?" + "partition.\nAre sure you want to use it anyway?" ), # TRANSLATORS: button label _("&Yes, Use It"), @@ -475,9 +475,9 @@ def RootPartitionDialog(flavor) # TRANSLATORS: error message _( "Initializing the system for upgrade has failed for unknown reason.\n" \ - "It is highly recommended not to continue the upgrade process.\n" \ - "\n" \ - "Are you sure you want to continue?" + "It is highly recommended not to continue the upgrade process.\n" \ + "\n" \ + "Are you sure you want to continue?" ), # TRANSLATORS: button label _("&Yes, Continue"), @@ -493,30 +493,27 @@ def RootPartitionDialog(flavor) end # not aborted - if ret != :back - # Target load failed, #466803 - if Pkg.TargetLoad != true - Builtins.y2error("Pkg::TargetLoad failed") - if Popup.AnyQuestion( - Label.ErrorMsg, - # TRANSLATORS: error message - _( - "Initializing the system for upgrade has failed for unknown reason.\n" \ - "It is highly recommended not to continue the upgrade process.\n" \ - "\n" \ - "Are you sure you want to continue?" - ), - # TRANSLATORS: button label - _("&Yes, Continue"), - Label.CancelButton, - :focus_no + if ret != :back && (Pkg.TargetLoad != true) + Builtins.y2error("Pkg::TargetLoad failed") + if Popup.AnyQuestion( + Label.ErrorMsg, + # TRANSLATORS: error message + _( + "Initializing the system for upgrade has failed for unknown reason.\n" \ + "It is highly recommended not to continue the upgrade process.\n" \ + "\n" \ + "Are you sure you want to continue?" + ), + # TRANSLATORS: button label + _("&Yes, Continue"), + Label.CancelButton, + :focus_no + ) + ret = :back + else + Builtins.y2warning( + "User decided to continue despite the error above (Pkg::TargetLoad() failed)" ) - ret = :back - else - Builtins.y2warning( - "User decided to continue despite the error above (Pkg::TargetLoad() failed)" - ) - end end end diff --git a/src/modules/RootPart.rb b/src/modules/RootPart.rb index b82e1d7c..355f1c6a 100644 --- a/src/modules/RootPart.rb +++ b/src/modules/RootPart.rb @@ -197,10 +197,10 @@ def UnmountPartitions(keep_in_target) Builtins.sformat( _( "Cannot unmount partition %1.\n" \ - "\n" \ - "It is currently in use. If the partition stays mounted,\n" \ - "the data may be lost. Unmount the partition manually\n" \ - "or restart your computer.\n" + "\n" \ + "It is currently in use. If the partition stays mounted,\n" \ + "the data may be lost. Unmount the partition manually\n" \ + "or restart your computer.\n" ), file ) @@ -395,7 +395,15 @@ def RunFSCKonJFS(mount_type, device, error_message) UI.CloseDialog # failed - if Ops.get(cmd, "exit") != 0 + if Ops.get(cmd, "exit") == 0 + # add device into the list of already checked partitions (with exit status 0); + @already_checked_jfs_partitions = Builtins.add( + @already_checked_jfs_partitions, + device + ) + Builtins.y2milestone("Result: %1", cmd) + return true + else Builtins.y2error("Result: %1", cmd) error_message.value = Builtins.tostring(Ops.get(cmd, "stderr")) @@ -418,8 +426,8 @@ def RunFSCKonJFS(mount_type, device, error_message) # %1 is a device name such as /dev/hda5 _( "The file system check of device %1 has failed.\n" \ - "\n" \ - "Do you want to continue mounting the device?\n" + "\n" \ + "Do you want to continue mounting the device?\n" ), device ), @@ -429,14 +437,6 @@ def RunFSCKonJFS(mount_type, device, error_message) details ) # succeeded - else - # add device into the list of already checked partitions (with exit status 0); - @already_checked_jfs_partitions = Builtins.add( - @already_checked_jfs_partitions, - device - ) - Builtins.y2milestone("Result: %1", cmd) - return true end end @@ -595,7 +595,7 @@ def readFsTab(fstab) fstab_file = Ops.add(Installation.destdir, "/etc/fstab") if FileUtils.Exists(fstab_file) - # Note: this is a copy from etc_fstab.scr file (yast2.rpm), + # NOTE: this is a copy from etc_fstab.scr file (yast2.rpm), # keep the files in sync! SCR.RegisterAgent( path(".target.etc.fstab"), @@ -705,15 +705,15 @@ def CheckBootSize(_bootpart) SCR.Execute(path(".target.bash_output"), cmd) ) - if Ops.get_integer(bootsizeout, "exit", -1) != 0 - Builtins.y2error("Error: '%1' -> %2", cmd, bootsizeout) - else + if Ops.get_integer(bootsizeout, "exit", -1) == 0 scriptout = Builtins.splitstring( Ops.get_string(bootsizeout, "stdout", ""), " " ) Builtins.y2milestone("Scriptout: %1", scriptout) bootsize = Builtins.tointeger(Ops.get(scriptout, 1, "0")) + else + Builtins.y2error("Error: '%1' -> %2", cmd, bootsizeout) end if bootsize.nil? || bootsize == 0 @@ -745,11 +745,11 @@ def CheckBootSize(_bootpart) Builtins.sformat( _( "Your /boot partition is too small (%1 MB).\n" \ - "We recommend a size of no less than %2 MB or else the new Kernel may not fit.\n" \ - "It is safer to either enlarge the partition\n" \ - "or not use a /boot partition at all.\n" \ - "\n" \ - "Do you want to continue updating the current system?\n" + "We recommend a size of no less than %2 MB or else the new Kernel may not fit.\n" \ + "It is safer to either enlarge the partition\n" \ + "or not use a /boot partition at all.\n" \ + "\n" \ + "Do you want to continue updating the current system?\n" ), current_bs, suggested_bs @@ -760,12 +760,12 @@ def CheckBootSize(_bootpart) Builtins.y2warning( "User decided to continue despite small a /boot partition" ) - return true + true else Builtins.y2milestone( "User decided not to continue with small /boot partition" ) - return false + false end end @@ -858,9 +858,7 @@ def MountFSTab(fstab, _message) end end - if fspath == "/boot" || fspath == "/boot/" - success = false unless CheckBootSize(spec) - end + success = false if (fspath == "/boot" || fspath == "/boot/") && !CheckBootSize(spec) elsif vfstype == "swap" && fspath == "swap" log.info("mounting #{spec} to #{fspath}") @@ -873,10 +871,10 @@ def MountFSTab(fstab, _message) ret_from_shell = Convert.to_integer( SCR.Execute(path(".target.bash"), command) ) - if ret_from_shell != 0 - log.error("swapon failed: #{command}") - else + if ret_from_shell == 0 AddMountedPartition(type: "swap", device: spec) + else + log.error("swapon failed: #{command}") end end end @@ -909,13 +907,13 @@ def mount_failed_action(spec, error) # %2 is output of the 'mount' command _( "The partition %1 could not be mounted.\n" \ - "\n" \ - "%2\n" \ - "\n" \ - "If you are sure that the partition is not necessary for the\n" \ - "update (not a system partition), click Continue.\n" \ - "To check or fix the mount options, click Specify Mount Options.\n" \ - "To abort the update, click Cancel.\n" + "\n" \ + "%2\n" \ + "\n" \ + "If you are sure that the partition is not necessary for the\n" \ + "update (not a system partition), click Continue.\n" \ + "To check or fix the mount options, click Specify Mount Options.\n" \ + "To abort the update, click Cancel.\n" ), spec, error @@ -1012,8 +1010,8 @@ def MountPartitions(root_device_current) message = Builtins.sformat( _( "Partitions could not be mounted.\n" \ - "\n" \ - "Check the log file %1." + "\n" \ + "Check the log file %1." ), Ops.add(Directory.logdir, "/y2log") ) @@ -1063,9 +1061,9 @@ def MountPartitions(root_device_current) # TRANSLATORS: warning popup _( "Some partitions in the system on %1 are mounted by kernel-device name. This is\n" \ - "not reliable for the update since kernel-device names are unfortunately not\n" \ - "persistent. It is strongly recommended to start the old system and change the\n" \ - "mount-by method to any other method for all partitions." + "not reliable for the update since kernel-device names are unfortunately not\n" \ + "persistent. It is strongly recommended to start the old system and change the\n" \ + "mount-by method to any other method for all partitions." ), root_device_current ) @@ -1081,12 +1079,12 @@ def MountPartitions(root_device_current) # TRANSLATORS: warning popup _( "Some home directories in the system on %1 are encrypted. This release does not\n" \ - "support cryptconfig any longer and those home directories " \ - "will not be accessible\n" \ - "after upgrade. In order to access these home directories, " \ - "they need to be decrypted\n" \ - "before performing upgrade.\n" \ - "You can consider encrypting whole volume via LUKS." + "support cryptconfig any longer and those home directories " \ + "will not be accessible\n" \ + "after upgrade. In order to access these home directories, " \ + "they need to be decrypted\n" \ + "before performing upgrade.\n" \ + "You can consider encrypting whole volume via LUKS." ), root_device_current ) @@ -1101,29 +1099,15 @@ def MountPartitions(root_device_current) else tmp = "" - if !( - tmp_ref = arg_ref(tmp) - check_root_device_result = check_root_device( - root_device_current, - fstab, - tmp_ref - ) - tmp = tmp_ref.value - check_root_device_result - ) - Builtins.y2error("fstab has wrong root device!") - - # TRANSLATORS: Error message, where %{root} and %{tmp} are replaced by - # device names (e.g., /dev/sda1 and /dev/sda2). - message = format( - _("The root partition in /etc/fstab has an invalid root device.\n" \ - "It is currently mounted as %{root} but listed as %{tmp}."), - root: root_device_current, - tmp: tmp + if tmp_ref = arg_ref(tmp) + check_root_device_result = check_root_device( + root_device_current, + fstab, + tmp_ref ) + tmp = tmp_ref.value + check_root_device_result - success = false - else Builtins.y2milestone("fstab %1", fstab) legacy_filesystems = @@ -1152,6 +1136,19 @@ def MountPartitions(root_device_current) ) success = false end + else + Builtins.y2error("fstab has wrong root device!") + + # TRANSLATORS: Error message, where %{root} and %{tmp} are replaced by + # device names (e.g., /dev/sda1 and /dev/sda2). + message = format( + _("The root partition in /etc/fstab has an invalid root device.\n" \ + "It is currently mounted as %{root} but listed as %{tmp}."), + root: root_device_current, + tmp: tmp + ) + + success = false end end else @@ -1170,19 +1167,19 @@ def MountPartitions(root_device_current) ) Builtins.y2milestone("activated %1", @activated) - if !success - Popup.Message(message) - - # some mount failed, unmount all mounted fs - UnmountPartitions(false) - @did_try_mount_partitions = true - else + if success # enter the mount points of the newly mounted partitions update_staging! create_pre_snapshot Update.clean_backup create_backup inject_intsys_files + else + Popup.Message(message) + + # some mount failed, unmount all mounted fs + UnmountPartitions(false) + @did_try_mount_partitions = true end success @@ -1479,7 +1476,7 @@ def FindRootPartitions filesystems.each_with_index do |fs, counter| if UI.WidgetExists(Id("search_progress")) - percent = 100 * (counter + 1 / filesystems.size) + percent = 100 * (counter + (1 / filesystems.size)) UI.ChangeWidget(Id("search_pb"), :Value, percent) end @@ -1578,7 +1575,7 @@ def load_saved(data) publish function: :SetSelectedToValid, type: "void ()" publish function: :UnmountPartitions, type: "void (boolean)" publish function: :AnyQuestionAnyButtonsDetails, - type: "boolean (string, string, string, string, string)" + type: "boolean (string, string, string, string, string)" publish function: :MountPartitions, type: "boolean (string)" publish function: :IncompleteInstallationDetected, type: "boolean (string)" publish function: :FindRootPartitions, type: "void ()" @@ -1717,8 +1714,8 @@ def fs_by_devicename(devicegraph, device_spec) # log which devicegraph we operate on graph = "?" - graph = "probed" if devicegraph.object_id == probed.object_id - if devicegraph.object_id == staging.object_id + graph = "probed" if devicegraph.equal?(probed) + if devicegraph.equal?(staging) graph = "staging#" + Y2Storage::StorageManager.instance.staging_revision.to_s end log.info("fs_by_devicename(#{graph}, #{device_spec}) = #{"sid#" + fs.sid.to_s if fs}") diff --git a/src/modules/SUSERelease.rb b/src/modules/SUSERelease.rb index f92613a2..5012aa6b 100644 --- a/src/modules/SUSERelease.rb +++ b/src/modules/SUSERelease.rb @@ -80,7 +80,7 @@ def ReleaseInformation(base_dir = "/") # Removes all unneeded stuff such as architecture or product nickname def shorten(long_name) - long_name.gsub(/[ ]*\(.*/, "") + long_name.gsub(/ *\(.*/, "") end publish function: :ReleaseInformation, type: "string (string)" diff --git a/src/modules/Update.rb b/src/modules/Update.rb index 389ea3ac..70adf191 100644 --- a/src/modules/Update.rb +++ b/src/modules/Update.rb @@ -947,7 +947,7 @@ def create_tarball(tarball_path, root, paths) command = "tar cv -C '#{root}'" # no shell escaping here, but we backup reasonable files and want to allow globs - command << " " + paths_without_prefix.join(" ") + command << (" " + paths_without_prefix.join(" ")) # use parallel gzip for faster compression (uses all available CPU cores) command << " | pigz - > '#{tarball_path}'" res = SCR.Execute(path(".target.bash_output"), command) @@ -997,7 +997,7 @@ def installed_desktop if !FileUtils.Exists(windowmanager_sysconfig) log.warn "Sysconfig file #{windowmanager_sysconfig} does not exist, " \ - "desktop upgrade will not be handled" + "desktop upgrade will not be handled" return nil end diff --git a/test/update_test.rb b/test/update_test.rb index 608b6541..9d0bc74e 100755 --- a/test/update_test.rb +++ b/test/update_test.rb @@ -53,7 +53,7 @@ def default_SetDesktopPattern_stubs end it "returns product name from SUSE-release if os-release is missing and " \ - "SUSE-release exists in Installation.destdir" do + "SUSE-release exists in Installation.destdir" do allow(Yast::Installation).to receive(:destdir) .and_return(File.join(DATA_DIR, "update-test-2")) expect(Yast::Update.installed_product).to eq("SUSE Linux Enterprise Server 11") @@ -251,7 +251,7 @@ def default_SetDesktopPattern_stubs it "logs info and error" do expect(Yast::Update.log).to receive(:info) .with("Version expected: opensuse-leap-15.0. " \ - "Backup version: opensuse-tumbleweed-20180911") + "Backup version: opensuse-tumbleweed-20180911") .and_call_original expect(Yast::Update.log).to receive(:error).with(/not restored/).and_call_original @@ -284,7 +284,7 @@ def default_SetDesktopPattern_stubs end context "if there is no windowmanager sysconfig file present " \ - "on the system selected for upgrade" do + "on the system selected for upgrade" do it "returns true as there is nothing to do" do default_product_control_desktop allow(Yast::FileUtils).to receive(:Exists).with(/windowmanager/).and_return(false) @@ -425,10 +425,10 @@ def default_SetDesktopPattern_stubs allow(Yast::ProductFeatures).to receive(:GetFeature) .with("software", "upgrade") .and_return("product_upgrades" => [{ - "from" => "openSUSE", - "to" => "SLES", - "compatible_vendors" => ["openSUSE", "SLES LCC"] - }]) + "from" => "openSUSE", + "to" => "SLES", + "compatible_vendors" => ["openSUSE", "SLES LCC"] + }]) end it "does not set compatible vendors at all" do @@ -443,9 +443,9 @@ def default_SetDesktopPattern_stubs allow(Yast::ProductFeatures).to receive(:GetFeature) .with("software", "upgrade") .and_return("product_upgrades" => [{ - "from" => "openSUSE Leap", - "to" => "openSUSE Jump" - }]) + "from" => "openSUSE Leap", + "to" => "openSUSE Jump" + }]) end it "does not set compatible vendors at all" do @@ -459,10 +459,10 @@ def default_SetDesktopPattern_stubs allow(Yast::ProductFeatures).to receive(:GetFeature) .with("software", "upgrade") .and_return("product_upgrades" => [{ - "from" => "openSUSE Leap", - "to" => "openSUSE Jump", - "compatible_vendors" => ["openSUSE", "SLES LCC"] - }]) + "from" => "openSUSE Leap", + "to" => "openSUSE Jump", + "compatible_vendors" => ["openSUSE", "SLES LCC"] + }]) end it "set it in the solver" do From 6a28d3205df014f515bba583ebaf078269d149b8 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Fri, 22 Dec 2023 16:17:21 +0100 Subject: [PATCH 2/3] new rubocop: auto corrections with -A --- src/clients/backup_proposal.rb | 7 ++++--- src/clients/packages_proposal.rb | 7 ++++--- src/clients/rootpart_proposal.rb | 7 ++++--- src/clients/update_proposal.rb | 12 +++++++----- src/include/update/rootpart.rb | 5 +++-- src/modules/RootPart.rb | 12 +++++++----- src/modules/SUSERelease.rb | 3 --- 7 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/clients/backup_proposal.rb b/src/clients/backup_proposal.rb index 8739efaa..e39d8a80 100644 --- a/src/clients/backup_proposal.rb +++ b/src/clients/backup_proposal.rb @@ -38,7 +38,8 @@ def main @param = Convert.to_map(WFM.Args(1)) @ret = {} - if @func == "MakeProposal" + case @func + when "MakeProposal" @force_reset = Ops.get_boolean(@param, "force_reset", false) @language_changed = Ops.get_boolean(@param, "language_changed", false) @@ -81,7 +82,7 @@ def main end @ret = { "preformatted_proposal" => HTML.List(@tmp) } - elsif @func == "AskUser" + when "AskUser" @has_next = Ops.get_boolean(@param, "has_next", false) # call some function that displays a user dialog @@ -96,7 +97,7 @@ def main # Fill return map @ret = { "workflow_sequence" => @result } - elsif @func == "Description" + when "Description" # Fill return map. # # Static values do just nicely here, no need to call a function. diff --git a/src/clients/packages_proposal.rb b/src/clients/packages_proposal.rb index f0cd899e..3e8b6583 100644 --- a/src/clients/packages_proposal.rb +++ b/src/clients/packages_proposal.rb @@ -49,7 +49,8 @@ def main @param = Convert.to_map(WFM.Args(1)) @ret = {} - if @func == "MakeProposal" + case @func + when "MakeProposal" @force_reset = Ops.get_boolean(@param, "force_reset", false) @language_changed = Ops.get_boolean(@param, "language_changed", false) @@ -188,7 +189,7 @@ def main ret_ref = arg_ref(@ret) Packages.CheckOldAddOns(ret_ref) @ret = ret_ref.value - elsif @func == "AskUser" + when "AskUser" @has_next = Ops.get_boolean(@param, "has_next", false) # call some function that displays a user dialog @@ -202,7 +203,7 @@ def main # Fill return map @ret = { "workflow_sequence" => @result } - elsif @func == "Description" + when "Description" # Fill return map. # # Static values do just nicely here, no need to call a function. diff --git a/src/clients/rootpart_proposal.rb b/src/clients/rootpart_proposal.rb index 7ff7b161..02fde4ed 100644 --- a/src/clients/rootpart_proposal.rb +++ b/src/clients/rootpart_proposal.rb @@ -43,7 +43,8 @@ def main @param = Convert.to_map(WFM.Args(1)) @ret = {} - if @func == "MakeProposal" + case @func + when "MakeProposal" @force_reset = Ops.get_boolean(@param, "force_reset", false) @language_changed = Ops.get_boolean(@param, "language_changed", false) @@ -113,7 +114,7 @@ def main @ret = Builtins.add(@ret, "raw_proposal", []) end end - elsif @func == "AskUser" + when "AskUser" @has_next = Ops.get_boolean(@param, "has_next", false) # call some function that displays a user dialog @@ -138,7 +139,7 @@ def main "workflow_sequence" => @result, "rootpart_changed" => RootPart.selectedRootPartition != @tmp } - elsif @func == "Description" + when "Description" # Fill return map. @ret = if Mode.normal diff --git a/src/clients/update_proposal.rb b/src/clients/update_proposal.rb index b0ca7268..5c123e8a 100644 --- a/src/clients/update_proposal.rb +++ b/src/clients/update_proposal.rb @@ -59,7 +59,8 @@ def main @rpm_db_existency_checked_already = false - if @func == "MakeProposal" + case @func + when "MakeProposal" @force_reset = Ops.get_boolean(@param, "force_reset", false) @language_changed = Ops.get_boolean(@param, "language_changed", false) @@ -218,12 +219,12 @@ def main end # save the solver test case with details for later debugging Pkg.CreateSolverTestCase("/var/log/YaST2/solver-upgrade-proposal") if @ret["warning"] - elsif @func == "AskUser" + when "AskUser" # With proper control file, this should never be reached # TRANSLATORS: error message Report.Error(_("The update summary is read only and cannot be changed.")) @ret = { "workflow_sequence" => :back } - elsif @func == "Description" + when "Description" # Fill return map. # # Static values do just nicely here, no need to call a function. @@ -363,11 +364,12 @@ def CheckRPMDBforExistency ui_r = UI.UserInput - if ui_r == :cancel || ui_r == :abort + case ui_r + when :cancel, :abort ret = false file_found_or_error_skipped = true Builtins.y2milestone("Check failed, returning error.") - elsif ui_r == :retry + when :retry file_found_or_error_skipped = false Builtins.y2milestone("Trying again...") # } else if (ui_r == `ignore) { diff --git a/src/include/update/rootpart.rb b/src/include/update/rootpart.rb index c6890a4c..10c56cfb 100644 --- a/src/include/update/rootpart.rb +++ b/src/include/update/rootpart.rb @@ -284,10 +284,11 @@ def RootPartitionDialog(flavor) # finishing the target before selecting a new system to load Pkg.TargetFinish if flavor == :update_dialog - if flavor == :update_dialog + case flavor + when :update_dialog Wizard.SetContents(title, contents, help_text, true, true) Wizard.EnableAbortButton if Mode.autoupgrade - elsif flavor == :update_dialog_proposal + when :update_dialog_proposal Wizard.CreateDialog Wizard.SetContentsButtons( title, diff --git a/src/modules/RootPart.rb b/src/modules/RootPart.rb index 355f1c6a..aa7435b2 100644 --- a/src/modules/RootPart.rb +++ b/src/modules/RootPart.rb @@ -186,7 +186,8 @@ def UnmountPartitions(keep_in_target) Builtins.y2milestone("Unmounting %1", info) type = Ops.get_string(info, :type, "") if type != "" - if type == "mount" + case type + when "mount" file = Ops.add( Installation.destdir, Ops.get_string(info, :mntpt, "") @@ -206,7 +207,7 @@ def UnmountPartitions(keep_in_target) ) ) end - elsif type == "swap" + when "swap" device = Ops.get_string(info, :device, "") # FIXME? is it safe? if SCR.Execute( @@ -215,7 +216,7 @@ def UnmountPartitions(keep_in_target) ) != 0 Builtins.y2error("Cannot deactivate swap %1", device) end - elsif type == "crypt" + when "crypt" dmname = Ops.get_string(info, :device, "") dmname = Ops.add( "cr_", @@ -333,10 +334,11 @@ def AnyQuestionAnyButtonsDetails(headline, question, button_yes, button_no, deta loop do userinput = UI.UserInput - if userinput == :yes + case userinput + when :yes ret = true break - elsif userinput == :details + when :details curr_status = Convert.to_boolean(UI.QueryWidget(Id(:details), :Value)) if curr_status == false diff --git a/src/modules/SUSERelease.rb b/src/modules/SUSERelease.rb index 5012aa6b..dfd39806 100644 --- a/src/modules/SUSERelease.rb +++ b/src/modules/SUSERelease.rb @@ -29,9 +29,6 @@ module Yast class SUSEReleaseFileMissingError < StandardError - def initialize(message) - super message - end end class SUSEReleaseClass < Module From 98ee3e446797376c9874d19a8e9d8ed283df00d4 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Fri, 22 Dec 2023 16:32:20 +0100 Subject: [PATCH 3/3] new rubocop: manual fixes --- .rubocop.yml | 2 +- src/lib/update/clients/inst_update_partition_auto.rb | 2 ++ src/modules/RootPart.rb | 6 ++---- src/modules/SUSERelease.rb | 2 ++ 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 07b36878..60bede6d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -18,7 +18,7 @@ Lint/UnderscorePrefixedVariableName: # Offense count: 25 Metrics/AbcSize: - Max: 190 + Max: 200 # Offense count: 23 # Configuration parameters: CountComments, ExcludedMethods. diff --git a/src/lib/update/clients/inst_update_partition_auto.rb b/src/lib/update/clients/inst_update_partition_auto.rb index b5a5979e..76de8e1c 100644 --- a/src/lib/update/clients/inst_update_partition_auto.rb +++ b/src/lib/update/clients/inst_update_partition_auto.rb @@ -31,6 +31,8 @@ class InstUpdatePartitionAutoClient < Client DATA_PATH = "/var/lib/YaST2/update_partition_auto.yaml".freeze def initialize + super + Yast.import "Pkg" Yast.import "UI" diff --git a/src/modules/RootPart.rb b/src/modules/RootPart.rb index aa7435b2..8785a343 100644 --- a/src/modules/RootPart.rb +++ b/src/modules/RootPart.rb @@ -1101,14 +1101,12 @@ def MountPartitions(root_device_current) else tmp = "" - if tmp_ref = arg_ref(tmp) - check_root_device_result = check_root_device( + if (tmp_ref = arg_ref(tmp)) + check_root_device( root_device_current, fstab, tmp_ref ) - tmp = tmp_ref.value - check_root_device_result Builtins.y2milestone("fstab %1", fstab) diff --git a/src/modules/SUSERelease.rb b/src/modules/SUSERelease.rb index dfd39806..191477ed 100644 --- a/src/modules/SUSERelease.rb +++ b/src/modules/SUSERelease.rb @@ -37,6 +37,8 @@ class SUSEReleaseClass < Module RELEASE_FILE_PATH = "/etc/SuSE-release".freeze def initialize + super + textdomain "update" Yast.import "FileUtils"