Пример #1
0
def parse(lines, highlight_words, filters, objref_dict):
    """
    Given filters returns indeces of wanted lines from log

    Args:
        lines: array of log lines
        highlight_words: array of words that need to be bolded
        filters: dictionary of which filters to apply
        objref_dict: a dictionary where the keys are possible filters
        and the values are the words to be highlighted
    Returns:
        matched_lines: ordered array of indeces of lines to display
        highlight_words: updated highlight_words
    """
    matched_lines = []

    if not filters["pod"] and objref_dict:
        highlight_words = []

    # If the filter is on, look for it in the objref_dict
    for k in filters:
        if k != "pod" and filters[k] and k in objref_dict:
            highlight_words.append(objref_dict[k])

    words_re = regex.combine_wordsRE(highlight_words)

    for n, line in enumerate(lines):
        if words_re.search(line):
            matched_lines.append(n)

    return matched_lines, highlight_words
Пример #2
0
def parse(lines, hilight_words, filters, objref_dict):
    """
    Given filters returns indeces of wanted lines from log

    Args:
        lines: array of log lines
        hilight_words: array of words that need to be bolded
        filters: dictionary of which filters to apply
        objref_dict: a dictionary where the keys are possible filters
        and the values are the words to be hilighted
    Returns:
        matched_lines: ordered array of indeces of lines to display
        hilight_words: updated hilight_words
    """
    matched_lines = []

    if not filters["pod"] and objref_dict:
        hilight_words = []

    # If the filter is on, look for it in the objref_dict
    for k in filters:
        if k != "pod" and filters[k] and k in objref_dict:
            hilight_words.append(objref_dict[k])

    words_re = regex.combine_wordsRE(hilight_words)

    for n, line in enumerate(lines):
        if words_re.search(line):
            matched_lines.append(n)

    return matched_lines, hilight_words
Пример #3
0
 def test_combine_wordsRE(self):
     for text, matches in [
         ('pod123 failed', True),
         ('Volume mounted to pod', True),
         ('UID: "a123"', True),
     ]:
         self.assertEqual(bool(regex.combine_wordsRE(["pod123", "volume", "a123"])), matches,
             'combine_words(%r) should be %r' % (text, matches))
Пример #4
0
 def test_combine_wordsRE(self):
     for text, matches in [
         ('pod123 failed', True),
         ('Volume mounted to pod', True),
         ('UID: "a123"', True),
     ]:
         self.assertEqual(bool(regex.combine_wordsRE(["pod123", "volume", "a123"])), matches,
             'combine_words(%r) should be %r' % (text, matches))
Пример #5
0
def highlight(line, highlight_words):
    # Join all the words that need to be bolded into one regex
    words_re = regex.combine_wordsRE(highlight_words)
    line = words_re.sub(r'<span class="keyword">\1</span>', line)
    return '<span class="highlight">%s</span>' % line
Пример #6
0
def hilight(line, hilight_words):
    # Join all the words that need to be bolded into one regex
    words_re = regex.combine_wordsRE(hilight_words)
    line = words_re.sub(r'<span class="keyword">\1</span>', line)
    return '<span class="hilight">%s</span>' % line