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

update docs

This commit is contained in:
Kelly Brazil
2021-04-08 15:53:06 -07:00
parent b8b8dfead4
commit da611f0ac6
4 changed files with 63 additions and 50 deletions

View File

@ -13,6 +13,19 @@ Usage (module):
import jc.parsers.ini
result = jc.parsers.ini.parse(ini_file_output)
Schema:
ini or key/value document converted to a dictionary - see configparser standard
library documentation for more details.
Note: Values starting and ending with quotation marks will have the marks removed.
If you would like to keep the quotation marks, use the -r or raw=True argument.
{
"key1": string,
"key2": string
}
Compatibility:
'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'
@ -56,7 +69,8 @@ import configparser
class info():
version = '1.3'
"""Provides parser metadata (version, author, etc.)"""
version = '1.4'
description = 'INI file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -69,7 +83,7 @@ class info():
__version__ = info.version
def process(proc_data):
def _process(proc_data):
"""
Final processing to conform to the schema.
@ -79,15 +93,7 @@ def process(proc_data):
Returns:
Dictionary representing an ini or simple key/value pair document:
{
ini or key/value document converted to a dictionary - see configparser standard
library documentation for more details.
Note: Values starting and ending with quotation marks will have the marks removed.
If you would like to keep the quotation marks, use the -r or raw=True argument.
}
Dictionary representing an ini or simple key/value pair document.
"""
# remove quotation marks from beginning and end of values
for heading in proc_data:
@ -145,4 +151,4 @@ def parse(data, raw=False, quiet=False):
if raw:
return raw_output
else:
return process(raw_output)
return _process(raw_output)

View File

@ -15,6 +15,29 @@ Usage (module):
import jc.parsers.iptables
result = jc.parsers.iptables.parse(iptables_command_output)
Schema:
[
{
"chain": string,
"rules": [
{
"num" integer,
"pkts": integer,
"bytes": integer, # converted based on suffix
"target": string,
"prot": string,
"opt": string, # "--" = Null
"in": string,
"out": string,
"source": string,
"destination": string,
"options": string
}
]
}
]
Compatibility:
'linux'
@ -143,7 +166,8 @@ import jc.utils
class info():
version = '1.4'
"""Provides parser metadata (version, author, etc.)"""
version = '1.5'
description = '`iptables` command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -156,7 +180,7 @@ class info():
__version__ = info.version
def process(proc_data):
def _process(proc_data):
"""
Final processing to conform to the schema.
@ -166,28 +190,7 @@ def process(proc_data):
Returns:
List of Dictionaries. Structured data with the following schema:
[
{
"chain": string,
"rules": [
{
"num" integer,
"pkts": integer,
"bytes": integer, # converted based on suffix
"target": string,
"prot": string,
"opt": string, # "--" = Null
"in": string,
"out": string,
"source": string,
"destination": string,
"options": string
}
]
}
]
List of Dictionaries. Structured data to conform to the schema.
"""
for entry in proc_data:
for rule in entry['rules']:
@ -289,4 +292,4 @@ def parse(data, raw=False, quiet=False):
if raw:
return raw_output
else:
return process(raw_output)
return _process(raw_output)

View File

@ -15,6 +15,16 @@ Usage (module):
import jc.parsers.iw-scan
result = jc.parsers.iw-scan.parse(iw-scan_command_output)
Schema:
[
{
"foo": string/integer/float, # best guess based on value
"bar": string/integer/float,
"baz": string/integer/float
}
]
Compatibility:
'linux'
@ -114,7 +124,8 @@ import jc.utils
class info():
version = '0.5'
"""Provides parser metadata (version, author, etc.)"""
version = '0.6'
description = '`iw dev [device] scan` command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -128,7 +139,7 @@ class info():
__version__ = info.version
def process(proc_data):
def _process(proc_data):
"""
Final processing to conform to the schema.
@ -138,14 +149,7 @@ def process(proc_data):
Returns:
List of Dictionaries. Structured data with the following schema:
[
{
"foo": string/integer/float, # best guess based on value
"bar": string/integer/float,
"baz": string/integer/float
}
]
List of Dictionaries. Structured data to conform to the schema.
"""
# convert ints and floats for top-level keys
@ -174,7 +178,7 @@ def process(proc_data):
return proc_data
def post_parse(data):
def _post_parse(data):
# remove empty items
cleandata = []
for ssid in data:
@ -276,7 +280,7 @@ def post_parse(data):
item['vht_tx_highest_supported_mbps'] = item['vht_tx_highest_supported'].replace(' Mbps', '')
del item['vht_tx_highest_supported']
return process(cleandata)
return _process(cleandata)
def parse(data, raw=False, quiet=False):
@ -331,4 +335,4 @@ def parse(data, raw=False, quiet=False):
if raw:
return raw_output
else:
return post_parse(raw_output)
return _post_parse(raw_output)

Binary file not shown.