mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-23 00:29:59 +02:00
add ps parser
This commit is contained in:
@ -1,13 +1,13 @@
|
|||||||
jc changelog
|
jc changelog
|
||||||
|
|
||||||
2019xxxx v0.5.0
|
2019xxxx v0.5.0
|
||||||
- Add ps parser
|
|
||||||
- Add route parser
|
|
||||||
- Change some ifconfig fields to integers
|
|
||||||
- Fix netstat -p parsing for Ubuntu
|
- Fix netstat -p parsing for Ubuntu
|
||||||
- Use maxsplit option in split in ls.py line 109... otherwise filenames with multiple spaces
|
+ Add ps parser
|
||||||
|
+ Add route parser
|
||||||
|
+ Change some ifconfig fields to integers
|
||||||
|
+ Use maxsplit option in split in ls.py line 109... otherwise filenames with multiple spaces
|
||||||
between words can be incorrectly represented with the .join operation
|
between words can be incorrectly represented with the .join operation
|
||||||
- Use list(filter(None, cleandata)) or list comprehension to clean any blank entries in ls.py line 98
|
+ Use list(filter(None, cleandata)) or list comprehension to clean any blank entries in ls.py line 98
|
||||||
|
|
||||||
20191017 v0.2.0
|
20191017 v0.2.0
|
||||||
- ifconfig, ls, and netstat support
|
- ifconfig, ls, and netstat support
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
"""JC - JSON CLI output utility
|
"""JC - JSON CLI output utility
|
||||||
|
|
||||||
v0.1
|
|
||||||
|
|
||||||
* kellyjonbrazil@gmail.com
|
* kellyjonbrazil@gmail.com
|
||||||
|
|
||||||
This module serializes standard unix command line output to structured JSON
|
This module serializes standard unix command line output to structured JSON
|
||||||
|
3
jc/jc.py
3
jc/jc.py
@ -9,6 +9,7 @@ import json
|
|||||||
import jc.parsers.ifconfig
|
import jc.parsers.ifconfig
|
||||||
import jc.parsers.ls
|
import jc.parsers.ls
|
||||||
import jc.parsers.netstat
|
import jc.parsers.netstat
|
||||||
|
import jc.parsers.ps
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -34,6 +35,8 @@ def main():
|
|||||||
result = jc.parsers.ls.parse(data)
|
result = jc.parsers.ls.parse(data)
|
||||||
elif arg == '--netstat':
|
elif arg == '--netstat':
|
||||||
result = jc.parsers.netstat.parse(data)
|
result = jc.parsers.netstat.parse(data)
|
||||||
|
elif arg == '--ps':
|
||||||
|
result = jc.parsers.ps.parse(data)
|
||||||
|
|
||||||
# output resulting dictionary as json
|
# output resulting dictionary as json
|
||||||
if pretty:
|
if pretty:
|
||||||
|
21
jc/parsers/ps.py
Normal file
21
jc/parsers/ps.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
"""jc - JSON CLI output utility ps Parser
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
specify --ps as the first argument if the piped input is coming from ps
|
||||||
|
|
||||||
|
ps options supported:
|
||||||
|
- ef
|
||||||
|
- axu
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def parse(data):
|
||||||
|
|
||||||
|
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]
|
Reference in New Issue
Block a user