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

Merge pull request #68 from kellyjonbrazil/dev

Dev v1.11.5
This commit is contained in:
Kelly Brazil
2020-06-12 12:34:34 -07:00
committed by GitHub
79 changed files with 690 additions and 328 deletions

View File

@ -74,7 +74,7 @@ There are several ways to get `jc`. You can install via `pip`; other OS package
### Pip (macOS, linux, unix, Windows)
```
$ pip3 install --upgrade jc
$ pip3 install jc
```
### OS Package Repositories

View File

@ -1,5 +1,30 @@
jc changelog
20200612 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
- Update crontab parser to fix error on parsing empty data
- 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
- Update systemctl parser to fix error on parsing empty data
- Update systemctl_lj parser to fix error on parsing empty data
- Update systemctl_ls parser to fix error on parsing empty data
- Update systemctl_luf parser to fix error on parsing empty data
- Update uptime parser to fix error on parsing empty data
- Update w parser to fix error on parsing empty data
- Update xml 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

@ -21,7 +21,7 @@ import jc.appdirs as appdirs
class info():
version = '1.11.4'
version = '1.11.5'
description = 'jc cli output JSON conversion tool'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'

View File

@ -88,7 +88,7 @@ import jc.parsers.universal
class info():
version = '1.0'
version = '1.1'
description = 'airport -s command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -170,15 +170,17 @@ 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()))
# fix headers
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].replace('-', '_')
cleandata[0] = cleandata[0].replace('security (auth/unicast/group)', 'security')
if cleandata:
# fix headers
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].replace('-', '_')
cleandata[0] = cleandata[0].replace('security (auth/unicast/group)', 'security')
# parse the data
raw_output = jc.parsers.universal.sparse_table_parse(cleandata)
# parse the data
raw_output = jc.parsers.universal.sparse_table_parse(cleandata)
if raw:
return raw_output

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,69 +171,65 @@ 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()))
# remove final Entries row if -v was used
if cleandata[-1].startswith('Entries:'):
cleandata.pop(-1)
if cleandata:
# detect if freebsd/osx style was used
if cleandata[0][-1] == ']':
raw_output = []
for line in cleandata:
splitline = line.split()
output_line = {
'name': splitline[0],
'address': splitline[1].lstrip('(').rstrip(')'),
'hwtype': splitline[-1].lstrip('[').rstrip(']'),
'hwaddress': splitline[3],
'iface': splitline[5]
}
# remove final Entries row if -v was used
if cleandata[-1].startswith('Entries:'):
cleandata.pop(-1)
if 'permanent' in splitline:
output_line['permanent'] = True
# detect if freebsd/osx style was used
if cleandata[0][-1] == ']':
for line in cleandata:
splitline = line.split()
output_line = {
'name': splitline[0],
'address': splitline[1].lstrip('(').rstrip(')'),
'hwtype': splitline[-1].lstrip('[').rstrip(']'),
'hwaddress': splitline[3],
'iface': splitline[5]
}
if 'permanent' in splitline:
output_line['permanent'] = True
else:
output_line['permanent'] = False
if 'expires' in splitline:
output_line['expires'] = splitline[-3]
raw_output.append(output_line)
if raw:
return raw_output
else:
output_line['permanent'] = False
return process(raw_output)
if 'expires' in splitline:
output_line['expires'] = splitline[-3]
# detect if linux style was used
elif cleandata[0].startswith('Address'):
raw_output.append(output_line)
# fix header row to change Flags Mask to flags_mask
cleandata[0] = cleandata[0].replace('Flags Mask', 'flags_mask')
cleandata[0] = cleandata[0].lower()
if raw:
return raw_output
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
# otherwise, try bsd style
else:
return process(raw_output)
for line in cleandata:
line = line.split()
output_line = {
'name': line[0],
'address': line[1].lstrip('(').rstrip(')'),
'hwtype': line[4].lstrip('[').rstrip(']'),
'hwaddress': line[3],
'iface': line[6],
}
raw_output.append(output_line)
# detect if linux style was used
elif cleandata[0].startswith('Address'):
# fix header row to change Flags Mask to flags_mask
cleandata[0] = cleandata[0].replace('Flags Mask', 'flags_mask')
cleandata[0] = cleandata[0].lower()
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if raw:
return raw_output
else:
return process(raw_output)
# otherwise, try bsd style
if raw:
return raw_output
else:
raw_output = []
for line in cleandata:
line = line.split()
output_line = {
'name': line[0],
'address': line[1].lstrip('(').rstrip(')'),
'hwtype': line[4].lstrip('[').rstrip(']'),
'hwaddress': line[3],
'iface': line[6],
}
raw_output.append(output_line)
if raw:
return raw_output
else:
return process(raw_output)
return process(raw_output)

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 list(filter(None, data.splitlines())):
# if the first field is a device, use normal parsing:
if data.split(maxsplit=1)[0][-1] == ':':
linedata = data.splitlines()

View File

@ -132,7 +132,7 @@ import jc.parsers.universal
class info():
version = '1.2'
version = '1.3'
description = 'crontab command and file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -225,44 +225,45 @@ def parse(data, raw=False, quiet=False):
# Clear any blank lines
cleandata = list(filter(None, cleandata))
# Clear any commented lines
for i, line in reversed(list(enumerate(cleandata))):
if line.strip().startswith('#'):
cleandata.pop(i)
if cleandata:
# Clear any commented lines
for i, line in reversed(list(enumerate(cleandata))):
if line.strip().startswith('#'):
cleandata.pop(i)
# Pop any variable assignment lines
cron_var = []
for i, line in reversed(list(enumerate(cleandata))):
if '=' in line:
var_line = cleandata.pop(i)
var_name = var_line.split('=', maxsplit=1)[0].strip()
var_value = var_line.split('=', maxsplit=1)[1].strip()
cron_var.append({'name': var_name,
'value': var_value})
# Pop any variable assignment lines
cron_var = []
for i, line in reversed(list(enumerate(cleandata))):
if '=' in line:
var_line = cleandata.pop(i)
var_name = var_line.split('=', maxsplit=1)[0].strip()
var_value = var_line.split('=', maxsplit=1)[1].strip()
cron_var.append({'name': var_name,
'value': var_value})
raw_output['variables'] = cron_var
raw_output['variables'] = cron_var
# Pop any shortcut lines
shortcut_list = []
for i, line in reversed(list(enumerate(cleandata))):
if line.strip().startswith('@'):
shortcut_line = cleandata.pop(i)
occurrence = shortcut_line.split(maxsplit=1)[0].strip().lstrip('@')
cmd = shortcut_line.split(maxsplit=1)[1].strip()
shortcut_list.append({'occurrence': occurrence,
'command': cmd})
# Pop any shortcut lines
shortcut_list = []
for i, line in reversed(list(enumerate(cleandata))):
if line.strip().startswith('@'):
shortcut_line = cleandata.pop(i)
occurrence = shortcut_line.split(maxsplit=1)[0].strip().lstrip('@')
cmd = shortcut_line.split(maxsplit=1)[1].strip()
shortcut_list.append({'occurrence': occurrence,
'command': cmd})
# Add header row for parsing
cleandata[:0] = ['minute hour day_of_month month day_of_week command']
# Add header row for parsing
cleandata[:0] = ['minute hour day_of_month month day_of_week command']
if len(cleandata) > 1:
cron_list = jc.parsers.universal.simple_table_parse(cleandata)
if len(cleandata) > 1:
cron_list = jc.parsers.universal.simple_table_parse(cleandata)
raw_output['schedule'] = cron_list
raw_output['schedule'] = cron_list
# Add shortcut entries back in
for item in shortcut_list:
raw_output['schedule'].append(item)
# Add shortcut entries back in
for item in shortcut_list:
raw_output['schedule'].append(item)
if raw:
return raw_output

View File

@ -133,7 +133,7 @@ import jc.parsers.universal
class info():
version = '1.1'
version = '1.2'
description = 'crontab file parser with user support'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -226,46 +226,47 @@ def parse(data, raw=False, quiet=False):
# Clear any blank lines
cleandata = list(filter(None, cleandata))
# Clear any commented lines
for i, line in reversed(list(enumerate(cleandata))):
if line.strip().startswith('#'):
cleandata.pop(i)
if cleandata:
# Clear any commented lines
for i, line in reversed(list(enumerate(cleandata))):
if line.strip().startswith('#'):
cleandata.pop(i)
# Pop any variable assignment lines
cron_var = []
for i, line in reversed(list(enumerate(cleandata))):
if '=' in line:
var_line = cleandata.pop(i)
var_name = var_line.split('=', maxsplit=1)[0].strip()
var_value = var_line.split('=', maxsplit=1)[1].strip()
cron_var.append({'name': var_name,
'value': var_value})
# Pop any variable assignment lines
cron_var = []
for i, line in reversed(list(enumerate(cleandata))):
if '=' in line:
var_line = cleandata.pop(i)
var_name = var_line.split('=', maxsplit=1)[0].strip()
var_value = var_line.split('=', maxsplit=1)[1].strip()
cron_var.append({'name': var_name,
'value': var_value})
raw_output['variables'] = cron_var
raw_output['variables'] = cron_var
# Pop any shortcut lines
shortcut_list = []
for i, line in reversed(list(enumerate(cleandata))):
if line.strip().startswith('@'):
shortcut_line = cleandata.pop(i)
occurrence = shortcut_line.split(maxsplit=1)[0].strip().lstrip('@')
usr = shortcut_line.split(maxsplit=2)[1].strip()
cmd = shortcut_line.split(maxsplit=2)[2].strip()
shortcut_list.append({'occurrence': occurrence,
'user': usr,
'command': cmd})
# Pop any shortcut lines
shortcut_list = []
for i, line in reversed(list(enumerate(cleandata))):
if line.strip().startswith('@'):
shortcut_line = cleandata.pop(i)
occurrence = shortcut_line.split(maxsplit=1)[0].strip().lstrip('@')
usr = shortcut_line.split(maxsplit=2)[1].strip()
cmd = shortcut_line.split(maxsplit=2)[2].strip()
shortcut_list.append({'occurrence': occurrence,
'user': usr,
'command': cmd})
# Add header row for parsing
cleandata[:0] = ['minute hour day_of_month month day_of_week user command']
# Add header row for parsing
cleandata[:0] = ['minute hour day_of_month month day_of_week user command']
if len(cleandata) > 1:
cron_list = jc.parsers.universal.simple_table_parse(cleandata)
if len(cleandata) > 1:
cron_list = jc.parsers.universal.simple_table_parse(cleandata)
raw_output['schedule'] = cron_list
raw_output['schedule'] = cron_list
# Add shortcut entries back in
for item in shortcut_list:
raw_output['schedule'].append(item)
# Add shortcut entries back in
for item in shortcut_list:
raw_output['schedule'].append(item)
if raw:
return raw_output

View File

@ -73,7 +73,7 @@ import jc.parsers.universal
class info():
version = '1.3'
version = '1.4'
description = 'df command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -184,14 +184,16 @@ def parse(data, raw=False, quiet=False):
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()
raw_output = []
# fix headers
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].replace('-', '_')
cleandata[0] = cleandata[0].replace('mounted on', 'mounted_on')
if list(filter(None, cleandata)):
# fix headers
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].replace('-', '_')
cleandata[0] = cleandata[0].replace('mounted on', 'mounted_on')
# parse the data
raw_output = jc.parsers.universal.sparse_table_parse(cleandata)
# parse the data
raw_output = jc.parsers.universal.sparse_table_parse(cleandata)
if raw:
return raw_output

View File

@ -53,7 +53,7 @@ import jc.parsers.universal
class info():
version = '1.0'
version = '1.1'
description = 'free command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -122,14 +122,17 @@ def parse(data, raw=False, quiet=False):
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].replace('buff/cache', 'buff_cache')
cleandata[0] = 'type ' + cleandata[0]
raw_output = []
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if cleandata:
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].replace('buff/cache', 'buff_cache')
cleandata[0] = 'type ' + cleandata[0]
for entry in raw_output:
entry['type'] = entry['type'].rstrip(':')
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
for entry in raw_output:
entry['type'] = entry['type'].rstrip(':')
if raw:
return raw_output

View File

@ -216,7 +216,7 @@ import jc.parsers.universal
class info():
version = '1.3'
version = '1.4'
description = 'lsblk command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -330,17 +330,20 @@ def parse(data, raw=False, quiet=False):
linedata = data.splitlines()
# Clear any blank lines
cleandata = list(filter(None, linedata))
cleandata = data.splitlines()
raw_output = []
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].replace(':', '_')
cleandata[0] = cleandata[0].replace('-', '_')
if cleandata:
cleandata = data.splitlines()
raw_output = jc.parsers.universal.sparse_table_parse(cleandata)
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].replace(':', '_')
cleandata[0] = cleandata[0].replace('-', '_')
# clean up non-ascii characters, if any
for entry in raw_output:
entry['name'] = entry['name'].encode('ascii', errors='ignore').decode()
raw_output = jc.parsers.universal.sparse_table_parse(cleandata)
# clean up non-ascii characters, if any
for entry in raw_output:
entry['name'] = entry['name'].encode('ascii', errors='ignore').decode()
if raw:
return raw_output

View File

@ -107,7 +107,7 @@ import jc.parsers.universal
class info():
version = '1.1'
version = '1.2'
description = 'lsmod command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -175,13 +175,16 @@ def parse(data, raw=False, quiet=False):
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()
cleandata[0] = cleandata[0].lower()
raw_output = []
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if list(filter(None, cleandata)):
cleandata[0] = cleandata[0].lower()
for mod in raw_output:
if 'by' in mod:
mod['by'] = mod['by'].split(',')
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
for mod in raw_output:
if 'by' in mod:
mod['by'] = mod['by'].split(',')
if raw:
return raw_output

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,25 +435,26 @@ def parse(data, raw=False, quiet=False):
cleandata = list(filter(None, cleandata))
raw_output = []
# check for FreeBSD/OSX vs Linux
# is this from FreeBSD/OSX?
if cleandata[0] == 'Active Internet connections' \
or cleandata[0] == 'Active Internet connections (including servers)' \
or cleandata[0] == 'Active Multipath Internet connections' \
or cleandata[0] == 'Active LOCAL (UNIX) domain sockets' \
or cleandata[0] == 'Registered kernel control modules' \
or cleandata[0] == 'Active kernel event sockets' \
or cleandata[0] == 'Active kernel control sockets' \
or cleandata[0] == 'Routing tables' \
or cleandata[0].startswith('Name '):
if cleandata:
# check for FreeBSD/OSX vs Linux
# is this from FreeBSD/OSX?
if cleandata[0] == 'Active Internet connections' \
or cleandata[0] == 'Active Internet connections (including servers)' \
or cleandata[0] == 'Active Multipath Internet connections' \
or cleandata[0] == 'Active LOCAL (UNIX) domain sockets' \
or cleandata[0] == 'Registered kernel control modules' \
or cleandata[0] == 'Active kernel event sockets' \
or cleandata[0] == 'Active kernel control sockets' \
or cleandata[0] == 'Routing tables' \
or cleandata[0].startswith('Name '):
import jc.parsers.netstat_freebsd_osx
raw_output = jc.parsers.netstat_freebsd_osx.parse(cleandata)
import jc.parsers.netstat_freebsd_osx
raw_output = jc.parsers.netstat_freebsd_osx.parse(cleandata)
# use linux parser
else:
import jc.parsers.netstat_linux
raw_output = jc.parsers.netstat_linux.parse(cleandata)
# use linux parser
else:
import jc.parsers.netstat_linux
raw_output = jc.parsers.netstat_linux.parse(cleandata)
if raw:
return raw_output

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,28 +268,29 @@ def parse(data, raw=False, quiet=False):
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()
raw_output = []
cleandata = data.splitlines()
cleandata[0] = 's ' + cleandata[0]
cleandata[0] = cleandata[0].lower()
if list(filter(None, cleandata)):
cleandata[0] = 's ' + cleandata[0]
cleandata[0] = cleandata[0].lower()
# delete header delimiter
del cleandata[1]
# delete header delimiter
del cleandata[1]
# separate first character with a space for easier parsing
for i, line in list(enumerate(cleandata[1:])):
if line[0] == ' ':
# fixup for no-state
cleandata[i + 1] = '~ ' + line[1:]
else:
# fixup - realign columns since we added the 's' column
cleandata[i + 1] = line[:1] + ' ' + line[1:]
# separate first character with a space for easier parsing
for i, line in list(enumerate(cleandata[1:])):
if line[0] == ' ':
# fixup for no-state
cleandata[i + 1] = '~ ' + line[1:]
else:
# fixup - realign columns since we added the 's' column
cleandata[i + 1] = line[:1] + ' ' + line[1:]
# fixup for occaisional ip/hostname fields with a space
cleandata[i + 1] = cleandata[i + 1].replace(' (', '_(')
# fixup for occaisional ip/hostname fields with a space
cleandata[i + 1] = cleandata[i + 1].replace(' (', '_(')
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if raw:
return raw_output

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,23 +93,24 @@ def parse(data, raw=False, quiet=False):
# Clear any blank lines
cleandata = list(filter(None, linedata))
# detect legacy output type
if ' (' in cleandata[0]:
for row in cleandata:
raw_output.append({'package': row.split(' (')[0],
'version': row.split(' (')[1].rstrip(')')})
if cleandata:
# detect legacy output type
if ' (' in cleandata[0]:
for row in cleandata:
raw_output.append({'package': row.split(' (')[0],
'version': row.split(' (')[1].rstrip(')')})
# otherwise normal table output
else:
# clear separator line
for i, line in reversed(list(enumerate(cleandata))):
if '---' in line:
cleandata.pop(i)
# otherwise normal table output
else:
# clear separator line
for i, line in reversed(list(enumerate(cleandata))):
if '---' in line:
cleandata.pop(i)
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].lower()
if cleandata:
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if cleandata:
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if raw:
return raw_output

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,9 +282,12 @@ def parse(data, raw=False, quiet=False):
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()
cleandata[0] = cleandata[0].lower()
raw_output = []
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if list(filter(None, cleandata)):
cleandata[0] = cleandata[0].lower()
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if raw:
return raw_output

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,9 +182,12 @@ def parse(data, raw=False, quiet=False):
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()[1:]
cleandata[0] = cleandata[0].lower()
raw_output = []
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if list(filter(None, cleandata)):
cleandata[0] = cleandata[0].lower()
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if raw:
return raw_output

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'
@ -308,17 +308,17 @@ def process(proc_data):
except (ValueError):
entry[key] = None
if 'local_port' in entry:
if 'local_port' in entry:
try:
entry['local_port_num'] = int(entry['local_port'])
except (ValueError):
pass
if 'peer_port' in entry:
try:
entry['peer_port_num'] = int(entry['peer_port'])
except (ValueError):
pass
if 'peer_port' in entry:
try:
entry['peer_port_num'] = int(entry['peer_port'])
except (ValueError):
pass
return proc_data

View File

@ -40,7 +40,7 @@ import jc.utils
class info():
version = '1.1'
version = '1.2'
description = 'systemctl command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -99,24 +99,27 @@ def parse(data, raw=False, quiet=False):
linedata = data.splitlines()
# Clear any blank lines
linedata = list(filter(None, linedata))
# clean up non-ascii characters, if any
cleandata = []
for entry in linedata:
cleandata.append(entry.encode('ascii', errors='ignore').decode())
header_text = cleandata[0]
header_list = header_text.lower().split()
raw_output = []
for entry in cleandata[1:]:
if 'LOAD = ' in entry:
break
if linedata:
# clean up non-ascii characters, if any
cleandata = []
for entry in linedata:
cleandata.append(entry.encode('ascii', errors='ignore').decode())
else:
entry_list = entry.rstrip().split(maxsplit=4)
output_line = dict(zip(header_list, entry_list))
raw_output.append(output_line)
header_text = cleandata[0]
header_list = header_text.lower().split()
raw_output = []
for entry in cleandata[1:]:
if 'LOAD = ' in entry:
break
else:
entry_list = entry.rstrip().split(maxsplit=4)
output_line = dict(zip(header_list, entry_list))
raw_output.append(output_line)
if raw:
return raw_output

View File

@ -59,7 +59,7 @@ import jc.utils
class info():
version = '1.1'
version = '1.2'
description = 'systemctl list-jobs command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -125,25 +125,29 @@ def parse(data, raw=False, quiet=False):
linedata = data.splitlines()
# Clear any blank lines
linedata = list(filter(None, linedata))
# clean up non-ascii characters, if any
cleandata = []
for entry in linedata:
cleandata.append(entry.encode('ascii', errors='ignore').decode())
header_text = cleandata[0]
header_text = header_text.lower()
header_list = header_text.split()
raw_output = []
for entry in cleandata[1:]:
if 'No jobs running.' in entry or 'jobs listed.' in entry:
break
if linedata:
cleandata = []
else:
entry_list = entry.split(maxsplit=4)
output_line = dict(zip(header_list, entry_list))
raw_output.append(output_line)
# clean up non-ascii characters, if any
for entry in linedata:
cleandata.append(entry.encode('ascii', errors='ignore').decode())
header_text = cleandata[0]
header_text = header_text.lower()
header_list = header_text.split()
raw_output = []
for entry in cleandata[1:]:
if 'No jobs running.' in entry or 'jobs listed.' in entry:
break
else:
entry_list = entry.split(maxsplit=4)
output_line = dict(zip(header_list, entry_list))
raw_output.append(output_line)
if raw:
return raw_output

View File

@ -34,7 +34,7 @@ import jc.utils
class info():
version = '1.1'
version = '1.2'
description = 'systemctl list-sockets command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -91,24 +91,27 @@ def parse(data, raw=False, quiet=False):
linedata = data.splitlines()
# Clear any blank lines
linedata = list(filter(None, linedata))
# clean up non-ascii characters, if any
cleandata = []
for entry in linedata:
cleandata.append(entry.encode('ascii', errors='ignore').decode())
header_text = cleandata[0].lower()
header_list = header_text.split()
raw_output = []
for entry in cleandata[1:]:
if 'sockets listed.' in entry:
break
if linedata:
cleandata = []
# clean up non-ascii characters, if any
for entry in linedata:
cleandata.append(entry.encode('ascii', errors='ignore').decode())
else:
entry_list = entry.rsplit(maxsplit=2)
output_line = dict(zip(header_list, entry_list))
raw_output.append(output_line)
header_text = cleandata[0].lower()
header_list = header_text.split()
raw_output = []
for entry in cleandata[1:]:
if 'sockets listed.' in entry:
break
else:
entry_list = entry.rsplit(maxsplit=2)
output_line = dict(zip(header_list, entry_list))
raw_output.append(output_line)
if raw:
return raw_output

View File

@ -31,7 +31,7 @@ import jc.utils
class info():
version = '1.1'
version = '1.2'
description = 'systemctl list-unit-files command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -87,25 +87,28 @@ def parse(data, raw=False, quiet=False):
linedata = data.splitlines()
# Clear any blank lines
linedata = list(filter(None, linedata))
# clean up non-ascii characters, if any
cleandata = []
for entry in linedata:
cleandata.append(entry.encode('ascii', errors='ignore').decode())
header_text = cleandata[0]
header_text = header_text.lower().replace('unit file', 'unit_file')
header_list = header_text.split()
raw_output = []
for entry in cleandata[1:]:
if 'unit files listed.' in entry:
break
if linedata:
cleandata = []
# clean up non-ascii characters, if any
for entry in linedata:
cleandata.append(entry.encode('ascii', errors='ignore').decode())
else:
entry_list = entry.split(maxsplit=4)
output_line = dict(zip(header_list, entry_list))
raw_output.append(output_line)
header_text = cleandata[0]
header_text = header_text.lower().replace('unit file', 'unit_file')
header_list = header_text.split()
raw_output = []
for entry in cleandata[1:]:
if 'unit files listed.' in entry:
break
else:
entry_list = entry.split(maxsplit=4)
output_line = dict(zip(header_list, entry_list))
raw_output.append(output_line)
if raw:
return raw_output

View File

@ -34,7 +34,7 @@ import jc.utils
class info():
version = '1.0'
version = '1.1'
description = 'uptime command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -107,10 +107,9 @@ def parse(data, raw=False, quiet=False):
jc.utils.compatibility(__name__, info.compatible)
raw_output = {}
cleandata = data.splitlines()
if cleandata:
if list(filter(None, cleandata)):
parsed_line = cleandata[0].split()
# allow space for odd times

View File

@ -83,7 +83,7 @@ import jc.utils
class info():
version = '1.1'
version = '1.2'
description = 'w command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -149,36 +149,39 @@ def parse(data, raw=False, quiet=False):
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()[1:]
header_text = cleandata[0].lower()
# fixup for 'from' column that can be blank
from_col = header_text.find('from')
# clean up 'login@' header
# even though @ in a key is valid json, it can make things difficult
header_text = header_text.replace('login@', 'login_at')
headers = [h for h in ' '.join(header_text.strip().split()).split() if h]
# parse lines
raw_output = []
if cleandata:
for entry in cleandata[1:]:
output_line = {}
# normalize data by inserting Null for missing data
temp_line = entry.split(maxsplit=len(headers) - 1)
if list(filter(None, cleandata)):
header_text = cleandata[0].lower()
# fixup for 'from' column that can be blank
from_col = header_text.find('from')
# clean up 'login@' header
# even though @ in a key is valid json, it can make things difficult
header_text = header_text.replace('login@', 'login_at')
headers = [h for h in ' '.join(header_text.strip().split()).split() if h]
# fix from column, always at column 2
if 'from' in headers:
if entry[from_col] in string.whitespace:
temp_line.insert(2, '-')
# parse lines
raw_output = []
if cleandata:
for entry in cleandata[1:]:
output_line = {}
output_line = dict(zip(headers, temp_line))
raw_output.append(output_line)
# normalize data by inserting Null for missing data
temp_line = entry.split(maxsplit=len(headers) - 1)
# strip whitespace from beginning and end of all string values
for row in raw_output:
for item in row:
if isinstance(row[item], str):
row[item] = row[item].strip()
# fix from column, always at column 2
if 'from' in headers:
if entry[from_col] in string.whitespace:
temp_line.insert(2, '-')
output_line = dict(zip(headers, temp_line))
raw_output.append(output_line)
# strip whitespace from beginning and end of all string values
for row in raw_output:
for item in row:
if isinstance(row[item], str):
row[item] = row[item].strip()
if raw:
return raw_output

View File

@ -59,7 +59,7 @@ import xmltodict
class info():
version = '1.0'
version = '1.1'
description = 'XML file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -111,7 +111,9 @@ def parse(data, raw=False, quiet=False):
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
if data:
raw_output = []
if list(filter(None, data.splitlines())):
raw_output = xmltodict.parse(data)
if raw:

View File

@ -5,7 +5,7 @@ with open('README.md', 'r') as f:
setuptools.setup(
name='jc',
version='1.11.4',
version='1.11.5',
author='Kelly Brazil',
author_email='kellyjonbrazil@gmail.com',
description='Converts the output of popular command-line tools and file-types to JSON.',

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -17,6 +17,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/airport-I.json'), 'r', encoding='utf-8') as f:
self.osx_10_14_6_airport_I_json = json.loads(f.read())
def test_airport_I_nodata(self):
"""
Test 'airport -I' with no data
"""
self.assertEqual(jc.parsers.airport.parse('', quiet=True), {})
def test_airport_I_osx_10_14_6(self):
"""
Test 'airport -I' on OSX 10.14.6

View File

@ -17,6 +17,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/airport-s.json'), 'r', encoding='utf-8') as f:
self.osx_10_14_6_airport_s_json = json.loads(f.read())
def test_airport_s_nodata(self):
"""
Test 'airport -s' with no data
"""
self.assertEqual(jc.parsers.airport_s.parse('', quiet=True), [])
def test_airport_s_osx_10_14_6(self):
"""
Test 'airport -s' on OSX 10.14.6

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

View File

@ -17,6 +17,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/crontab.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_crontab_json = json.loads(f.read())
def test_crontab_nodata(self):
"""
Test 'crontab' with no data
"""
self.assertEqual(jc.parsers.crontab.parse('', quiet=True), {})
def test_crontab_centos_7_7(self):
"""
Test 'crontab' 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/centos-7.7/crontab-u.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_crontab_u_json = json.loads(f.read())
def test_crontab_u_nodata(self):
"""
Test 'crontab' with no data (has a user field)
"""
self.assertEqual(jc.parsers.crontab_u.parse('', quiet=True), {})
def test_crontab_u_ubuntu_18_4(self):
"""
Test 'crontab' on Ubuntu 18.4 (has a user field)

View File

@ -65,6 +65,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/csv-insurance.json'), 'r', encoding='utf-8') as f:
self.generic_csv_insurance_json = json.loads(f.read())
def test_csv_nodata(self):
"""
Test with no data
"""
self.assertEqual(jc.parsers.csv.parse('', quiet=True), [])
def test_csv_biostats(self):
"""
Test 'biostats.csv' file

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/df-h.json'), 'r', encoding='utf-8') as f:
self.osx_10_14_6_df_h_json = json.loads(f.read())
def test_df_nodata(self):
"""
Test plain 'df' with no data
"""
self.assertEqual(jc.parsers.df.parse('', quiet=True), [])
def test_df_centos_7_7(self):
"""
Test plain 'df' on Centos 7.7

View File

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

View File

@ -29,6 +29,11 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/dmidecode.json'), 'r', encoding='utf-8') as f:
self.fedora32_dmidecode_json = json.loads(f.read())
def test_dmidecode_nodata(self):
"""
Test 'dmidecode' with no data
"""
self.assertEqual(jc.parsers.dmidecode.parse('', quiet=True), [])
def test_dmidecode_centos_7_7(self):
"""

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/du.json'), 'r', encoding='utf-8') as f:
self.osx_10_14_6_du_json = json.loads(f.read())
def test_du_nodata(self):
"""
Test 'du' with no data
"""
self.assertEqual(jc.parsers.du.parse('', quiet=True), [])
def test_du_centos_7_7(self):
"""
Test 'du' 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/env.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_env_json = json.loads(f.read())
def test_env_nodata(self):
"""
Test 'env' with no data
"""
self.assertEqual(jc.parsers.env.parse('', quiet=True), [])
def test_env_centos_7_7(self):
"""
Test 'env' 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/file2.json'), 'r', encoding='utf-8') as f:
self.osx_10_14_6_file2_json = json.loads(f.read())
def test_file_nodata(self):
"""
Test 'file' with no data
"""
self.assertEqual(jc.parsers.file.parse('', quiet=True), [])
def test_file_centos_7_7(self):
"""
Test 'file *' 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/ubuntu-18.04/free-h.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_free_h_json = json.loads(f.read())
def test_free_nodata(self):
"""
Test 'free' with no data
"""
self.assertEqual(jc.parsers.free.parse('', quiet=True), [])
def test_free_centos_7_7(self):
"""
Test 'free' 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/fstab.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_fstab_json = json.loads(f.read())
def test_fstab_nodata(self):
"""
Test 'cat /etc/fstab' with no data
"""
self.assertEqual(jc.parsers.fstab.parse('', quiet=True), [])
def test_fstab_centos_7_7(self):
"""
Test 'cat /etc/fstab' 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/group.json'), 'r', encoding='utf-8') as f:
self.osx_10_14_6_group_json = json.loads(f.read())
def test_group_nodata(self):
"""
Test 'cat /etc/group' with no data
"""
self.assertEqual(jc.parsers.group.parse('', quiet=True), [])
def test_group_centos_7_7(self):
"""
Test 'cat /etc/group' 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/gshadow.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_gshadow_json = json.loads(f.read())
def test_gshadow_nodata(self):
"""
Test 'cat /etc/gshadow' with no data
"""
self.assertEqual(jc.parsers.gshadow.parse('', quiet=True), [])
def test_gshadow_centos_7_7(self):
"""
Test 'cat /etc/gshadow' 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/history.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_history_json = json.loads(f.read())
def test_history_nodata(self):
"""
Test 'history' with no data
"""
self.assertEqual(jc.parsers.history.parse('', quiet=True), [])
def test_history_centos_7_7(self):
"""
Test 'history' 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/hosts.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_hosts_json = json.loads(f.read())
def test_hosts_nodata(self):
"""
Test 'cat /etc/hosts' with no data
"""
self.assertEqual(jc.parsers.hosts.parse('', quiet=True), [])
def test_hosts_centos_7_7(self):
"""
Test 'cat /etc/hosts' 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/osx-10.14.6/id.json'), 'r', encoding='utf-8') as f:
self.osx_10_14_6_id_json = json.loads(f.read())
def test_id_nodata(self):
"""
Test 'id' with no data
"""
self.assertEqual(jc.parsers.id.parse('', quiet=True), {})
def test_id_centos_7_7(self):
"""
Test 'id' 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/osx-10.14.6/ifconfig2.json'), 'r', encoding='utf-8') as f:
self.osx_10_14_6_ifconfig2_json = json.loads(f.read())
def test_ifconfig_nodata(self):
"""
Test 'ifconfig' with no data
"""
self.assertEqual(jc.parsers.ifconfig.parse('', quiet=True), [])
def test_ifconfig_centos_7_7(self):
"""
Test 'ifconfig' 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/generic/ini-iptelserver.json'), 'r', encoding='utf-8') as f:
self.generic_ini_iptelserver_json = json.loads(f.read())
def test_ini_nodata(self):
"""
Test the test ini file with no data
"""
self.assertEqual(jc.parsers.ini.parse('', quiet=True), {})
def test_ini_test(self):
"""
Test the test ini file

View File

@ -83,6 +83,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/iptables-raw.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_iptables_raw_json = json.loads(f.read())
def test_iptables_nodata(self):
"""
Test 'sudo iptables' with no data
"""
self.assertEqual(jc.parsers.iptables.parse('', quiet=True), [])
def test_iptables_filter_centos_7_7(self):
"""
Test 'sudo iptables -L -t filter' 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/jobs.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_jobs_json = json.loads(f.read())
def test_jobs_nodata(self):
"""
Test 'jobs' with no data
"""
self.assertEqual(jc.parsers.jobs.parse('', quiet=True), [])
def test_jobs_centos_7_7(self):
"""
Test 'jobs' on Centos 7.7

View File

@ -65,6 +65,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/last.json'), 'r', encoding='utf-8') as f:
self.freebsd12_last_json = json.loads(f.read())
def test_last_nodata(self):
"""
Test plain 'last' with no data
"""
self.assertEqual(jc.parsers.last.parse('', quiet=True), [])
def test_last_centos_7_7(self):
"""
Test plain 'last' 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/ubuntu-18.04/lsblk-allcols.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_lsblk_allcols_json = json.loads(f.read())
def test_lsblk_nodata(self):
"""
Test 'lsblk' with no data
"""
self.assertEqual(jc.parsers.lsblk.parse('', quiet=True), [])
def test_lsblk_centos_7_7(self):
"""
Test 'lsblk' 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/lsmod.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_lsmod_json = json.loads(f.read())
def test_lsmod_nodata(self):
"""
Test 'lsmod' with no data
"""
self.assertEqual(jc.parsers.lsmod.parse('', quiet=True), [])
def test_lsmod_centos_7_7(self):
"""
Test 'lsmod' 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/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

View File

@ -35,6 +35,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/stat.json'), 'r', encoding='utf-8') as f:
self.freebsd12_stat_json = json.loads(f.read())
def test_stat_nodata(self):
"""
Test 'stat' with no data
"""
self.assertEqual(jc.parsers.stat.parse('', quiet=True), [])
def test_stat_centos_7_7(self):
"""
Test 'stat /bin/*' 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/systemctl.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_systemctl_json = json.loads(f.read())
def test_systemctl_nodata(self):
"""
Test 'systemctl' with no data
"""
self.assertEqual(jc.parsers.systemctl.parse('', quiet=True), [])
def test_systemctl_centos_7_7(self):
"""
Test 'systemctl -a' on Centos 7.7

View File

@ -17,6 +17,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/systemctl-lj.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_systemctl_lj_json = json.loads(f.read())
def test_systemctl_lj_nodata(self):
"""
Test 'systemctl -a list-jobs' with no data
"""
self.assertEqual(jc.parsers.systemctl_lj.parse('', quiet=True), [])
def test_systemctl_lj_ubuntu_18_4(self):
"""
Test 'systemctl -a list-jobs' on Ubuntu 18.4

View File

@ -23,6 +23,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/systemctl-ls.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_systemctl_ls_json = json.loads(f.read())
def test_systemctl_ls_nodata(self):
"""
Test 'systemctl -a list-sockets' with no data
"""
self.assertEqual(jc.parsers.systemctl_ls.parse('', quiet=True), [])
def test_systemctl_ls_centos_7_7(self):
"""
Test 'systemctl -a list-sockets' 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/systemctl-luf.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_systemctl_luf_json = json.loads(f.read())
def test_systemctl_luf_nodata(self):
"""
Test 'systemctl -a list-sockets' with no data
"""
self.assertEqual(jc.parsers.systemctl_luf.parse('', quiet=True), [])
def test_systemctl_luf_centos_7_7(self):
"""
Test 'systemctl -a list-sockets' 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/timedatectl.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_timedatectl_json = json.loads(f.read())
def test_timedatectl_nodata(self):
"""
Test 'timedatectl' with no data
"""
self.assertEqual(jc.parsers.timedatectl.parse('', quiet=True), {})
def test_timedatectl_centos_7_7(self):
"""
Test 'timedatectl' 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/uname-a.json'), 'r', encoding='utf-8') as f:
self.osx_10_14_6_uname_a_json = json.loads(f.read())
def test_uname_nodata(self):
"""
Test 'uname -a' with no data
"""
self.assertEqual(jc.parsers.uname.parse('', quiet=True), {})
def test_uname_centos_7_7(self):
"""
Test 'uname -a' 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/uptime.json'), 'r', encoding='utf-8') as f:
self.osx_10_14_6_uptime_json = json.loads(f.read())
def test_uptime_nodata(self):
"""
Test 'uptime' with no data
"""
self.assertEqual(jc.parsers.uptime.parse('', quiet=True), {})
def test_uptime_centos_7_7(self):
"""
Test 'uptime' 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/w.json'), 'r', encoding='utf-8') as f:
self.nixos_w_json = json.loads(f.read())
def test_w_nodata(self):
"""
Test 'w' with no data
"""
self.assertEqual(jc.parsers.w.parse('', quiet=True), [])
def test_w_centos_7_7(self):
"""
Test 'w' 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/osx-10.14.6/who-a.json'), 'r', encoding='utf-8') as f:
self.osx_10_14_6_who_a_json = json.loads(f.read())
def test_who_nodata(self):
"""
Test 'who' with no data
"""
self.assertEqual(jc.parsers.who.parse('', quiet=True), [])
def test_who_centos_7_7(self):
"""
Test 'who' 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/generic/xml-foodmenu.json'), 'r', encoding='utf-8') as f:
self.generic_xml_foodmenu_json = json.loads(f.read())
def test_xml_nodata(self):
"""
Test xml parser with no data
"""
self.assertEqual(jc.parsers.xml.parse('', quiet=True), [])
def test_xml_cd_catalog(self):
"""
Test the cd catalog xml file

View File

@ -23,6 +23,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/yaml-istio-sidecar.json'), 'r', encoding='utf-8') as f:
self.generic_yaml_istio_sidecar_json = json.loads(f.read())
def test_yaml_nodata(self):
"""
Test the YAML parser with no data
"""
self.assertEqual(jc.parsers.yaml.parse('', quiet=True), [])
def test_yaml_istio_sc(self):
"""
Test the Istio SC yaml file