1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2026-04-05 17:50:11 +02:00

Compare commits

..

6 Commits

Author SHA1 Message Date
Kelly Brazil
87b506dc9b fix for spaces in dig answer data 2021-02-05 06:55:06 -08:00
Kelly Brazil
15c9002d9e simplify logic by taking out 'not' in JC_COLORS parsing 2021-01-08 11:56:56 -08:00
Kelly Brazil
042aaa61b9 minor updates 2021-01-08 08:23:29 -08:00
Kelly Brazil
ef856c6ba5 clarify -q option 2021-01-07 12:09:41 -08:00
Kelly Brazil
9cf5be73e3 typo fix 2021-01-06 16:19:47 -08:00
Kelly Brazil
63fc149e2a typo fix 2021-01-06 16:17:25 -08:00
10 changed files with 58 additions and 15 deletions

View File

@@ -1,5 +1,8 @@
jc changelog
20210205 v1.14.2
- Update dig parser to fix cases where there are spaces in the answer data (e.g. TXT records)
20210106 v1.14.1
- Add iw-scan parser tested on linux (beta)
- Update date parser for Ubuntu 20.04 support

View File

@@ -111,7 +111,7 @@ pip3 install jc
```bash
COMMAND | jc PARSER [OPTIONS]
```
Alternatively, the "magic" syntax can be used by prepending `jc` to the command to be converted. Options can be passed to `jc` immediately before the command is given. (Note: command aliases are not supported)
Alternatively, the "magic" syntax can be used by prepending `jc` to the command to be converted. Options can be passed to `jc` immediately before the command is given. (Note: command aliases and shell builtins are not supported)
```bash
jc [OPTIONS] COMMAND
```
@@ -183,10 +183,10 @@ The JSON output can be compact (default) or pretty formatted with the `-p` optio
### Options
- `-a` about `jc`. Prints information about `jc` and the parsers (in JSON, of course!)
- `-d` debug mode. Prints trace messages if parsing issues encountered (use `-dd` for verbose debugging)
- `-d` debug mode. Prints trace messages if parsing issues are encountered (use `-dd` for verbose debugging)
- `-m` monochrome JSON output
- `-p` pretty format the JSON output
- `-q` quiet mode. Suppresses warning messages
- `-q` quiet mode. Suppresses parser warning messages
- `-r` raw output. Provides a more literal JSON output with all values as strings and no additional semantic processing
### Setting Custom Colors via Environment Variable

View File

@@ -1,6 +1,6 @@
# jc.parsers.iw_scan
jc - JSON CLI output utility `iw DEV scan` command output parser
jc - JSON CLI output utility `iw dev <device> scan` command output parser
This parser is considered beta quality. Not all fields are parsed.
@@ -132,7 +132,7 @@ Parameters:
Returns:
List of Dictionaries. Structured data with the following schema:
]
[
{
"foo": string/integer/float, # best guess based on value
"bar": string/integer/float,

View File

@@ -21,7 +21,7 @@ import jc.appdirs as appdirs
class info():
version = '1.14.1'
version = '1.14.2'
description = 'JSON CLI output utility'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -191,10 +191,10 @@ def set_env_colors(env_colors=None):
# Try the color set in the JC_COLORS env variable first. If it is set to default, then fall back to default colors
return {
Name.Tag: f'bold {PYGMENT_COLOR[color_list[0]]}' if not color_list[0] == 'default' else f"bold {PYGMENT_COLOR['blue']}", # key names
Keyword: PYGMENT_COLOR[color_list[1]] if not color_list[1] == 'default' else PYGMENT_COLOR['brightblack'], # true, false, null
Number: PYGMENT_COLOR[color_list[2]] if not color_list[2] == 'default' else PYGMENT_COLOR['magenta'], # numbers
String: PYGMENT_COLOR[color_list[3]] if not color_list[3] == 'default' else PYGMENT_COLOR['green'] # strings
Name.Tag: f'bold {PYGMENT_COLOR[color_list[0]]}' if color_list[0] != 'default' else f"bold {PYGMENT_COLOR['blue']}", # key names
Keyword: PYGMENT_COLOR[color_list[1]] if color_list[1] != 'default' else PYGMENT_COLOR['brightblack'], # true, false, null
Number: PYGMENT_COLOR[color_list[2]] if color_list[2] != 'default' else PYGMENT_COLOR['magenta'], # numbers
String: PYGMENT_COLOR[color_list[3]] if color_list[3] != 'default' else PYGMENT_COLOR['green'] # strings
}

View File

@@ -333,7 +333,7 @@ import jc.utils
class info():
version = '1.3'
version = '1.4'
description = 'dig command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -526,7 +526,11 @@ def parse_answer(answer):
answer_class = answer[2]
answer_type = answer[3]
answer_ttl = answer[1]
answer_data = answer[4]
answer_data = ' '.join(answer[4:])
# remove surrounding quotation marks from answer_data if they exist
if answer_data.startswith('"') and answer_data.endswith('"'):
answer_data = answer_data[1:-1]
return {'name': answer_name,
'class': answer_class,

View File

@@ -1,4 +1,4 @@
"""jc - JSON CLI output utility `iw DEV scan` command output parser
"""jc - JSON CLI output utility `iw dev <device> scan` command output parser
This parser is considered beta quality. Not all fields are parsed.
@@ -139,7 +139,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,

View File

@@ -5,7 +5,7 @@ with open('README.md', 'r') as f:
setuptools.setup(
name='jc',
version='1.14.1',
version='1.14.2',
author='Kelly Brazil',
author_email='kellyjonbrazil@gmail.com',
description='Converts the output of popular command-line tools and file-types to JSON.',

View File

@@ -0,0 +1 @@
[{"id": 26965, "opcode": "QUERY", "status": "NXDOMAIN", "flags": ["qr", "rd", "ra"], "query_num": 1, "answer_num": 0, "authority_num": 1, "additional_num": 1, "question": {"name": "x.y.z.w.bl.spamcop.net.", "class": "IN", "type": "TXT"}, "authority": [{"name": "bl.spamcop.net.", "class": "IN", "type": "SOA", "ttl": 0, "data": "bl.spamcop.net."}], "answer": [{"name": "x.y.z.w.bl.spamcop.net.", "class": "IN", "type": "TXT", "ttl": 2100, "data": "Blocked - see https://www.spamcop.net/bl.shtml?w.z.y.x"}], "query_time": 297, "server": "192.168.1.254#53(192.168.1.254)", "when": "Fri Feb 05 06:28:58 PST 2021", "rcvd": 104}]

View File

@@ -0,0 +1,23 @@
; <<>> DiG 9.10.6 <<>> TXT x.y.z.w.bl.spamcop.net
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 26965
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;x.y.z.w.bl.spamcop.net. IN TXT
;; AUTHORITY SECTION:
bl.spamcop.net. 0 IN SOA bl.spamcop.net. hostmaster.admin.spamcop.net. 1612535191 3600 1800 3600 0
;; ANSWER SECTION:
x.y.z.w.bl.spamcop.net. 2100 IN TXT "Blocked - see https://www.spamcop.net/bl.shtml?w.z.y.x"
;; Query time: 297 msec
;; SERVER: 192.168.1.254#53(192.168.1.254)
;; WHEN: Fri Feb 05 06:28:58 PST 2021
;; MSG SIZE rcvd: 104

View File

@@ -55,6 +55,9 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/dig-axfr.out'), 'r', encoding='utf-8') as f:
self.osx_10_14_6_dig_axfr = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/dig-answer-spaces.out'), 'r', encoding='utf-8') as f:
self.generic_dig_answer_spaces = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/dig.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_dig_json = json.loads(f.read())
@@ -101,6 +104,9 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/dig-axfr.json'), 'r', encoding='utf-8') as f:
self.osx_10_14_6_dig_axfr_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/dig-answer-spaces.json'), 'r', encoding='utf-8') as f:
self.generic_dig_answer_spaces_json = json.loads(f.read())
def test_dig_nodata(self):
"""
Test 'dig' with no data
@@ -197,6 +203,12 @@ class MyTests(unittest.TestCase):
"""
self.assertEqual(jc.parsers.dig.parse(self.osx_10_14_6_dig_axfr, quiet=True), self.osx_10_14_6_dig_axfr_json)
def test_dig_answer_spaces(self):
"""
Test 'dig' with spaces in the answer data (e.g. TXT responses)
"""
self.assertEqual(jc.parsers.dig.parse(self.generic_dig_answer_spaces, quiet=True), self.generic_dig_answer_spaces_json)
if __name__ == '__main__':
unittest.main()