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