From 193f6f6ff487db4b62464cc394d8f7ddaafce015 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 9 Dec 2024 16:55:45 +0000 Subject: [PATCH 1/3] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.7.3 → v0.8.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.3...v0.8.2) - [github.com/teemtee/tmt.git: 1.38.0 → 1.39.0](https://github.com/teemtee/tmt.git/compare/1.38.0...1.39.0) - [github.com/jendrikseipp/vulture: v2.13 → v2.14](https://github.com/jendrikseipp/vulture/compare/v2.13...v2.14) --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 03e0840f0d..5bbd97c81e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ minimum_pre_commit_version: "2.9.0" repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.7.3 + rev: v0.8.2 hooks: # Run the linter. - id: ruff @@ -23,7 +23,7 @@ repos: hooks: - id: "check-json5" - repo: "https://github.com/teemtee/tmt.git" - rev: "1.38.0" + rev: "1.39.0" hooks: - id: "tmt-tests-lint" verbose: false @@ -42,6 +42,6 @@ repos: - id: gitleaks stages: [manual, pre-push] - repo: https://github.com/jendrikseipp/vulture - rev: v2.13 + rev: v2.14 hooks: - id: vulture From 0401fceb78ae7ce46b3ae5bd18ab8dee564fab45 Mon Sep 17 00:00:00 2001 From: Freya Gustavsson Date: Wed, 11 Dec 2024 16:56:14 +0100 Subject: [PATCH 2/3] chore: replace percent strings for logging This replaces logging with their best counterpart. Either normal logging methods with arguments, or by utilizing `.format()` --- .../actions/system_checks/is_loaded_kernel_latest.py | 6 ++++-- convert2rhel/actions/system_checks/package_updates.py | 10 ++++++---- .../actions/system_checks/rhel_compatible_kernel.py | 5 +++-- convert2rhel/applock.py | 6 +++--- convert2rhel/backup/packages.py | 5 +++-- convert2rhel/pkghandler.py | 9 +++------ convert2rhel/pkgmanager/handlers/dnf/callback.py | 6 +++--- convert2rhel/subscription.py | 2 +- convert2rhel/systeminfo.py | 10 +++++----- 9 files changed, 31 insertions(+), 28 deletions(-) diff --git a/convert2rhel/actions/system_checks/is_loaded_kernel_latest.py b/convert2rhel/actions/system_checks/is_loaded_kernel_latest.py index 02e023b132..d3bb76f6ab 100644 --- a/convert2rhel/actions/system_checks/is_loaded_kernel_latest.py +++ b/convert2rhel/actions/system_checks/is_loaded_kernel_latest.py @@ -39,8 +39,10 @@ def run(self): if system_info.id == "oracle" and system_info.eus_system: logger.info( - "Did not perform the check because there were no publicly available %s %d.%d repositories available." - % (system_info.name, system_info.version.major, system_info.version.minor) + "Did not perform the check because there were no publicly available %s %d.%d repositories available.", + system_info.name, + system_info.version.major, + system_info.version.minor, ) return diff --git a/convert2rhel/actions/system_checks/package_updates.py b/convert2rhel/actions/system_checks/package_updates.py index 0572fcba9f..d51b7a6923 100644 --- a/convert2rhel/actions/system_checks/package_updates.py +++ b/convert2rhel/actions/system_checks/package_updates.py @@ -35,8 +35,9 @@ def run(self): if system_info.id == "oracle" and system_info.eus_system: logger.info( - "Did not perform the check because there were no publicly available %s %d.%d repositories available." - % (system_info.name, system_info.version.major, system_info.version.minor) + "Did not perform the check because there were no publicly available {} {}.{} repositories available.".format( + system_info.name, system_info.version.major, system_info.version.minor + ) ) self.add_message( level="INFO", @@ -44,8 +45,9 @@ def run(self): title="Did not perform the package updates check", description="Please refer to the diagnosis for further information", diagnosis=( - "Did not perform the check because there were no publicly available %s %d.%d repositories available." - % (system_info.name, system_info.version.major, system_info.version.minor) + "Did not perform the check because there were no publicly available {} {}.{} repositories available.".format( + system_info.name, system_info.version.major, system_info.version.minor + ) ), ) return diff --git a/convert2rhel/actions/system_checks/rhel_compatible_kernel.py b/convert2rhel/actions/system_checks/rhel_compatible_kernel.py index 9945597a7a..fe30dfc1a6 100644 --- a/convert2rhel/actions/system_checks/rhel_compatible_kernel.py +++ b/convert2rhel/actions/system_checks/rhel_compatible_kernel.py @@ -116,8 +116,9 @@ def _bad_kernel_version(kernel_release): ) logger.debug( - "Booted kernel version '%s' corresponds to the version available in RHEL %d" - % (kernel_version, system_info.version.major) + "Booted kernel version '{}' corresponds to the version available in RHEL {}".format( + kernel_version, system_info.version.major + ) ) return False diff --git a/convert2rhel/applock.py b/convert2rhel/applock.py index cdead1cb09..fc5b0b1e31 100644 --- a/convert2rhel/applock.py +++ b/convert2rhel/applock.py @@ -72,7 +72,7 @@ def __str__(self): status = "locked" else: status = "unlocked" - return "%s PID %d %s" % (self._pidfile, self._pid, status) + return "{} PID {} {}".format(self._pidfile, self._pid, status) def _try_create(self): """Try to create the lock file. If this succeeds, the lock file @@ -149,10 +149,10 @@ def try_to_lock(self, _recursive=False): raise ApplicationLockedError("Lock file {} is corrupt".format(self._pidfile)) if self._pid_exists(pid): - raise ApplicationLockedError("%s locked by process %d" % (self._pidfile, pid)) + raise ApplicationLockedError("{} locked by process {}".format(self._pidfile, pid)) # The lock file was created by a process that has exited; # remove it and try again. - logger.info("Cleaning up lock held by exited process %d." % pid) + logger.info("Cleaning up lock held by exited process %d.", pid) os.unlink(self._pidfile) self.try_to_lock(_recursive=True) diff --git a/convert2rhel/backup/packages.py b/convert2rhel/backup/packages.py index 2ab1a44275..acd27d55f6 100644 --- a/convert2rhel/backup/packages.py +++ b/convert2rhel/backup/packages.py @@ -172,8 +172,9 @@ def _install_local_rpms(self, replace=False, critical=True): "one or more packages that we removed as part of the " "conversion." ), - diagnosis="Couldn't install %s packages. Command: %s Output: %s Status: %d" - % (pkgs_as_str, cmd, output, ret_code), + diagnosis="Couldn't install {} packages. Command: {} Output: {} Status: {}".format( + pkgs_as_str, cmd, output, ret_code + ), ) logger.warning("Couldn't install {} packages.".format(pkgs_as_str)) diff --git a/convert2rhel/pkghandler.py b/convert2rhel/pkghandler.py index 98f2a2d51c..8516478c5c 100644 --- a/convert2rhel/pkghandler.py +++ b/convert2rhel/pkghandler.py @@ -318,8 +318,7 @@ def format_pkg_info(pkgs, disable_repos=None): max_nvra_length = max(len(nvra) for nvra in package_info) header = ( - "%-*s %-*s %s" - % ( + "{}-{} {}-{} {}".format( max_nvra_length, "Package", max_packager_length, @@ -329,8 +328,7 @@ def format_pkg_info(pkgs, disable_repos=None): + "\n" ) header_underline = ( - "%-*s %-*s %s" - % ( + "{}-{} {}-{} {}".format( max_nvra_length, "-" * len("Package"), max_packager_length, @@ -348,8 +346,7 @@ def format_pkg_info(pkgs, disable_repos=None): pkg_list = "" for package, info in package_info.items(): pkg_list += ( - "%-*s %-*s %s" - % ( + "{}-{} {}-{} {}".format( max_nvra_length, package, max_packager_length, diff --git a/convert2rhel/pkgmanager/handlers/dnf/callback.py b/convert2rhel/pkgmanager/handlers/dnf/callback.py index 0155a409d1..45d5351cc4 100644 --- a/convert2rhel/pkgmanager/handlers/dnf/callback.py +++ b/convert2rhel/pkgmanager/handlers/dnf/callback.py @@ -196,7 +196,7 @@ def end(self, payload, status, err_msg): if status: # the error message, no trimming if status == pkgmanager.callback.STATUS_DRPM and self.total_drpm > 1: - message = "(%d/%d) [%s %d/%d]: %s" % ( + message = "({}/{}) [{} {}/{}]: {}".format( self.done_files, self.total_files, self._STATUS_MAPPING[status], @@ -206,7 +206,7 @@ def end(self, payload, status, err_msg): ) message = "{} - {}".format(message, err_msg) else: - message = "(%d/%d) [%s]: %s" % ( + message = "({}/{}) [{}]: {}".format( self.done_files, self.total_files, self._STATUS_MAPPING.get(status, "Unknown"), @@ -214,7 +214,7 @@ def end(self, payload, status, err_msg): ) else: if self.total_files > 1: - message = "(%d/%d): %s" % (self.done_files, self.total_files, package) + message = "({}/{}): {}".format(self.done_files, self.total_files, package) if message: logger.info(message) diff --git a/convert2rhel/subscription.py b/convert2rhel/subscription.py index 9b4cc736bb..7335435672 100644 --- a/convert2rhel/subscription.py +++ b/convert2rhel/subscription.py @@ -155,7 +155,7 @@ def register_system(): while attempt < MAX_NUM_OF_ATTEMPTS_TO_SUBSCRIBE: attempt_msg = "" if attempt > 0: - attempt_msg = "Attempt %d of %d: " % ( + attempt_msg = "Attempt {} of {}: ".format( attempt + 1, MAX_NUM_OF_ATTEMPTS_TO_SUBSCRIBE, ) diff --git a/convert2rhel/systeminfo.py b/convert2rhel/systeminfo.py index e296c10d34..3739be7de7 100644 --- a/convert2rhel/systeminfo.py +++ b/convert2rhel/systeminfo.py @@ -182,10 +182,10 @@ def resolve_system_info(self): def print_system_information(self): """Print system related information.""" - self.logger.info("%-20s %s" % ("Name:", self.name)) - self.logger.info("%-20s %s" % ("OS version:", self.version)) - self.logger.info("%-20s %s" % ("Architecture:", self.arch)) - self.logger.info("%-20s %s" % ("Config filename:", self.cfg_filename)) + self.logger.info("%-20s %s", "Name:", self.name) + self.logger.info("%-20s %s", "OS version:", self.version) + self.logger.info("%-20s %s", "Architecture:", self.arch) + self.logger.info("%-20s %s", "Config filename:", self.cfg_filename) @staticmethod def get_system_release_file_content(): @@ -282,7 +282,7 @@ def _get_architecture(self): return arch def _get_cfg_filename(self): - cfg_filename = "%s-%d-%s.cfg" % ( + cfg_filename = "{}-{}-{}.cfg".format( self.id, self.version.major, self.arch, From d78a11d6302103c391326048d989785bb26b9f0d Mon Sep 17 00:00:00 2001 From: Freya Gustavsson Date: Thu, 16 Jan 2025 14:28:02 +0100 Subject: [PATCH 3/3] fix: Convert parametrized %-strings This changes `%-*s %-*s %s` %-string to their format counterpart `%-*s` = left-padded with next %-parameter indicating substring length or precision length. --- convert2rhel/pkghandler.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/convert2rhel/pkghandler.py b/convert2rhel/pkghandler.py index 8516478c5c..a214c957e8 100644 --- a/convert2rhel/pkghandler.py +++ b/convert2rhel/pkghandler.py @@ -318,22 +318,22 @@ def format_pkg_info(pkgs, disable_repos=None): max_nvra_length = max(len(nvra) for nvra in package_info) header = ( - "{}-{} {}-{} {}".format( - max_nvra_length, + "{:{nvra}} {:{pkgr}} {}".format( "Package", - max_packager_length, "Vendor/Packager", "Repository", + nvra=max_nvra_length, + pkgr=max_packager_length, ) + "\n" ) header_underline = ( - "{}-{} {}-{} {}".format( - max_nvra_length, + "{:{nvra}} {:{pkgr}} {}".format( "-" * len("Package"), - max_packager_length, "-" * len("Vendor/Packager"), "-" * len("Repository"), + nvra=max_nvra_length, + pkgr=max_packager_length, ) + "\n" ) @@ -346,12 +346,12 @@ def format_pkg_info(pkgs, disable_repos=None): pkg_list = "" for package, info in package_info.items(): pkg_list += ( - "{}-{} {}-{} {}".format( - max_nvra_length, + "{:{nvra}} {:{pkgr}} {}".format( package, - max_packager_length, info["packager"], info["repoid"], + nvra=max_nvra_length, + pkgr=max_packager_length, ) + "\n" )