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

add route parser

This commit is contained in:
Kelly Brazil
2019-10-18 13:38:11 -07:00
parent 367ab54f94
commit 43ed09ce5b
3 changed files with 25 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import jc.parsers.ifconfig
import jc.parsers.ls
import jc.parsers.netstat
import jc.parsers.ps
import jc.parsers.route
def main():
@ -37,6 +38,8 @@ def main():
result = jc.parsers.netstat.parse(data)
elif arg == '--ps':
result = jc.parsers.ps.parse(data)
elif arg == '--route':
result = jc.parsers.route.parse(data)
# output resulting dictionary as json
if pretty:

21
jc/parsers/route.py Normal file
View File

@ -0,0 +1,21 @@
"""jc - JSON CLI output utility route Parser
Usage:
specify --route as the first argument if the piped input is coming from route
Example:
"""
def parse(data):
# code adapted from Conor Heine at:
# https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501
cleandata = data.splitlines()
headers = [h for h in ' '.join(cleandata[0].strip().split()).split() if h]
raw_data = map(lambda s: s.strip().split(None, len(headers) - 1), cleandata[1:])
return [dict(zip(headers, r)) for r in raw_data]

View File

@ -5,7 +5,7 @@ with open('README.md', 'r') as f:
setuptools.setup(
name='jc',
version='0.5.1',
version='0.5.2',
author='Kelly Brazil',
author_email='kellyjonbrazil@gmail.com',
description='This tool serializes the output of popular command line tools to structured JSON output.',