1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-13 01:20:24 +02:00

move if statements and generalize the history detail detection

This commit is contained in:
Kelly Brazil
2021-03-17 12:49:48 -07:00
parent ad39fc6029
commit 8d88b91fcf

View File

@ -121,14 +121,6 @@ def parse(data, raw=False, quiet=False):
detail_key = '' detail_key = ''
continue continue
# history lines are a special case of detail lines
# set the history detail key
if line.startswith(' History ('):
continue
# detail_key = line.strip().lower().replace('-', '_').replace(' ', '_').replace('(', '').replace(')', '')[:-1]
# device_obj[detail_key] = {}
# continue
# history detail lines # history detail lines
# if detail_key.startswith('history_'): # if detail_key.startswith('history_'):
if line.startswith(' ') and ':' not in line: if line.startswith(' ') and ':' not in line:
@ -148,12 +140,19 @@ def parse(data, raw=False, quiet=False):
detail_obj[key] = val detail_obj[key] = val
continue continue
# history lines are a special case of detail lines
# set the history detail key
if line.startswith(' ') and ':' in line and line.strip().split(':', maxsplit=1)[1] == '':
continue
# detail_key = line.strip().lower().replace('-', '_').replace(' ', '_').replace('(', '').replace(')', '')[:-1]
# device_obj[detail_key] = {}
# continue
# top level lines # top level lines
if line.startswith(' ') and ':' in line: if line.startswith(' ') and ':' in line:
key = line.split(':', maxsplit=1)[0].strip().lower().replace('-', '_').replace(' ', '_') key = line.split(':', maxsplit=1)[0].strip().lower().replace('-', '_').replace(' ', '_')
val = line.split(':', maxsplit=1)[1].strip() val = line.split(':', maxsplit=1)[1].strip()
device_obj[key] = val device_obj[key] = val
continue continue
# set the detail key # set the detail key