Use f-strings in tuna where possible

Resolves: rhbz#2120803

Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>
This commit is contained in:
Leah Leshchinsky 2022-11-02 13:25:51 -04:00
parent 053808b527
commit 468781debe
No known key found for this signature in database
GPG Key ID: 1674BC3F464A7C0C
4 changed files with 203 additions and 1 deletions

View File

@ -0,0 +1,75 @@
From 1e2f6a3b64bce4ea335e97b1ab31ada3e082a6bc Mon Sep 17 00:00:00 2001
From: Leah Leshchinsky <lleshchi@redhat.com>
Date: Tue, 1 Nov 2022 13:24:00 -0400
Subject: [PATCH 2/4] tuna: tuna-cmd.py use fstrings
Add fstrings where possible to improve readabilty
Due to the discussion regarding dropping the language feature, gettext
shorthand _() have been removed.
Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>
Signed-off-by: John Kacur <jkacur@redhat.com>
diff --git a/tuna-cmd.py b/tuna-cmd.py
index c5bc65059da7..44d9faaf15fb 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -89,7 +89,7 @@ irqs = None
class HelpMessageParser(argparse.ArgumentParser):
def error(self, message):
- sys.stderr.write('error: %s\n' % message)
+ sys.stderr.write(f'error: {message}\n')
self.print_help()
sys.exit(2)
@@ -263,13 +263,16 @@ def thread_help(tid):
ps = procfs.pidstats()
if tid not in ps:
- print("tuna: " + _("thread %d doesn't exists!") % tid)
+ print(f"tuna: thread {tid} doesn't exist!")
return
pinfo = ps[tid]
cmdline = procfs.process_cmdline(pinfo)
help, title = tuna.kthread_help_plain_text(tid, cmdline)
- print("%s\n\n%s" % (title, _(help)))
+ print(title, "\n\n")
+ if help.isspace():
+ help = "No help description available."
+ print(help)
def save(cpu_list, thread_list, filename):
@@ -295,7 +298,7 @@ def ps_show_header(has_ctxt_switch_info, cgroups=False):
def ps_show_sockets(pid, ps, inodes, inode_re, indent=0):
header_printed = False
- dirname = "/proc/%s/fd" % pid
+ dirname = f"/proc/{pid}/fd"
try:
filenames = os.listdir(dirname)
except: # Process died
@@ -688,7 +691,7 @@ def main():
try:
tuna.threads_set_priority(args.thread_list, args.priority, args.affect_children)
except OSError as err:
- print("tuna: %s" % err)
+ print(f"tuna: {err}")
sys.exit(2)
elif args.command in ['show_configs']:
@@ -705,7 +708,7 @@ def main():
spread = args.command in ['spread', 'x']
if not (args.thread_list or args.irq_list):
- parser.error("tuna: %s " % (args.command) + _("requires a thread/irq list!\n"))
+ parser.error(f"tuna: {args.command} requires a thread/irq list!\n")
if args.thread_list:
tuna.move_threads_to_cpu(args.cpu_list, args.thread_list, spread=spread)
--
2.31.1

View File

@ -0,0 +1,94 @@
From efcc75a317b63227a8630ca17e9bcf153a6cc03e Mon Sep 17 00:00:00 2001
From: Leah Leshchinsky <lleshchi@redhat.com>
Date: Mon, 31 Oct 2022 13:11:31 -0400
Subject: [PATCH 3/4] tuna: tuna.py use fstrings
Add fstrings where possible to improve readabilty
Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>
Signed-off-by: John Kacur <jkacur@redhat.com>
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 43adb84079e4..e527facb151c 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -58,7 +58,7 @@ def iskthread(pid):
# in this function, so that they know that the thread vanished and
# can act accordingly, removing entries from tree views, etc
try:
- f = open("/proc/%d/smaps" % pid)
+ f = open(f"/proc/{pid}/smaps")
except IOError:
# Thread has vanished
return True
@@ -88,7 +88,7 @@ def is_irq_thread(cmd):
return cmd[:4] in ("IRQ-", "irq/")
def threaded_irq_re(irq):
- return re.compile("(irq/%s-.+|IRQ-%s)" % (irq, irq))
+ return re.compile(f"(irq/{irq}-.+|IRQ-{irq})")
# FIXME: Move to python-linux-procfs
def has_threaded_irqs(ps):
@@ -96,10 +96,10 @@ def has_threaded_irqs(ps):
return len(ps.find_by_regex(irq_re)) > 0
def set_irq_affinity_filename(filename, bitmasklist):
- pathname = "/proc/irq/%s" % filename
+ pathname = f"/proc/irq/{filename}"
f = open(pathname, "w")
text = ",".join(["%x" % a for a in bitmasklist])
- f.write("%s\n" % text)
+ f.write(f"{text}\n")
try:
f.close()
except IOError:
@@ -225,7 +225,7 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning=None, spread=False)
if pid not in ps:
continue
- threads = procfs.pidstats("/proc/%d/task" % pid)
+ threads = procfs.pidstats(f"/proc/{pid}/task")
for tid in list(threads.keys()):
try:
curr_affinity = os.sched_getaffinity(tid)
@@ -320,11 +320,11 @@ def affinity_remove_cpus(affinity, cpus, nr_cpus):
# Should be moved to python_linux_procfs.interrupts, shared with interrupts.parse_affinity, etc.
def parse_irq_affinity_filename(filename, nr_cpus):
try:
- f = open("/proc/irq/%s" % filename)
+ f = open(f"/proc/irq/{filename}")
except IOError as err:
if procfs.is_s390():
print("This operation is not supported on s390", file=sys.stderr)
- print("tuna: %s" % err, file=sys.stderr)
+ print(f"tuna: {err}", file=sys.stderr)
sys.exit(2)
line = f.readline()
@@ -624,19 +624,19 @@ def run_command(cmd, policy, rtprio, cpu_list, background):
try:
thread_set_priority(pid, policy, rtprio)
except (SystemError, OSError) as err:
- print("tuna: %s" % err)
+ print(f"tuna: {err}")
sys.exit(2)
if cpu_list:
try:
os.sched_setaffinity(pid, cpu_list)
except (SystemError, OSError) as err:
- print("tuna: %s" % err)
+ print(f"tuna: {err}")
sys.exit(2)
try:
os.execvp(cmd_list[0], cmd_list)
except (SystemError, OSError) as err:
- print("tuna: %s" % err)
+ print(f"tuna: {err}")
sys.exit(2)
else:
if not background:
--
2.31.1

View File

@ -0,0 +1,26 @@
From 67c5a4dc31f7dd8a6204a1a636fcec4e8f17a86b Mon Sep 17 00:00:00 2001
From: Leah Leshchinsky <lleshchi@redhat.com>
Date: Fri, 28 Oct 2022 12:52:46 -0400
Subject: [PATCH 1/4] tuna: tuna_gui.py use fstrings
Add fstrings where possible to improve readabilty
Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>
Signed-off-by: John Kacur <jkacur@redhat.com>
diff --git a/tuna/tuna_gui.py b/tuna/tuna_gui.py
index f1f2caacbcba..459f90303ed5 100755
--- a/tuna/tuna_gui.py
+++ b/tuna/tuna_gui.py
@@ -33,7 +33,7 @@ class main_gui:
if self.check_root():
sys.exit(1)
for dir in tuna_glade_dirs:
- tuna_glade = "%s/tuna_gui.glade" % dir
+ tuna_glade = f"{dir}/tuna_gui.glade"
if os.access(tuna_glade, os.F_OK):
break
self.wtree = Gtk.Builder()
--
2.31.1

View File

@ -1,6 +1,6 @@
Name: tuna
Version: 0.18
Release: 7%{?dist}
Release: 8%{?dist}
License: GPLv2
Summary: Application tuning GUI & command line utility
URL: https://git.kernel.org/pub/scm/utils/tuna/tuna.git
@ -19,6 +19,9 @@ Patch3: tuna-Add-sockets-command-line-option.patch
Patch4: tuna-Replace-python_ethtool-with-builtin-funtionalit.patch
Patch5: tuna-Fix-matching-irqs-in-ps_show_thread.patch
Patch6: tuna-Remove-threads-print-statement.patch
Patch7: tuna-tuna_gui.py-use-fstrings.patch
Patch8: tuna-tuna-cmd.py-use-fstrings.patch
Patch9: tuna-tuna.py-use-fstrings.patch
%description
Provides interface for changing scheduler and IRQ tunables, at whole CPU and at
@ -72,6 +75,10 @@ done
%{_datadir}/polkit-1/actions/org.tuna.policy
%changelog
* Wed Nov 02 2022 Leah Leshchinsky <lleshchi@redhat.com> - 0.18-8
- Use f-strings in tuna where possible
Resolves: rhbz#2120803
* Wed Oct 26 2022 Leah Leshchinsky <lleshchi@redhat.com> - 0.18-7
- Add sockets command line option
Resolves: rhbz#2122781