Tomb/extras/pytomb/tomblib/parser.py
Jaromil 3eb93acc18 Directory reorganization
This commit re-organizes all the source distribution contents to
present users with the simple script, while moving the rest in extras.
Also autoconf/automake scripts were removed, back to minimalism.

The rationale of this change is that Tomb really only consists of a
script and users with no extra needs should just be presented with
it with no need for anything else. Any other thing on top of the Tomb
script is an extra and can be even distributed separately or integrated
in distributions.
2013-05-18 17:29:37 +02:00

35 lines
1.2 KiB
Python

'''
Utilities to analyze tomb output
'''
import re
#found: [m] followed by some ID (usually "found") inside square brackets, then
#something else, then a space, then the content
_found_regex = re.compile(r'^\[m\]\[([^]]+)\] +(([^:]+)://(.+))$')
#generic: programname, then some identifiers in square (or round) brackets,
#then maybe something else, then a space, then the context
_generic_regex = re.compile(r'^[a-z-]+ [[(]([^]]+)[\])] +(.+)$')
types = {'E':'error', 'W':'warning', 'D':'debug', '*':'success'}
def parse_line(line):
'''Analyze a single line.
Return None if no standard format is detected, a dict otherwise.
The fields 'type' and 'content' are always in the dict; 'content' may be
empty
'type' can be 'error', 'progress'
'''
match = _found_regex.match(line)
if match:
return { 'type': types.get(match.group(1)) or match.group(1),
'content': match.group(2), 'scheme': match.group(3),
'path': match.group(4) }
match = _generic_regex.search(line)
if match:
return { 'type': types.get(match.group(1)) or match.group(1),
'content': match.group(2) }
return None