diff --git a/jc/cli.py b/jc/cli.py index 6cdaa19a..4051b862 100644 --- a/jc/cli.py +++ b/jc/cli.py @@ -21,7 +21,7 @@ import jc.appdirs as appdirs class info(): - version = '1.14.2' + version = '1.14.3' description = 'JSON CLI output utility' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -51,6 +51,7 @@ parsers = [ 'gshadow', 'hash', 'hashsum', + 'hciconfig', 'history', 'hosts', 'id', diff --git a/jc/parsers/hciconfig.py b/jc/parsers/hciconfig.py new file mode 100644 index 00000000..7812c3e9 --- /dev/null +++ b/jc/parsers/hciconfig.py @@ -0,0 +1,142 @@ +"""jc - JSON CLI output utility `hciconfig` command output parser + +<> + +Usage (cli): + + $ hciconfig | jc --hciconfig + + or + + $ jc hciconfig + +Usage (module): + + import jc.parsers.hciconfig + result = jc.parsers.hciconfig.parse(hciconfig_command_output) + +Compatibility: + + 'linux' + +Examples: + + $ hciconfig | jc --hciconfig -p + [] + + $ hciconfig | jc --hciconfig -p -r + [] +""" +import jc.utils + + +class info(): + version = '1.0' + description = 'hciconfig command parser' + author = 'Kelly Brazil' + author_email = 'kellyjonbrazil@gmail.com' + # details = 'enter any other details here' + + # compatible options: linux, darwin, cygwin, win32, aix, freebsd + compatible = ['linux'] + magic_commands = ['hciconfig'] + + +__version__ = info.version + + +def process(proc_data): + """ + Final processing to conform to the schema. + + Parameters: + + proc_data: (List of Dictionaries) raw structured data to process + + Returns: + + List of Dictionaries. Structured data with the following schema: + + [ + { + "device": string, + "type": string, + "bus": string, + "bd_address": string, + "acl_mtu": integer, + "acl_mtu_packets": integer, + "sco_mtu": integer, + "sco_mtu_packets": integer, + "state": [ + string + ], + "rx_bytes": integer, + "rx_acl": integer, + "rx_sco": integer, + "rx_events": integer, + "rx_errors": integer, + "tx_bytes": integer, + "tx_acl": integer, + "tx_sco": integer, + "tx_commands": integer, + "tx_errors": integer, + "features": [ + string + ], + "packet_type": [ + string + ], + "link_policy": [ + string + ], + "link_mode": [ + string + ], + "name": string, + "class": string, + "service_classes": [ + string + ], + "device_class": string, + "hci_version": string, + "revision": string, + "lmp_version": string, + "subversion": string, + "manufacturer": string + } + ] + """ + + # rebuild output for added semantic information + 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: + + List of Dictionaries. Raw or processed structured data. + """ + if not quiet: + jc.utils.compatibility(__name__, info.compatible) + + raw_output = [] + + if jc.utils.has_data(data): + + for line in filter(None, data.splitlines()): + # parse the content + pass + + if raw: + return raw_output + else: + return process(raw_output) diff --git a/setup.py b/setup.py index 359da564..b87e486d 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open('README.md', 'r') as f: setuptools.setup( name='jc', - version='1.14.2', + version='1.14.3', author='Kelly Brazil', author_email='kellyjonbrazil@gmail.com', description='Converts the output of popular command-line tools and file-types to JSON.', diff --git a/tests/fixtures/centos-7.7/hciconfig-a.out b/tests/fixtures/centos-7.7/hciconfig-a.out new file mode 100644 index 00000000..7e841ea3 --- /dev/null +++ b/tests/fixtures/centos-7.7/hciconfig-a.out @@ -0,0 +1,10 @@ +hci0: Type: Primary Bus: USB + BD Address: 00:50:56:FE:FD:38 ACL MTU: 8192:128 SCO MTU: 64:128 + DOWN + RX bytes:503 acl:0 sco:0 events:22 errors:0 + TX bytes:336 acl:0 sco:0 commands:22 errors:0 + Features: 0xff 0xff 0x8f 0xfe 0x83 0xe1 0x08 0x80 + Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 + Link policy: RSWITCH HOLD SNIFF PARK + Link mode: SLAVE ACCEPT + diff --git a/tests/fixtures/centos-7.7/hciconfig.out b/tests/fixtures/centos-7.7/hciconfig.out new file mode 100644 index 00000000..d018dc8b --- /dev/null +++ b/tests/fixtures/centos-7.7/hciconfig.out @@ -0,0 +1,6 @@ +hci0: Type: Primary Bus: USB + BD Address: 00:50:56:FE:FD:38 ACL MTU: 8192:128 SCO MTU: 64:128 + DOWN + RX bytes:503 acl:0 sco:0 events:22 errors:0 + TX bytes:336 acl:0 sco:0 commands:22 errors:0 + diff --git a/tests/fixtures/ubuntu-20.04/hciconfig-a.out b/tests/fixtures/ubuntu-20.04/hciconfig-a.out new file mode 100644 index 00000000..599a213a --- /dev/null +++ b/tests/fixtures/ubuntu-20.04/hciconfig-a.out @@ -0,0 +1,27 @@ +hci0: Type: Primary Bus: USB + BD Address: 00:1A:7D:DA:71:13 ACL MTU: 310:10 SCO MTU: 64:8 + UP RUNNING + RX bytes:13905869 acl:0 sco:0 events:393300 errors:0 + TX bytes:62629 acl:0 sco:0 commands:3893 errors:0 + Features: 0xff 0xff 0x8f 0xfe 0xdb 0xff 0x5b 0x87 + Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 + Link policy: RSWITCH HOLD SNIFF PARK + Link mode: SLAVE ACCEPT + Name: 'CSR8510 A10' + Class: 0x000000 + Service Classes: Unspecified + Device Class: Miscellaneous, + HCI Version: 4.0 (0x6) Revision: 0x22bb + LMP Version: 4.0 (0x6) Subversion: 0x22bb + Manufacturer: Cambridge Silicon Radio (10) + +hci1: Type: Primary Bus: USB + BD Address: 00:1A:7D:DA:71:13 ACL MTU: 310:10 SCO MTU: 64:8 + DOWN + RX bytes:4388363 acl:0 sco:0 events:122021 errors:0 + TX bytes:52350 acl:0 sco:0 commands:3480 errors:2 + Features: 0xff 0xff 0x8f 0xfe 0xdb 0xff 0x5b 0x87 + Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 + Link policy: RSWITCH HOLD SNIFF PARK + Link mode: SLAVE ACCEPT + diff --git a/tests/fixtures/ubuntu-20.04/hciconfig.out b/tests/fixtures/ubuntu-20.04/hciconfig.out new file mode 100644 index 00000000..ce9a033a --- /dev/null +++ b/tests/fixtures/ubuntu-20.04/hciconfig.out @@ -0,0 +1,17 @@ +hci0: Type: Primary Bus: USB + BD Address: 00:50:56:E7:46:1A ACL MTU: 8192:128 SCO MTU: 64:128 + UP RUNNING + RX bytes:1307 acl:0 sco:0 events:51 errors:0 + TX bytes:1200 acl:0 sco:0 commands:51 errors:0 + Features: 0xff 0xff 0x8f 0xfe 0x83 0xe1 0x08 0x80 + Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 + Link policy: RSWITCH HOLD SNIFF PARK + Link mode: SLAVE ACCEPT + Name: 'kbrazil-ubuntu' + Class: 0x000000 + Service Classes: Unspecified + Device Class: Miscellaneous, + HCI Version: 2.1 (0x4) Revision: 0x100 + LMP Version: 2.1 (0x4) Subversion: 0x100 + Manufacturer: not assigned (6502) +