[PATCH][kteam-tools] ktl: Don't treat all strings matching "#[0-9]+" as a bug numbers

Seth Forshee seth.forshee at canonical.com
Tue Aug 9 15:26:10 UTC 2016

The bug number regular expression matching correctly identifies
lines containing launchpad bug numbers, but once such a line is
identified it treats any string matching "#[0-9]+" as a bug
number. For example, in this changelog entry #1 is identified as
a bug number:

  * [LTCTest][Opal][OP820] Machine crashed with Oops: Kernel access of bad area,
    sig: 11 [#1] while executing Froze PE Error injection (LP: #1603449)

Rather than matching the "LP: #NNNNNN" string and the bug number
separately, they can be combined into one regex which matches
against the full string but returns only the bug number portion
of the string. Since re.findall will return an empty list if
there are no matches, all that is needed is to append the list
returned by findall with this regex to the bug list for each line
of the changelog.

Signed-off-by: Seth Forshee <seth.forshee at canonical.com>
 ktl/debian.py | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/ktl/debian.py b/ktl/debian.py
index dd2703a..76435aa 100644
--- a/ktl/debian.py
+++ b/ktl/debian.py
@@ -30,8 +30,7 @@ class Debian:
     package_rc = compile("^(linux[-\S])*.*$")
     ver_rc     = compile("^linux[-\S]* \(([0-9]+\.[0-9]+\.[0-9]+[-\.][0-9]+\.[0-9]+[~a-z0-9]*)\).*$")
-    bug_line_rc = compile("LP:\s#[0-9]+")
-    bug_rc = compile("#([0-9]+)")
+    bug_rc = compile("LP:\s#([0-9]+)")
     # debian_directories
@@ -176,11 +175,8 @@ class Debian:
                 bugs = []
                 # find bug numbers and append them to the list
-                bug_line_matches = cls.bug_line_rc.search(line)
-                if bug_line_matches:
-                    bug_matches = findall(cls.bug_rc,line)
-                    if bug_matches:
-                        bugs.extend( bug_matches )
+                bug_matches = findall(cls.bug_rc,line)
+                bugs.extend(bug_matches)

More information about the kernel-team mailing list