[PATCH 0/2] tuna: use fstrings
by Leah Leshchinsky
fstring changes targeted for getopt branch
Leah Leshchinsky (2):
tuna: tuna_gui.py use fstrings
tuna: tuna.py use fstrings
tuna/tuna.py | 20 ++++++++++----------
tuna/tuna_gui.py | 2 +-
2 files changed, 11 insertions(+), 11 deletions(-)
--
2.31.1
1 year, 1 month
[PATCH v2] tuna: tuna.py use fstrings
by Leah Leshchinsky
Add fstrings where possible to improve readabilty
Signed-off-by: Leah Leshchinsky <lleshchi(a)redhat.com>
---
Fixed pathname = f"/proc/irq/{filename}"
target branch: getopt
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 84419c957b1b..e64211b88fc3 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()
@@ -627,19 +627,19 @@ def run_command(cmd, policy, rtprio, cpu_list):
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:
os.waitpid(newpid, 0)
--
2.31.1
1 year, 1 month
[PATCH v2] tuna: tuna.py use fstrings
by Leah Leshchinsky
Add fstrings where possible to improve readabilty
Signed-off-by: Leah Leshchinsky <lleshchi(a)redhat.com>
---
Fixed pathname = f"/proc/irq/{filename}"
Target branch: main
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
1 year, 1 month
[PATCH 1/3] tuna: tuna-cmd.py use fstrings
by Leah Leshchinsky
Add fstrings where possible to improve readabilty
Signed-off-by: Leah Leshchinsky <lleshchi(a)redhat.com>
diff --git a/tuna-cmd.py b/tuna-cmd.py
index c5bc65059da7..fa07909967c8 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,13 @@ 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 exists!")
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(f"{title}\n\n{help}")
def save(cpu_list, thread_list, filename):
@@ -295,7 +295,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 +688,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 +705,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
1 year, 1 month
[PATCH] tuna: Remove threads print statement
by Leah Leshchinsky
Remove unnecessary print statement from threadstring_to_list function
Signed-off-by: Leah Leshchinsky <lleshchi(a)redhat.com>
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 80e27523acc6..c5bc65059da7 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -533,7 +533,6 @@ def threadstring_to_list(threadstr):
global ps
thread_list = []
thread_strings = list(set(threadstr.split(',')))
- print(thread_strings)
for s in thread_strings:
if s.isdigit():
thread_list.append(int(s))
--
2.31.1
1 year, 1 month