diff mbox series

[6/7] rteval: kcompile: Fix regular expression to match kernel prefix

Message ID 20220603161224.10947-6-jkacur@redhat.com
State New
Headers show
Series [1/7] rteval: rteval-cmd: Use "with" with open | expand

Commit Message

John Kacur June 3, 2022, 4:12 p.m. UTC
If the user specifies a kernel to compile as a load other than the
default kernel, the kernel prefix is obtained with a regular expression.

Currently the regular expression does not accomodate two digit numbers
in the kernel version.
Fix that regular expression to accomodate different kernel versions,
with room to grow for the future.

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 rteval/modules/loads/kcompile.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Valentin Schneider June 6, 2022, 10:59 a.m. UTC | #1
On 03/06/22 12:12, John Kacur wrote:
> @@ -169,7 +169,7 @@ class Kcompile(CommandLineLoad):
>              if not os.path.exists(tarfile):
>                  raise rtevalRuntimeError(self, " tarfile %s does not exist!" % tarfile)
>              self.source = tarfile
> -            kernel_prefix = re.search(r"linux-\d\.\d", self.source).group(0)
> +            kernel_prefix = re.search(r"linux-\d{1,2}\.\d{1,3}", self.source).group(0)

Sorry about that one!
That looks OK to me, though why not go for "linux-\d+\.\d+" ?
diff mbox series

Patch

diff --git a/rteval/modules/loads/kcompile.py b/rteval/modules/loads/kcompile.py
index 2701a0dcba91..3d9b882d8810 100644
--- a/rteval/modules/loads/kcompile.py
+++ b/rteval/modules/loads/kcompile.py
@@ -169,7 +169,7 @@  class Kcompile(CommandLineLoad):
             if not os.path.exists(tarfile):
                 raise rtevalRuntimeError(self, " tarfile %s does not exist!" % tarfile)
             self.source = tarfile
-            kernel_prefix = re.search(r"linux-\d\.\d", self.source).group(0)
+            kernel_prefix = re.search(r"linux-\d{1,2}\.\d{1,3}", self.source).group(0)
         else:
             tarfiles = glob.glob(os.path.join(self.srcdir, "%s*" % DEFAULT_KERNEL_PREFIX))
             if tarfiles:
@@ -177,6 +177,7 @@  class Kcompile(CommandLineLoad):
             else:
                 raise rtevalRuntimeError(self, " no kernel tarballs found in %s" % self.srcdir)
             kernel_prefix = DEFAULT_KERNEL_PREFIX
+        self._log(Log.DEBUG, f"kernel_prefix = {kernel_prefix}")
 
         # check for existing directory
         kdir = None