1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-13 01:20:24 +02:00

initial pip show parser add

This commit is contained in:
Kelly Brazil
2019-12-16 19:07:51 -08:00
parent ad338cc5b5
commit addeef50ba

84
jc/parsers/pip_show.py Normal file
View File

@ -0,0 +1,84 @@
"""jc - JSON CLI output utility pip-show Parser
Usage:
specify --pip-show as the first argument if the piped input is coming from pip show
Compatibility:
'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'
Examples:
$ pip show | jc --pip-show -p
[
]
"""
import jc.utils
import jc.parsers.universal
class info():
version = '1.0'
description = 'pip-show parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
compatible = ['linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd']
def process(proc_data):
"""
Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
Returns:
dictionary structured data with the following schema:
[
{
}
]
"""
# no further processing
return proc_data
def parse(data, raw=False, quiet=False):
"""
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
dictionary raw or processed structured data
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
raw_output = []
linedata = data.splitlines()
# Clear any blank lines
cleandata = list(filter(None, linedata))
# '---' is record separator
if cleandata:
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if raw:
return raw_output
else:
return process(raw_output)