diff --git a/jc/parsers/ini.py b/jc/parsers/ini.py index 4303dd6d..fa847ef4 100644 --- a/jc/parsers/ini.py +++ b/jc/parsers/ini.py @@ -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) diff --git a/jc/parsers/iptables.py b/jc/parsers/iptables.py index 2b484797..e8fb6f9a 100644 --- a/jc/parsers/iptables.py +++ b/jc/parsers/iptables.py @@ -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) diff --git a/jc/parsers/iw_scan.py b/jc/parsers/iw_scan.py index 0c9e2bb7..012539c5 100644 --- a/jc/parsers/iw_scan.py +++ b/jc/parsers/iw_scan.py @@ -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) diff --git a/man/jc.1.gz b/man/jc.1.gz index 31db3eed..b2656eee 100644 Binary files a/man/jc.1.gz and b/man/jc.1.gz differ