mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-15 01:24:29 +02:00
add compatibility function
This commit is contained in:
8
jc/jc.py
8
jc/jc.py
@ -73,7 +73,7 @@ def helptext(message):
|
||||
print(textwrap.dedent(helptext_string), file=sys.stderr)
|
||||
|
||||
|
||||
def errormessage(message):
|
||||
def error_message(message):
|
||||
error_string = f'''
|
||||
jc: {message}
|
||||
'''
|
||||
@ -82,11 +82,13 @@ def errormessage(message):
|
||||
|
||||
|
||||
def compatibility(mod_name, compatible):
|
||||
'''
|
||||
compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
'''
|
||||
if sys.platform not in compatible:
|
||||
mod = mod_name.split('.')[-1]
|
||||
compat_list = ', '.join(compatible)
|
||||
errormessage(f'{mod} parser not compatible with your OS ({sys.platform}).\n Compatible platforms: {compat_list}')
|
||||
exit()
|
||||
error_message(f'Warning - {mod} parser not compatible with your OS ({sys.platform}).\n Compatible platforms: {compat_list}')
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -104,8 +104,9 @@ def process(proc_data):
|
||||
|
||||
|
||||
def parse(data, raw=False):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux'])
|
||||
['linux', 'aix', 'freebsd'])
|
||||
|
||||
# code adapted from Conor Heine at:
|
||||
# https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501
|
||||
|
@ -107,6 +107,7 @@ def process(proc_data):
|
||||
|
||||
|
||||
def parse(data, raw=False):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux'])
|
||||
|
||||
|
@ -148,6 +148,7 @@ $ dig -x 1.1.1.1 | jc --dig -p
|
||||
}
|
||||
]
|
||||
"""
|
||||
import jc
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
@ -311,6 +312,10 @@ def parse_answer(answer):
|
||||
|
||||
|
||||
def parse(data, raw=False):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'])
|
||||
|
||||
raw_output = []
|
||||
cleandata = data.splitlines()
|
||||
# remove blank lines
|
||||
|
@ -43,6 +43,7 @@ $ env | jc --env -p -r
|
||||
"_": "/usr/bin/env"
|
||||
}
|
||||
"""
|
||||
import jc
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
@ -67,6 +68,10 @@ def process(proc_data):
|
||||
|
||||
|
||||
def parse(data, raw=False):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'])
|
||||
|
||||
raw_output = {}
|
||||
|
||||
linedata = data.splitlines()
|
||||
|
@ -43,6 +43,7 @@ $ free | jc --free -p -r
|
||||
}
|
||||
]
|
||||
"""
|
||||
import jc
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
@ -74,6 +75,9 @@ def process(proc_data):
|
||||
|
||||
|
||||
def parse(data, raw=False):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux'])
|
||||
|
||||
# code adapted from Conor Heine at:
|
||||
# https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501
|
||||
|
@ -35,6 +35,7 @@ $ history | jc --history -p -r
|
||||
...
|
||||
}
|
||||
"""
|
||||
import jc
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
@ -59,6 +60,10 @@ def process(proc_data):
|
||||
|
||||
|
||||
def parse(data, raw=False):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'])
|
||||
|
||||
raw_output = {}
|
||||
|
||||
# split lines and clear out any non-ascii chars
|
||||
|
@ -120,6 +120,7 @@ $ ifconfig | jc --ifconfig -p -r
|
||||
}
|
||||
]
|
||||
"""
|
||||
import jc
|
||||
from ifconfigparser import IfconfigParser
|
||||
|
||||
|
||||
@ -170,6 +171,10 @@ def process(proc_data):
|
||||
|
||||
|
||||
def parse(data, raw=False):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux', 'aix', 'freebsd'])
|
||||
|
||||
raw_output = []
|
||||
|
||||
parsed = IfconfigParser(console_output=data)
|
||||
|
@ -125,6 +125,7 @@ $ sudo iptables --line-numbers -v -L -t nat | jc --iptables -p -r
|
||||
...
|
||||
]
|
||||
"""
|
||||
import jc
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
@ -193,6 +194,10 @@ def process(proc_data):
|
||||
|
||||
|
||||
def parse(data, raw=False):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux'])
|
||||
|
||||
raw_output = []
|
||||
chain = {}
|
||||
headers = []
|
||||
|
@ -68,6 +68,7 @@ $ jobs -l | jc --jobs -p -r
|
||||
]
|
||||
"""
|
||||
import string
|
||||
import jc
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
@ -96,6 +97,10 @@ def process(proc_data):
|
||||
|
||||
|
||||
def parse(data, raw=False):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux', 'darwin', 'cygwin', 'aix', 'freebsd'])
|
||||
|
||||
raw_output = []
|
||||
|
||||
linedata = data.splitlines()
|
||||
|
@ -166,8 +166,9 @@ def process(proc_data):
|
||||
|
||||
|
||||
def parse(data, raw=False):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux', 'darwin'])
|
||||
['linux', 'darwin', 'cygwin', 'aix', 'freebsd'])
|
||||
|
||||
raw_output = []
|
||||
|
||||
|
@ -130,6 +130,7 @@ def process(proc_data):
|
||||
|
||||
|
||||
def parse(data, raw=False):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux'])
|
||||
|
||||
|
@ -52,9 +52,13 @@ $ lsmod | jc --lsmod -p
|
||||
...
|
||||
]
|
||||
"""
|
||||
import jc
|
||||
|
||||
|
||||
def parse(data):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux'])
|
||||
|
||||
# code adapted from Conor Heine at:
|
||||
# https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501
|
||||
|
@ -71,9 +71,14 @@ $ sudo lsof | jc --lsof -p | more
|
||||
]
|
||||
"""
|
||||
import string
|
||||
import jc
|
||||
|
||||
|
||||
def parse(data):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux'])
|
||||
|
||||
output = []
|
||||
|
||||
linedata = data.splitlines()
|
||||
|
@ -47,9 +47,14 @@ $ mount | jc --mount -p
|
||||
...
|
||||
]
|
||||
"""
|
||||
import jc
|
||||
|
||||
|
||||
def parse(data):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux'])
|
||||
|
||||
output = []
|
||||
|
||||
linedata = data.splitlines()
|
||||
|
@ -97,9 +97,14 @@ $ sudo netstat -lpn | jc --netstat -p
|
||||
]
|
||||
"""
|
||||
import string
|
||||
import jc
|
||||
|
||||
|
||||
def parse_line(entry):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux'])
|
||||
|
||||
output_line = {}
|
||||
|
||||
if entry.find('tcp') == 0:
|
||||
|
@ -3,6 +3,7 @@
|
||||
Usage:
|
||||
Specify --netstat as the first argument if the piped input is coming from netstat
|
||||
"""
|
||||
import jc
|
||||
|
||||
|
||||
def normalize_headers(header):
|
||||
@ -44,6 +45,10 @@ def post_process(network_list, socket_list):
|
||||
|
||||
|
||||
def parse(data):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux'])
|
||||
|
||||
cleandata = data.splitlines()
|
||||
|
||||
network = False
|
||||
|
@ -65,9 +65,13 @@ $ ps -ef | jc --ps -p
|
||||
...
|
||||
]
|
||||
"""
|
||||
import jc
|
||||
|
||||
|
||||
def parse(data):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux', 'darwin', 'cygwin', 'aix', 'freebsd'])
|
||||
|
||||
# code adapted from Conor Heine at:
|
||||
# https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501
|
||||
|
@ -40,9 +40,13 @@ $ route | jc --route -p
|
||||
}
|
||||
]
|
||||
"""
|
||||
import jc
|
||||
|
||||
|
||||
def parse(data):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux', 'aix', 'freebsd'])
|
||||
|
||||
# code adapted from Conor Heine at:
|
||||
# https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501
|
||||
|
@ -20,9 +20,14 @@ $ uname -a | jc --uname -p
|
||||
"kernel_version": "#74-Ubuntu SMP Tue Sep 17 17:06:04 UTC 2019"
|
||||
}
|
||||
"""
|
||||
import jc
|
||||
|
||||
|
||||
def parse(data):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux'])
|
||||
|
||||
output = {}
|
||||
parsed_line = data.split(maxsplit=3)
|
||||
|
||||
|
@ -15,9 +15,14 @@ $ uptime | jc --uptime -p
|
||||
"load_15m": "1.91"
|
||||
}
|
||||
"""
|
||||
import jc
|
||||
|
||||
|
||||
def parse(data):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux', 'darwin', 'cygwin', 'aix', 'freebsd'])
|
||||
|
||||
output = {}
|
||||
|
||||
cleandata = data.splitlines()
|
||||
|
@ -29,9 +29,13 @@ $ w | jc --w -p
|
||||
}
|
||||
]
|
||||
"""
|
||||
import jc
|
||||
|
||||
|
||||
def parse(data):
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
jc.jc.compatibility(__name__,
|
||||
['linux', 'darwin', 'cygwin', 'aix', 'freebsd'])
|
||||
|
||||
# code adapted from Conor Heine at:
|
||||
# https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501
|
||||
|
Reference in New Issue
Block a user