mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-19 00:17:51 +02:00
move try/except inside for loop
This commit is contained in:
@ -120,10 +120,9 @@ def parse(
|
|||||||
"""
|
"""
|
||||||
jc.utils.compatibility(__name__, info.compatible, quiet)
|
jc.utils.compatibility(__name__, info.compatible, quiet)
|
||||||
jc.utils.streaming_input_type_check(data)
|
jc.utils.streaming_input_type_check(data)
|
||||||
line = ''
|
|
||||||
|
|
||||||
try:
|
|
||||||
for line in data:
|
for line in data:
|
||||||
|
try:
|
||||||
output_line: Dict = {}
|
output_line: Dict = {}
|
||||||
jc.utils.streaming_line_input_type_check(line)
|
jc.utils.streaming_line_input_type_check(line)
|
||||||
|
|
||||||
|
@ -189,10 +189,9 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
|
|||||||
headers = ''
|
headers = ''
|
||||||
cpu_list = []
|
cpu_list = []
|
||||||
device_list = []
|
device_list = []
|
||||||
line = ''
|
|
||||||
|
|
||||||
try:
|
|
||||||
for line in data:
|
for line in data:
|
||||||
|
try:
|
||||||
jc.utils.streaming_line_input_type_check(line)
|
jc.utils.streaming_line_input_type_check(line)
|
||||||
output_line = {}
|
output_line = {}
|
||||||
|
|
||||||
|
@ -149,10 +149,9 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
|
|||||||
jc.utils.streaming_input_type_check(data)
|
jc.utils.streaming_input_type_check(data)
|
||||||
|
|
||||||
parent = ''
|
parent = ''
|
||||||
line = ''
|
|
||||||
|
|
||||||
try:
|
|
||||||
for line in data:
|
for line in data:
|
||||||
|
try:
|
||||||
jc.utils.streaming_line_input_type_check(line)
|
jc.utils.streaming_line_input_type_check(line)
|
||||||
|
|
||||||
# skip line if it starts with 'total 1234'
|
# skip line if it starts with 'total 1234'
|
||||||
|
@ -491,14 +491,13 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
|
|||||||
|
|
||||||
Iterator object
|
Iterator object
|
||||||
"""
|
"""
|
||||||
s = _state()
|
|
||||||
line = ''
|
|
||||||
|
|
||||||
jc.utils.compatibility(__name__, info.compatible, quiet)
|
jc.utils.compatibility(__name__, info.compatible, quiet)
|
||||||
jc.utils.streaming_input_type_check(data)
|
jc.utils.streaming_input_type_check(data)
|
||||||
|
|
||||||
try:
|
s = _state()
|
||||||
|
|
||||||
for line in data:
|
for line in data:
|
||||||
|
try:
|
||||||
output_line = {}
|
output_line = {}
|
||||||
jc.utils.streaming_line_input_type_check(line)
|
jc.utils.streaming_line_input_type_check(line)
|
||||||
|
|
||||||
|
@ -173,7 +173,6 @@ def parse(
|
|||||||
summary: Dict = {}
|
summary: Dict = {}
|
||||||
process: str = ''
|
process: str = ''
|
||||||
last_process: str = ''
|
last_process: str = ''
|
||||||
line: str = ''
|
|
||||||
|
|
||||||
update_type = {
|
update_type = {
|
||||||
'<': 'file sent',
|
'<': 'file sent',
|
||||||
@ -271,8 +270,8 @@ def parse(
|
|||||||
stat2_line_log_v_re = re.compile(r'(?P<date>\d\d\d\d/\d\d/\d\d)\s+(?P<time>\d\d:\d\d:\d\d)\s+\[(?P<process>\d+)\]\s+sent\s+(?P<sent>[\d,]+)\s+bytes\s+received\s+(?P<received>[\d,]+)\s+bytes\s+(?P<bytes_sec>[\d,.]+)\s+bytes/sec')
|
stat2_line_log_v_re = re.compile(r'(?P<date>\d\d\d\d/\d\d/\d\d)\s+(?P<time>\d\d:\d\d:\d\d)\s+\[(?P<process>\d+)\]\s+sent\s+(?P<sent>[\d,]+)\s+bytes\s+received\s+(?P<received>[\d,]+)\s+bytes\s+(?P<bytes_sec>[\d,.]+)\s+bytes/sec')
|
||||||
stat3_line_log_v_re = re.compile(r'(?P<date>\d\d\d\d/\d\d/\d\d)\s+(?P<time>\d\d:\d\d:\d\d)\s+\[(?P<process>\d+)]\s+total\s+size\s+is\s+(?P<total_size>[\d,]+)\s+speedup\s+is\s+(?P<speedup>[\d,.]+)')
|
stat3_line_log_v_re = re.compile(r'(?P<date>\d\d\d\d/\d\d/\d\d)\s+(?P<time>\d\d:\d\d:\d\d)\s+\[(?P<process>\d+)]\s+total\s+size\s+is\s+(?P<total_size>[\d,]+)\s+speedup\s+is\s+(?P<speedup>[\d,.]+)')
|
||||||
|
|
||||||
try:
|
|
||||||
for line in data:
|
for line in data:
|
||||||
|
try:
|
||||||
jc.utils.streaming_line_input_type_check(line)
|
jc.utils.streaming_line_input_type_check(line)
|
||||||
output_line: Dict = {}
|
output_line: Dict = {}
|
||||||
|
|
||||||
@ -452,6 +451,14 @@ def parse(
|
|||||||
summary['speedup'] = stat3_line_log_v.group('speedup')
|
summary['speedup'] = stat3_line_log_v.group('speedup')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
if not ignore_exceptions:
|
||||||
|
e.args = (str(e) + ignore_exceptions_msg,)
|
||||||
|
raise e
|
||||||
|
|
||||||
|
yield e, line
|
||||||
|
|
||||||
|
try:
|
||||||
if summary:
|
if summary:
|
||||||
yield summary if raw else _process(summary)
|
yield summary if raw else _process(summary)
|
||||||
|
|
||||||
|
@ -157,11 +157,10 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
|
|||||||
jc.utils.streaming_input_type_check(data)
|
jc.utils.streaming_input_type_check(data)
|
||||||
|
|
||||||
output_line = {}
|
output_line = {}
|
||||||
line = ''
|
|
||||||
os_type = ''
|
os_type = ''
|
||||||
|
|
||||||
try:
|
|
||||||
for line in data:
|
for line in data:
|
||||||
|
try:
|
||||||
jc.utils.streaming_line_input_type_check(line)
|
jc.utils.streaming_line_input_type_check(line)
|
||||||
line = line.rstrip()
|
line = line.rstrip()
|
||||||
|
|
||||||
@ -287,6 +286,14 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
|
|||||||
yield output_line if raw else _process(output_line)
|
yield output_line if raw else _process(output_line)
|
||||||
output_line = {}
|
output_line = {}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
if not ignore_exceptions:
|
||||||
|
e.args = (str(e) + ignore_exceptions_msg,)
|
||||||
|
raise e
|
||||||
|
|
||||||
|
yield e, line
|
||||||
|
|
||||||
|
try:
|
||||||
# gather final item
|
# gather final item
|
||||||
if output_line:
|
if output_line:
|
||||||
yield output_line if raw else _process(output_line)
|
yield output_line if raw else _process(output_line)
|
||||||
|
Reference in New Issue
Block a user