1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-11 01:10:37 +02:00

use stream_error function for exceptions. raise on non -l ls output

This commit is contained in:
Kelly Brazil
2021-09-13 18:31:52 -07:00
parent 55bb71e9d4
commit f50dfaef45

View File

@ -56,11 +56,12 @@ Examples:
""" """
import re import re
import jc.utils import jc.utils
from jc.exceptions import ParseError
class info(): class info():
"""Provides parser metadata (version, author, etc.)""" """Provides parser metadata (version, author, etc.)"""
version = '1.0' version = '0.5'
description = '`ls` command streaming parser' description = '`ls` command streaming parser'
author = 'Kelly Brazil' author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com' author_email = 'kellyjonbrazil@gmail.com'
@ -136,6 +137,9 @@ def parse(data, raw=False, quiet=False):
parent = line.strip()[:-1] parent = line.strip()[:-1]
continue continue
if not re.match(r'[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', line):
raise ParseError(f'Unable to parse line: {line.strip()}')
parsed_line = line.strip().split(maxsplit=8) parsed_line = line.strip().split(maxsplit=8)
output_line = {} output_line = {}
@ -171,15 +175,4 @@ def parse(data, raw=False, quiet=False):
yield _process(output_line) yield _process(output_line)
except Exception as e: except Exception as e:
if not quiet: yield jc.utils.stream_error(e, quiet, line)
e.args = (str(e) + '... Use the quiet option (-q) to ignore errors.',)
raise e
else:
yield {
'_meta':
{
'success': False,
'error': 'error parsing line',
'line': line.strip()
}
}