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

fix for no data

This commit is contained in:
Kelly Brazil
2020-06-10 17:10:53 -07:00
parent 9179b4175c
commit 35d733b44f
5 changed files with 69 additions and 59 deletions

View File

@ -2,6 +2,8 @@ jc changelog
20200610 v1.11.5
- Update airport_s parser to fix error on parsing empty data
- Update arp parser to fix error on parsing empty data
- Update blkid parser to fix error on parsing empty data
- Add tests to all parsers for no data condition
20200610 v1.11.4

View File

@ -99,7 +99,7 @@ import jc.parsers.universal
class info():
version = '1.4'
version = '1.5'
description = 'arp command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -171,7 +171,10 @@ def parse(data, raw=False, quiet=False):
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()
raw_output = []
cleandata = list(filter(None, data.splitlines()))
if cleandata:
# remove final Entries row if -v was used
if cleandata[-1].startswith('Entries:'):
@ -179,7 +182,6 @@ def parse(data, raw=False, quiet=False):
# detect if freebsd/osx style was used
if cleandata[0][-1] == ']':
raw_output = []
for line in cleandata:
splitline = line.split()
output_line = {
@ -214,14 +216,8 @@ def parse(data, raw=False, quiet=False):
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if raw:
return raw_output
else:
return process(raw_output)
# otherwise, try bsd style
else:
raw_output = []
for line in cleandata:
line = line.split()
output_line = {

View File

@ -79,7 +79,7 @@ import jc.utils
class info():
version = '1.0'
version = '1.1'
description = 'blkid command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -176,7 +176,7 @@ def parse(data, raw=False, quiet=False):
raw_output = []
if data:
if len(data) > 1:
# if the first field is a device, use normal parsing:
if data.split(maxsplit=1)[0][-1] == ':':
linedata = data.splitlines()

View File

@ -71,6 +71,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/arp-a.json'), 'r', encoding='utf-8') as f:
self.freebsd12_arp_a_json = json.loads(f.read())
def test_arp_nodata(self):
"""
Test 'arp' with no data
"""
self.assertEqual(jc.parsers.arp.parse('', quiet=True), [])
def test_arp_centos_7_7(self):
"""
Test 'arp' on Centos 7.7

View File

@ -71,6 +71,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/blkid-ip-udev-multi.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_blkid_ip_udev_multi_json = json.loads(f.read())
def test_blkid_nodata(self):
"""
Test 'blkid' with no data
"""
self.assertEqual(jc.parsers.blkid.parse('', quiet=True), [])
def test_blkid_centos_7_7(self):
"""
Test 'blkid' on Centos 7.7