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

chore: replace percent strings for logging #1448

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 6 additions & 4 deletions convert2rhel/actions/system_checks/package_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ 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",
id="PACKAGE_UPDATES_CHECK_SKIP_NO_PUBLIC_REPOSITORIES",
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions convert2rhel/applock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 3 additions & 2 deletions convert2rhel/backup/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
9 changes: 3 additions & 6 deletions convert2rhel/pkghandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got this from Grok AI since it's been long since I wrote that code:

%-*s in print("%-*s" % (width, "text")) is a format specifier where:
   * means the width of the field is given by the first argument in the tuple (width in this case).
   - means left-align the text within that width.
   s means it's formatting a string.```

The format() replacement would look like print("{:<{}}".format("text", width)).

{:<{}} means:
  < aligns the text to the left.
  {} specifies the field width.```

% (
"{}-{} {}-{} {}".format(
max_nvra_length,
"Package",
max_packager_length,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions convert2rhel/pkgmanager/handlers/dnf/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -206,15 +206,15 @@ 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"),
package,
)
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)
Expand Down
2 changes: 1 addition & 1 deletion convert2rhel/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
10 changes: 5 additions & 5 deletions convert2rhel/systeminfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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,
Expand Down
Loading