commit:     0fbd4c06d15a194eb41e56e69583b31ccd847e29
Author:     Magnus Granberg <zorry <AT> gentoo <DOT> org>
AuthorDate: Sat Apr 17 17:27:51 2021 +0000
Commit:     Magnus Granberg <zorry <AT> gentoo <DOT> org>
CommitDate: Sat Apr 17 17:27:51 2021 +0000
URL:        
https://gitweb.gentoo.org/proj/tinderbox-cluster.git/commit/?id=0fbd4c06

Add support for search type in search pattern

Signed-off-by: Magnus Granberg <zorry <AT> gentoo.org>

 buildbot_gentoo_ci/db/model.py    |  2 +-
 buildbot_gentoo_ci/db/projects.py |  6 +--
 buildbot_gentoo_ci/steps/logs.py  | 94 ++++++++++++++++++---------------------
 3 files changed, 46 insertions(+), 56 deletions(-)

diff --git a/buildbot_gentoo_ci/db/model.py b/buildbot_gentoo_ci/db/model.py
index ede5cb7..ca9932a 100644
--- a/buildbot_gentoo_ci/db/model.py
+++ b/buildbot_gentoo_ci/db/model.py
@@ -225,11 +225,11 @@ class Model(base.DBConnectorComponent):
                   sa.ForeignKey('projects.uuid', ondelete='CASCADE'),
                   nullable=False),
         sa.Column('search', sa.String(50), nullable=False),
-        sa.Column('search_end', sa.String(50), nullable=True),
         sa.Column('start', sa.Integer, default=0),
         sa.Column('end', sa.Integer, default=0),
         sa.Column('status', sa.Enum('info', 'warning', 'ignore', 'error'), 
default='info'),
         sa.Column('type', sa.Enum('info', 'qa', 'compile', 'configure', 
'install', 'postinst', 'prepare', 'setup', 'test', 'unpack', 'ignore'), 
default='info'),
+        sa.Column('search_type', sa.Enum('in', 'startswith', 'endswith', 
'search'), default='in'),
     )
 
     keywords = sautils.Table(

diff --git a/buildbot_gentoo_ci/db/projects.py 
b/buildbot_gentoo_ci/db/projects.py
index 2393011..176be92 100644
--- a/buildbot_gentoo_ci/db/projects.py
+++ b/buildbot_gentoo_ci/db/projects.py
@@ -266,15 +266,11 @@ class 
ProjectsConnectorComponent(base.DBConnectorComponent):
             )
 
     def _row2dict_projects_pattern(self, conn, row):
-        if row.search_end == '':
-            search_end = None
-        else:
-            search_end = row.search_end
         return dict(
             id=row.id,
             project_uuid=row.project_uuid,
             search=row.search,
-            search_end=search_end,
+            search_type=row.search_type,
             start=row.start,
             end=row.end,
             status=row.status,

diff --git a/buildbot_gentoo_ci/steps/logs.py b/buildbot_gentoo_ci/steps/logs.py
index 4c3bf01..178d71e 100644
--- a/buildbot_gentoo_ci/steps/logs.py
+++ b/buildbot_gentoo_ci/steps/logs.py
@@ -75,13 +75,13 @@ class ParserBuildLog(BuildStep):
                     match = False
             if match:
                 self.log_search_pattern_list.append(project_pattern)
-        print(self.log_search_pattern_list)
 
     def search_buildlog(self, tmp_index):
         # get text line to search
         text_line = self.logfile_text_dict[tmp_index]
         # loop true the pattern list for match
         for search_pattern in self.log_search_pattern_list:
+            search_hit = False
             # we add all line that start with ' * ' as info
             # we add all line that start with '>>>' but not '>>> /' as info
             if text_line.startswith(' * ') or (text_line.startswith('>>>') and 
not text_line.startswith('>>> /')):
@@ -89,63 +89,57 @@ class ParserBuildLog(BuildStep):
                 self.summery_dict[tmp_index]['text'] = text_line
                 self.summery_dict[tmp_index]['type'] = 'info'
                 self.summery_dict[tmp_index]['status'] = 'info'
-            if re.search(search_pattern['search'], text_line):
+                self.summery_dict[tmp_index]['search_pattern_id'] = 0
+            if search_pattern['search_type'] == 'in':
+                if search_pattern['search'] in text_line:
+                    search_hit = True
+            if search_pattern['search_type'] == 'startswith':
+                if text_line.startswith(search_pattern['search']):
+                    search_hit = True
+            if search_pattern['search_type'] == 'endswith':
+                if text_line.endswith(search_pattern['search']):
+                    search_hit = True
+            if search_pattern['search_type'] == 'search':
+                if search_pattern['search'] in text_line:
+                    search_hit = True
+            if search_hit:
+                print(text_line)
+                print(search_pattern['search'])
                 self.summery_dict[tmp_index] = {}
                 self.summery_dict[tmp_index]['text'] = text_line
                 self.summery_dict[tmp_index]['type'] = search_pattern['type']
                 self.summery_dict[tmp_index]['status'] = 
search_pattern['status']
+                self.summery_dict[tmp_index]['search_pattern_id'] = 
search_pattern['id']
                 # add upper text lines if requested
                 # max 10
-                if search_pattern['start'] != 0:
-                    i = tmp_index
-                    i_start = i - search_pattern['start']
-                    match = True
-                    while match:
-                        i = i - 1
-                        if i < 0 or i < i_start:
-                            match = False
-                        else:
-                            self.summery_dict[i] = {}
-                            self.summery_dict[i]['text'] = 
self.logfile_text_dict[i]
-                            self.summery_dict[i]['type'] = 
search_pattern['type']
-                            self.summery_dict[i]['status'] = 'info'
+            if search_pattern['start'] != 0 and search_hit:
+                i = tmp_index
+                i_start = i - search_pattern['start']
+                match = True
+                while match:
+                    i = i - 1
+                    if i < 0 or i < i_start:
+                        match = False
+                    else:
+                        self.summery_dict[i] = {}
+                        self.summery_dict[i]['text'] = 
self.logfile_text_dict[i]
+                        self.summery_dict[i]['type'] = search_pattern['type']
+                        self.summery_dict[i]['status'] = 'info'
                 # add lower text lines if requested
                 # max 10
-                if search_pattern['end'] != 0:
-                    i = tmp_index
-                    i_end = i + search_pattern['end']
-                    match = True
-                    while match:
-                        i = i + 1
-                        if i > self.max_text_lines or i > i_end:
-                            match = False
-                        else:
-                            self.summery_dict[i] = {}
-                            self.summery_dict[i]['text'] = 
self.logfile_text_dict[i]
-                            self.summery_dict[i]['type'] = 
search_pattern['type']
-                            self.summery_dict[i]['status'] = 'info'
-                # add text lines if requested that we need to search for the 
end
-                # max 10
-                if search_pattern['search_end'] is not None:
-                    i = tmp_index
-                    match = True
-                    while match:
-                        i = i + 1
-                        if i > self.max_text_lines:
-                            match = False
-                        if re.search(search_pattern['search_end'], 
self.logfile_text_dict[i]):
-                            if not i + 1 > self.max_text_lines or not 
re.search(search_pattern['search_end'], self.logfile_text_dict[i + 1]):
-                                self.summery_dict[i] = {}
-                                self.summery_dict[i]['text'] = 
self.logfile_text_dict[i]
-                                self.summery_dict[i]['type'] = 
search_pattern['type']
-                                self.summery_dict[i]['status'] = 'info'
-                            else:
-                                match = False
-                        else:
-                            self.summery_dict[i] = {}
-                            self.summery_dict[i]['text'] = 
self.logfile_text_dict[i]
-                            self.summery_dict[i]['type'] = 
search_pattern['type']
-                            self.summery_dict[i]['status'] = 'info'
+            if search_pattern['end'] != 0 and search_hit:
+                i = tmp_index
+                i_end = i + search_pattern['end']
+                match = True
+                while match:
+                    i = i + 1
+                    if i > self.max_text_lines or i > i_end:
+                        match = False
+                    else:
+                        self.summery_dict[i] = {}
+                        self.summery_dict[i]['text'] = 
self.logfile_text_dict[i]
+                        self.summery_dict[i]['type'] = search_pattern['type']
+                        self.summery_dict[i]['status'] = 'info'
 
     @defer.inlineCallbacks
     def run(self):

Reply via email to