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-11 17:52:03 -07:00
parent 4d88595404
commit 1b57ec92f0
21 changed files with 150 additions and 66 deletions

View File

@ -8,7 +8,15 @@ jc changelog
- Update crontab_u parser to fix error on parsing empty data
- Update df parser to fix error on parsing empty data
- Update free parser to fix error on parsing empty data
- Update lsblk parser to fix error on parsing empty data
- Update lsmod parser to fix error on parsing empty data
- Update mount parser to fix error on parsing empty data
- Update netstat parser to fix error on parsing empty data
- Update ntpq parser to fix error on parsing empty data
- Update ps parser to fix error on parsing empty data
- Update route parser to fix error on parsing empty data
- Add tests to all parsers for no data condition
- Update ss parser to fix integer fields
20200610 v1.11.4
- Update ls parser to fix error on parsing an empty directory

View File

@ -56,7 +56,7 @@ import jc.utils
class info():
version = '1.3'
version = '1.4'
description = 'mount command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -162,6 +162,7 @@ def parse(data, raw=False, quiet=False):
# Clear any blank lines
cleandata = list(filter(None, linedata))
raw_output = []
if cleandata:
# check for OSX output

View File

@ -247,7 +247,7 @@ Examples:
class info():
version = '1.6'
version = '1.7'
description = 'netstat command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -435,6 +435,7 @@ def parse(data, raw=False, quiet=False):
cleandata = list(filter(None, cleandata))
raw_output = []
if cleandata:
# check for FreeBSD/OSX vs Linux
# is this from FreeBSD/OSX?
if cleandata[0] == 'Active Internet connections' \

View File

@ -183,7 +183,7 @@ import jc.parsers.universal
class info():
version = '1.1'
version = '1.2'
description = 'ntpq -p command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -268,9 +268,10 @@ def parse(data, raw=False, quiet=False):
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()
raw_output = []
cleandata = data.splitlines()
if list(filter(None, cleandata)):
cleandata[0] = 's ' + cleandata[0]
cleandata[0] = cleandata[0].lower()

View File

@ -32,7 +32,7 @@ import jc.parsers.universal
class info():
version = '1.1'
version = '1.2'
description = 'pip list command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -93,6 +93,7 @@ def parse(data, raw=False, quiet=False):
# Clear any blank lines
cleandata = list(filter(None, linedata))
if cleandata:
# detect legacy output type
if ' (' in cleandata[0]:
for row in cleandata:

View File

@ -177,7 +177,7 @@ import jc.parsers.universal
class info():
version = '1.1'
version = '1.2'
description = 'ps command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -282,6 +282,9 @@ def parse(data, raw=False, quiet=False):
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()
raw_output = []
if list(filter(None, cleandata)):
cleandata[0] = cleandata[0].lower()
raw_output = jc.parsers.universal.simple_table_parse(cleandata)

View File

@ -84,7 +84,7 @@ import jc.parsers.universal
class info():
version = '1.1'
version = '1.2'
description = 'route command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -182,6 +182,9 @@ def parse(data, raw=False, quiet=False):
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()[1:]
raw_output = []
if list(filter(None, cleandata)):
cleandata[0] = cleandata[0].lower()
raw_output = jc.parsers.universal.simple_table_parse(cleandata)

View File

@ -251,7 +251,7 @@ import jc.utils
class info():
version = '1.0'
version = '1.1'
description = 'ss command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -35,6 +35,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/lsof-sudo.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_lsof_sudo_json = json.loads(f.read())
def test_lsof_nodata(self):
"""
Test 'lsof' with no data
"""
self.assertEqual(jc.parsers.lsof.parse('', quiet=True), [])
def test_lsof_centos_7_7(self):
"""
Test 'lsof' on Centos 7.7

View File

@ -35,6 +35,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/mount2.json'), 'r', encoding='utf-8') as f:
self.osx_10_14_6_mount2_json = json.loads(f.read())
def test_mount_nodata(self):
"""
Test 'mount' with no data
"""
self.assertEqual(jc.parsers.mount.parse('', quiet=True), [])
def test_mount_centos_7_7(self):
"""
Test 'mount' on Centos 7.7

View File

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

View File

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

View File

@ -29,6 +29,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/passwd.json'), 'r', encoding='utf-8') as f:
self.osx_10_14_6_passwd_json = json.loads(f.read())
def test_passwd_nodata(self):
"""
Test 'cat /etc/passwd' with no data
"""
self.assertEqual(jc.parsers.passwd.parse('', quiet=True), [])
def test_passwd_centos_7_7(self):
"""
Test 'cat /etc/passwd' on Centos 7.7

View File

@ -41,6 +41,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/pip-list.json'), 'r', encoding='utf-8') as f:
self.osx_10_14_6_pip_list_json = json.loads(f.read())
def test_pip_list_nodata(self):
"""
Test 'pip_list' with no data
"""
self.assertEqual(jc.parsers.pip_list.parse('', quiet=True), [])
def test_pip_list_centos_7_7(self):
"""
Test 'pip_list' on Centos 7.7

View File

@ -35,6 +35,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/pip-show.json'), 'r', encoding='utf-8') as f:
self.osx_10_14_6_pip_show_json = json.loads(f.read())
def test_pip_show_nodata(self):
"""
Test 'pip show' with no data
"""
self.assertEqual(jc.parsers.pip_show.parse('', quiet=True), [])
def test_pip_show_centos_7_7(self):
"""
Test 'pip show' on Centos 7.7

View File

@ -59,6 +59,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ps-axu.json'), 'r', encoding='utf-8') as f:
self.osx_10_14_6_ps_axu_json = json.loads(f.read())
def test_ps_nodata(self):
"""
Test 'ps' with no data
"""
self.assertEqual(jc.parsers.ps.parse('', quiet=True), [])
def test_ps_ef_centos_7_7(self):
"""
Test 'ps -ef' on Centos 7.7

View File

@ -41,6 +41,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/nixos/route-ee.json'), 'r', encoding='utf-8') as f:
self.nixos_route_ee_json = json.loads(f.read())
def test_route_nodata(self):
"""
Test 'route' with no data
"""
self.assertEqual(jc.parsers.route.parse('', quiet=True), [])
def test_route_centos_7_7(self):
"""
Test 'route' on Centos 7.7

View File

@ -23,6 +23,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/shadow.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_shadow_json = json.loads(f.read())
def test_shadow_nodata(self):
"""
Test 'cat /etc/shadow' with no data
"""
self.assertEqual(jc.parsers.shadow.parse('', quiet=True), [])
def test_shadow_centos_7_7(self):
"""
Test 'cat /etc/shadow' on Centos 7.7

View File

@ -23,6 +23,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ss-sudo-a.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_ss_sudo_a_json = json.loads(f.read())
def test_ss_nodata(self):
"""
Test 'ss' with no data
"""
self.assertEqual(jc.parsers.ss.parse('', quiet=True), [])
def test_ss_sudo_a_centos_7_7(self):
"""
Test 'sudo ss -a' on Centos 7.7