mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-21 00:19:42 +02:00
linting
This commit is contained in:
7
jc/jc.py
7
jc/jc.py
@ -10,14 +10,16 @@ import jc.parsers.ifconfig
|
|||||||
import jc.parsers.ls
|
import jc.parsers.ls
|
||||||
import jc.parsers.netstat
|
import jc.parsers.netstat
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
pretty = False
|
pretty = False
|
||||||
data = sys.stdin.read()
|
data = sys.stdin.read()
|
||||||
|
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print(f'\nError: jc\n Must specify parser. (e.g. --ls, --netstat, --ifconfig, etc.)')
|
print('Error: jc')
|
||||||
|
print(' Must specify parser. (e.g. --ls, --netstat, --ifconfig, etc.)')
|
||||||
print(' Use -p to pretty print')
|
print(' Use -p to pretty print')
|
||||||
print(f'\nExample: ls -al | jc --ls -p\n')
|
print('Example: ls -al | jc --ls -p\n')
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
arg = sys.argv[1]
|
arg = sys.argv[1]
|
||||||
@ -39,5 +41,6 @@ def main():
|
|||||||
else:
|
else:
|
||||||
print(json.dumps(result))
|
print(json.dumps(result))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -13,6 +13,7 @@ $ ifconfig | jc --ifconfig -p
|
|||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from ifconfigparser import IfconfigParser
|
from ifconfigparser import IfconfigParser
|
||||||
|
|
||||||
|
|
||||||
def parse(data):
|
def parse(data):
|
||||||
output = []
|
output = []
|
||||||
|
|
||||||
@ -26,5 +27,3 @@ def parse(data):
|
|||||||
output.append(dct)
|
output.append(dct)
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,6 +85,7 @@ $ $ ls -l /usr/bin | jc --ls | jq .[] | jq 'select(.bytes > 50000000)'
|
|||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
def parse(data):
|
def parse(data):
|
||||||
output = []
|
output = []
|
||||||
|
|
||||||
|
@ -138,6 +138,7 @@ import string
|
|||||||
|
|
||||||
output = {}
|
output = {}
|
||||||
|
|
||||||
|
|
||||||
class state():
|
class state():
|
||||||
section = ''
|
section = ''
|
||||||
session = ''
|
session = ''
|
||||||
@ -153,6 +154,7 @@ class state():
|
|||||||
server_udp_ip4 = []
|
server_udp_ip4 = []
|
||||||
server_udp_ip6 = []
|
server_udp_ip6 = []
|
||||||
|
|
||||||
|
|
||||||
def parse_line(entry):
|
def parse_line(entry):
|
||||||
parsed_line = entry.split()
|
parsed_line = entry.split()
|
||||||
output_line = {}
|
output_line = {}
|
||||||
@ -179,6 +181,7 @@ def parse_line(entry):
|
|||||||
|
|
||||||
return output_line
|
return output_line
|
||||||
|
|
||||||
|
|
||||||
def parse(data):
|
def parse(data):
|
||||||
cleandata = data.splitlines()
|
cleandata = data.splitlines()
|
||||||
|
|
||||||
@ -225,6 +228,7 @@ def parse(data):
|
|||||||
else:
|
else:
|
||||||
state.network = 'ipv4'
|
state.network = 'ipv4'
|
||||||
|
|
||||||
|
# client section
|
||||||
if state.section == 'client' and state.session == 'tcp' and state.network == 'ipv4':
|
if state.section == 'client' and state.session == 'tcp' and state.network == 'ipv4':
|
||||||
state.client_tcp_ip4.append(parse_line(line))
|
state.client_tcp_ip4.append(parse_line(line))
|
||||||
|
|
||||||
@ -237,7 +241,7 @@ def parse(data):
|
|||||||
if state.section == 'client' and state.session == 'udp' and state.network == 'ipv6':
|
if state.section == 'client' and state.session == 'udp' and state.network == 'ipv6':
|
||||||
state.client_udp_ip6.append(parse_line(line))
|
state.client_udp_ip6.append(parse_line(line))
|
||||||
|
|
||||||
|
# server section
|
||||||
if state.section == 'server' and state.session == 'tcp' and state.network == 'ipv4':
|
if state.section == 'server' and state.session == 'tcp' and state.network == 'ipv4':
|
||||||
state.server_tcp_ip4.append(parse_line(line))
|
state.server_tcp_ip4.append(parse_line(line))
|
||||||
|
|
||||||
@ -254,6 +258,7 @@ def parse(data):
|
|||||||
state.network = ''
|
state.network = ''
|
||||||
|
|
||||||
# build dictionary
|
# build dictionary
|
||||||
|
# client section
|
||||||
if state.client_tcp_ip4:
|
if state.client_tcp_ip4:
|
||||||
if 'client' not in output:
|
if 'client' not in output:
|
||||||
output['client'] = {}
|
output['client'] = {}
|
||||||
@ -282,7 +287,7 @@ def parse(data):
|
|||||||
output['client']['udp'] = {}
|
output['client']['udp'] = {}
|
||||||
output['client']['udp']['ipv6'] = state.client_udp_ip6
|
output['client']['udp']['ipv6'] = state.client_udp_ip6
|
||||||
|
|
||||||
|
# server section
|
||||||
if state.server_tcp_ip4:
|
if state.server_tcp_ip4:
|
||||||
if 'server' not in output:
|
if 'server' not in output:
|
||||||
output['server'] = {}
|
output['server'] = {}
|
||||||
|
Reference in New Issue
Block a user