"Fossies" - the Fresh Open Source Software Archive

Member "Tomb-2.7/extras/tomber/tomber/tools/parser.py" (11 Oct 2019, 1184 Bytes) of package /linux/privat/Tomb-2.7.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "parser.py" see the Fossies "Dox" file reference documentation.

    1 '''
    2 Utilities to analyze tomb output
    3 '''
    4 import re
    5 
    6 #found: [m] followed by some ID (usually "found") inside square brackets, then
    7 #something else, then a space, then the content
    8 _found_regex = re.compile(r'^\[m\]\[([^]]+)\] +(([^:]+)://(.+))$')
    9 #generic: programname, then some identifiers in square (or round) brackets,
   10 #then maybe something else, then a space, then the context
   11 _generic_regex = re.compile(r'^[a-z-]+ [[(]([^]]+)[\])] +(.+)$')
   12 types = {'E': 'error', 'W': 'warning', 'D': 'debug', '*': 'success'}
   13 
   14 
   15 def parse_line(line):
   16     '''Analyze a single line.
   17     Return None if no standard format is detected, a dict otherwise.
   18     The fields 'type' and 'content' are always in the dict; 'content' may be
   19     empty
   20     'type' can be 'error', 'progress'
   21     '''
   22 
   23     match = _found_regex.match(line)
   24     if match:
   25         return {'type': types.get(match.group(1)) or match.group(1),
   26                 'content': match.group(2), 'scheme': match.group(3),
   27                 'path': match.group(4)}
   28     match = _generic_regex.search(line)
   29     if match:
   30         return {'type': types.get(match.group(1)) or match.group(1),
   31                 'content': match.group(2)}
   32 
   33     return None