diff mbox series

[v2] tuna: Fix string syntax warnings with raw strings

Message ID 20241028215717.250390-1-jwyatt@redhat.com
State New
Headers show
Series [v2] tuna: Fix string syntax warnings with raw strings | expand

Commit Message

John B. Wyatt IV Oct. 28, 2024, 9:57 p.m. UTC
tuna save <filename> allows you to save your kthreads tunables to
a file to be used by rtctl. There were several backslashes that produce
an error that pylint and Python (at least 3.12) gives a SyntaxWarning:
invalid escape sequence

Switch the strings written to the file with raw strings to resolve the
warning for this section of the code.

Tested by comparing the diffs of the files.

Signed-off-by: John B. Wyatt IV <jwyatt@redhat.com>
Signed-off-by: John B. Wyatt IV <sageofredondo@gmail.com>
---

Changes in v2:
	- Combine the second lines of '\n' to be concatenated with the
	  raw strings.

---
 tuna/tuna.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

John Kacur Oct. 30, 2024, 10:08 p.m. UTC | #1
On Mon, 28 Oct 2024, John B. Wyatt IV wrote:

> tuna save <filename> allows you to save your kthreads tunables to
> a file to be used by rtctl. There were several backslashes that produce
> an error that pylint and Python (at least 3.12) gives a SyntaxWarning:
> invalid escape sequence
> 
> Switch the strings written to the file with raw strings to resolve the
> warning for this section of the code.
> 
> Tested by comparing the diffs of the files.
> 
> Signed-off-by: John B. Wyatt IV <jwyatt@redhat.com>
> Signed-off-by: John B. Wyatt IV <sageofredondo@gmail.com>
> ---
> 
> Changes in v2:
> 	- Combine the second lines of '\n' to be concatenated with the
> 	  raw strings.
> 
> ---
>  tuna/tuna.py | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/tuna/tuna.py b/tuna/tuna.py
> index bd678e2..d4c3e2c 100755
> --- a/tuna/tuna.py
> +++ b/tuna/tuna.py
> @@ -669,7 +669,7 @@ def generate_rtgroups(filename, kthreads, nr_cpus):
>  # The regex is matched against process names as printed by "ps -eo cmd".
>  
>  ''' % filename)
> -    f.write("kthreads:*:1:*:\[.*\]$\n\n")
> +    f.write(r"kthreads:*:1:*:\[.*\]$" + "\n\n")
>  
>      per_cpu_kthreads = []
>      names = list(kthreads.keys())
> @@ -688,7 +688,7 @@ def generate_rtgroups(filename, kthreads, nr_cpus):
>              elif common[:8] == "softirq-":
>                  common = "(sirq|softirq)" + common[7:]
>                  name = "s" + name[4:]
> -            regex = common + "\/.*"
> +            regex = common + r"\/.*"
>          except:
>              idx = 0
>              regex = name
> @@ -701,9 +701,9 @@ def generate_rtgroups(filename, kthreads, nr_cpus):
>          else:
>              mask = ",".join([hex(a) for a in \
>                       procfs.hexbitmask(kt.affinity, nr_cpus)])
> -        f.write("%s:%c:%d:%s:\[%s\]$\n" % (name, \
> +        f.write(r"%s:%c:%d:%s:\[%s\]$" % (name, \
>                             tuna_sched.sched_str(kt.policy)[6].lower(), \
> -                            kt.rtprio, mask, regex))
> +                            kt.rtprio, mask, regex) + "\n")
>      f.close()
>  
>  
> -- 

Signed-off-by: John Kacur <jkacur@redhat.com>

Thank you John Wyatt
diff mbox series

Patch

diff --git a/tuna/tuna.py b/tuna/tuna.py
index bd678e2..d4c3e2c 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -669,7 +669,7 @@  def generate_rtgroups(filename, kthreads, nr_cpus):
 # The regex is matched against process names as printed by "ps -eo cmd".
 
 ''' % filename)
-    f.write("kthreads:*:1:*:\[.*\]$\n\n")
+    f.write(r"kthreads:*:1:*:\[.*\]$" + "\n\n")
 
     per_cpu_kthreads = []
     names = list(kthreads.keys())
@@ -688,7 +688,7 @@  def generate_rtgroups(filename, kthreads, nr_cpus):
             elif common[:8] == "softirq-":
                 common = "(sirq|softirq)" + common[7:]
                 name = "s" + name[4:]
-            regex = common + "\/.*"
+            regex = common + r"\/.*"
         except:
             idx = 0
             regex = name
@@ -701,9 +701,9 @@  def generate_rtgroups(filename, kthreads, nr_cpus):
         else:
             mask = ",".join([hex(a) for a in \
                      procfs.hexbitmask(kt.affinity, nr_cpus)])
-        f.write("%s:%c:%d:%s:\[%s\]$\n" % (name, \
+        f.write(r"%s:%c:%d:%s:\[%s\]$" % (name, \
                            tuna_sched.sched_str(kt.policy)[6].lower(), \
-                            kt.rtprio, mask, regex))
+                            kt.rtprio, mask, regex) + "\n")
     f.close()