diff --git a/changelog.txt b/changelog.txt index 9a435c34..97004a7b 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,13 +1,13 @@ jc changelog 2019xxxx v0.5.0 -- Add ps parser -- Add route parser -- Change some ifconfig fields to integers - 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 -- 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 - ifconfig, ls, and netstat support diff --git a/jc/__init__.py b/jc/__init__.py index fb8c1668..d584b3c6 100644 --- a/jc/__init__.py +++ b/jc/__init__.py @@ -1,7 +1,5 @@ """JC - JSON CLI output utility -v0.1 - * kellyjonbrazil@gmail.com This module serializes standard unix command line output to structured JSON diff --git a/jc/jc.py b/jc/jc.py index cc401823..5f981b7e 100755 --- a/jc/jc.py +++ b/jc/jc.py @@ -9,6 +9,7 @@ import json import jc.parsers.ifconfig import jc.parsers.ls import jc.parsers.netstat +import jc.parsers.ps def main(): @@ -34,6 +35,8 @@ def main(): result = jc.parsers.ls.parse(data) elif arg == '--netstat': result = jc.parsers.netstat.parse(data) + elif arg == '--ps': + result = jc.parsers.ps.parse(data) # output resulting dictionary as json if pretty: diff --git a/jc/parsers/ps.py b/jc/parsers/ps.py new file mode 100644 index 00000000..c3c27bfa --- /dev/null +++ b/jc/parsers/ps.py @@ -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]