From 4dda895f122ecc19b267ed1485cf656bae76ff07 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 24 Feb 2022 11:25:14 -0800 Subject: [PATCH 01/38] initial nmcli parser --- jc/lib.py | 1 + jc/parsers/nmcli.py | 130 +++++++++++++++++ .../centos-7.7/nmcli-connection-all.out | 3 + .../nmcli-connection-show-ens33.out | 136 ++++++++++++++++++ .../fixtures/centos-7.7/nmcli-connection.out | 3 + .../fixtures/centos-7.7/nmcli-device-all.out | 5 + .../centos-7.7/nmcli-device-show-ens33.out | 18 +++ .../centos-7.7/nmcli-device-show-lo.out | 12 ++ .../fixtures/centos-7.7/nmcli-device-show.out | 42 ++++++ tests/fixtures/centos-7.7/nmcli-device.out | 4 + .../fixtures/centos-7.7/nmcli-general-all.out | 3 + .../centos-7.7/nmcli-general-permissions.out | 18 +++ tests/fixtures/centos-7.7/nmcli.out | 29 ++++ 13 files changed, 404 insertions(+) create mode 100644 jc/parsers/nmcli.py create mode 100644 tests/fixtures/centos-7.7/nmcli-connection-all.out create mode 100644 tests/fixtures/centos-7.7/nmcli-connection-show-ens33.out create mode 100644 tests/fixtures/centos-7.7/nmcli-connection.out create mode 100644 tests/fixtures/centos-7.7/nmcli-device-all.out create mode 100644 tests/fixtures/centos-7.7/nmcli-device-show-ens33.out create mode 100644 tests/fixtures/centos-7.7/nmcli-device-show-lo.out create mode 100644 tests/fixtures/centos-7.7/nmcli-device-show.out create mode 100644 tests/fixtures/centos-7.7/nmcli-device.out create mode 100644 tests/fixtures/centos-7.7/nmcli-general-all.out create mode 100644 tests/fixtures/centos-7.7/nmcli-general-permissions.out create mode 100644 tests/fixtures/centos-7.7/nmcli.out diff --git a/jc/lib.py b/jc/lib.py index bbf3a43b..6fe8311e 100644 --- a/jc/lib.py +++ b/jc/lib.py @@ -60,6 +60,7 @@ parsers = [ 'lsusb', 'mount', 'netstat', + 'nmcli', 'ntpq', 'passwd', 'ping', diff --git a/jc/parsers/nmcli.py b/jc/parsers/nmcli.py new file mode 100644 index 00000000..504b6d43 --- /dev/null +++ b/jc/parsers/nmcli.py @@ -0,0 +1,130 @@ +"""jc - JSON CLI output utility `nmcli` command output parser + +<> + +Usage (cli): + + $ nmcli | jc --nmcli + + or + + $ jc nmcli + +Usage (module): + + import jc + result = jc.parse('nmcli', nmcli_command_output) + + or + + import jc.parsers.nmcli + result = jc.parsers.nmcli.parse(nmcli_command_output) + +Schema: + + [ + { + "nmcli": string, + "bar": boolean, + "baz": integer + } + ] + +Examples: + + $ nmcli | jc --nmcli -p + [] + + $ nmcli | jc --nmcli -p -r + [] +""" +from typing import List, Dict +import jc.utils + + +class info(): + """Provides parser metadata (version, author, etc.)""" + version = '1.0' + description = '`nmcli` command parser' + author = 'Kelly Brazil' + author_email = 'kellyjonbrazil@gmail.com' + compatible = ['linux'] + magic_commands = ['nmcli'] + + +__version__ = info.version + + +def _process(proc_data: List[Dict]) -> List[Dict]: + """ + Final processing to conform to the schema. + + Parameters: + + proc_data: (List of Dictionaries) raw structured data to process + + Returns: + + List of Dictionaries. Structured to conform to the schema. + """ + + # process the data here + # rebuild output for added semantic information + # use helper functions in jc.utils for int, float, bool + # conversions and timestamps + + return proc_data + +def _normalize_key(keyname: str) -> str: + return keyname.replace(' ', '_')\ + .replace('.', '_')\ + .replace('[', '_')\ + .replace(']', '')\ + .replace('-', '_')\ + .replace('GENERAL_', '')\ + .lower() + + +def parse( + data: str, + raw: bool = False, + quiet: bool = False +) -> List[Dict]: + """ + Main text parsing function + + Parameters: + + data: (string) text data to parse + raw: (boolean) unprocessed output if True + quiet: (boolean) suppress warning messages if True + + Returns: + + List of Dictionaries. Raw or processed structured data. + """ + jc.utils.compatibility(__name__, info.compatible, quiet) + jc.utils.input_type_check(data) + + raw_output: List = [] + item: Dict = {} + current_item = '' + + if jc.utils.has_data(data): + + for line in filter(None, data.splitlines()): + key, value = line.split(':', maxsplit=1) + key = _normalize_key(key) + value = value.strip() + + if item and 'device' in key and value != current_item: + raw_output.append(item) + item = {} + current_item = value + + item.update({key: value}) + + if item: + raw_output.append(item) + + return raw_output if raw else _process(raw_output) diff --git a/tests/fixtures/centos-7.7/nmcli-connection-all.out b/tests/fixtures/centos-7.7/nmcli-connection-all.out new file mode 100644 index 00000000..e2b771e0 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-connection-all.out @@ -0,0 +1,3 @@ +NAME UUID TYPE TIMESTAMP TIMESTAMP-REAL AUTOCONNECT AUTOCONNECT-PRIORITY READONLY DBUS-PATH ACTIVE DEVICE STATE ACTIVE-PATH SLAVE FILENAME +ens33 d92ece08-9e02-47d5-b2d2-92c80e155744 ethernet 1645643581 Wed 23 Feb 2022 11:13:01 AM PST yes 0 no /org/freedesktop/NetworkManager/Settings/1 yes ens33 activated /org/freedesktop/NetworkManager/ActiveConnection/1 -- /etc/sysconfig/network-scripts/ifcfg-ens33 + diff --git a/tests/fixtures/centos-7.7/nmcli-connection-show-ens33.out b/tests/fixtures/centos-7.7/nmcli-connection-show-ens33.out new file mode 100644 index 00000000..868e8c0f --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-connection-show-ens33.out @@ -0,0 +1,136 @@ +connection.id: ens33 +connection.uuid: d92ece08-9e02-47d5-b2d2-92c80e155744 +connection.stable-id: -- +connection.type: 802-3-ethernet +connection.interface-name: ens33 +connection.autoconnect: yes +connection.autoconnect-priority: 0 +connection.autoconnect-retries: -1 (default) +connection.multi-connect: 0 (default) +connection.auth-retries: -1 +connection.timestamp: 1645570618 +connection.read-only: no +connection.permissions: -- +connection.zone: -- +connection.master: -- +connection.slave-type: -- +connection.autoconnect-slaves: -1 (default) +connection.secondaries: -- +connection.gateway-ping-timeout: 0 +connection.metered: unknown +connection.lldp: default +connection.mdns: -1 (default) +connection.llmnr: -1 (default) +802-3-ethernet.port: -- +802-3-ethernet.speed: 0 +802-3-ethernet.duplex: -- +802-3-ethernet.auto-negotiate: no +802-3-ethernet.mac-address: -- +802-3-ethernet.cloned-mac-address: -- +802-3-ethernet.generate-mac-address-mask:-- +802-3-ethernet.mac-address-blacklist: -- +802-3-ethernet.mtu: auto +802-3-ethernet.s390-subchannels: -- +802-3-ethernet.s390-nettype: -- +802-3-ethernet.s390-options: -- +802-3-ethernet.wake-on-lan: default +802-3-ethernet.wake-on-lan-password: -- +ipv4.method: auto +ipv4.dns: -- +ipv4.dns-search: -- +ipv4.dns-options: "" +ipv4.dns-priority: 0 +ipv4.addresses: -- +ipv4.gateway: -- +ipv4.routes: -- +ipv4.route-metric: -1 +ipv4.route-table: 0 (unspec) +ipv4.routing-rules: -- +ipv4.ignore-auto-routes: no +ipv4.ignore-auto-dns: no +ipv4.dhcp-client-id: -- +ipv4.dhcp-timeout: 0 (default) +ipv4.dhcp-send-hostname: yes +ipv4.dhcp-hostname: -- +ipv4.dhcp-fqdn: -- +ipv4.never-default: no +ipv4.may-fail: yes +ipv4.dad-timeout: -1 (default) +ipv6.method: auto +ipv6.dns: -- +ipv6.dns-search: -- +ipv6.dns-options: "" +ipv6.dns-priority: 0 +ipv6.addresses: -- +ipv6.gateway: -- +ipv6.routes: -- +ipv6.route-metric: -1 +ipv6.route-table: 0 (unspec) +ipv6.routing-rules: -- +ipv6.ignore-auto-routes: no +ipv6.ignore-auto-dns: no +ipv6.never-default: no +ipv6.may-fail: yes +ipv6.ip6-privacy: -1 (unknown) +ipv6.addr-gen-mode: stable-privacy +ipv6.dhcp-duid: -- +ipv6.dhcp-send-hostname: yes +ipv6.dhcp-hostname: -- +ipv6.token: -- +proxy.method: none +proxy.browser-only: no +proxy.pac-url: -- +proxy.pac-script: -- +GENERAL.NAME: ens33 +GENERAL.UUID: d92ece08-9e02-47d5-b2d2-92c80e155744 +GENERAL.DEVICES: ens33 +GENERAL.STATE: activated +GENERAL.DEFAULT: yes +GENERAL.DEFAULT6: no +GENERAL.SPEC-OBJECT: -- +GENERAL.VPN: no +GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/1 +GENERAL.ZONE: -- +GENERAL.MASTER-PATH: -- +IP4.ADDRESS[1]: 192.168.71.180/24 +IP4.GATEWAY: 192.168.71.2 +IP4.ROUTE[1]: dst = 0.0.0.0/0, nh = 192.168.71.2, mt = 100 +IP4.ROUTE[2]: dst = 192.168.71.0/24, nh = 0.0.0.0, mt = 100 +IP4.DNS[1]: 192.168.71.2 +IP4.DOMAIN[1]: localdomain +DHCP4.OPTION[1]: broadcast_address = 192.168.71.255 +DHCP4.OPTION[2]: dhcp_lease_time = 1800 +DHCP4.OPTION[3]: dhcp_message_type = 5 +DHCP4.OPTION[4]: dhcp_server_identifier = 192.168.71.254 +DHCP4.OPTION[5]: domain_name = localdomain +DHCP4.OPTION[6]: domain_name_servers = 192.168.71.2 +DHCP4.OPTION[7]: expiry = 1645572241 +DHCP4.OPTION[8]: ip_address = 192.168.71.180 +DHCP4.OPTION[9]: network_number = 192.168.71.0 +DHCP4.OPTION[10]: next_server = 192.168.71.254 +DHCP4.OPTION[11]: requested_broadcast_address = 1 +DHCP4.OPTION[12]: requested_classless_static_routes = 1 +DHCP4.OPTION[13]: requested_domain_name = 1 +DHCP4.OPTION[14]: requested_domain_name_servers = 1 +DHCP4.OPTION[15]: requested_domain_search = 1 +DHCP4.OPTION[16]: requested_host_name = 1 +DHCP4.OPTION[17]: requested_interface_mtu = 1 +DHCP4.OPTION[18]: requested_ms_classless_static_routes = 1 +DHCP4.OPTION[19]: requested_nis_domain = 1 +DHCP4.OPTION[20]: requested_nis_servers = 1 +DHCP4.OPTION[21]: requested_ntp_servers = 1 +DHCP4.OPTION[22]: requested_rfc3442_classless_static_routes = 1 +DHCP4.OPTION[23]: requested_root_path = 1 +DHCP4.OPTION[24]: requested_routers = 1 +DHCP4.OPTION[25]: requested_static_routes = 1 +DHCP4.OPTION[26]: requested_subnet_mask = 1 +DHCP4.OPTION[27]: requested_time_offset = 1 +DHCP4.OPTION[28]: requested_wpad = 1 +DHCP4.OPTION[29]: routers = 192.168.71.2 +DHCP4.OPTION[30]: subnet_mask = 255.255.255.0 +IP6.ADDRESS[1]: fe80::c1cb:715d:bc3e:b8a0/64 +IP6.GATEWAY: -- +IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 100 +IP6.ROUTE[2]: dst = ff00::/8, nh = ::, mt = 256, table=255 + diff --git a/tests/fixtures/centos-7.7/nmcli-connection.out b/tests/fixtures/centos-7.7/nmcli-connection.out new file mode 100644 index 00000000..c1b5bf7c --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-connection.out @@ -0,0 +1,3 @@ +NAME UUID TYPE DEVICE +ens33 d92ece08-9e02-47d5-b2d2-92c80e155744 ethernet ens33 + diff --git a/tests/fixtures/centos-7.7/nmcli-device-all.out b/tests/fixtures/centos-7.7/nmcli-device-all.out new file mode 100644 index 00000000..2884f28f --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-device-all.out @@ -0,0 +1,5 @@ +DEVICE TYPE STATE IP4-CONNECTIVITY IP6-CONNECTIVITY DBUS-PATH CONNECTION CON-UUID CON-PATH +ens33 ethernet connected full full /org/freedesktop/NetworkManager/Devices/2 ens33 d92ece08-9e02-47d5-b2d2-92c80e155744 /org/freedesktop/NetworkManager/ActiveConnection/1 +docker0 bridge unmanaged unknown unknown /org/freedesktop/NetworkManager/Devices/3 -- -- -- +lo loopback unmanaged unknown unknown /org/freedesktop/NetworkManager/Devices/1 -- -- -- + diff --git a/tests/fixtures/centos-7.7/nmcli-device-show-ens33.out b/tests/fixtures/centos-7.7/nmcli-device-show-ens33.out new file mode 100644 index 00000000..9ded86e8 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-device-show-ens33.out @@ -0,0 +1,18 @@ +GENERAL.DEVICE: ens33 +GENERAL.TYPE: ethernet +GENERAL.HWADDR: 00:0C:29:3B:58:0E +GENERAL.MTU: 1500 +GENERAL.STATE: 100 (connected) +GENERAL.CONNECTION: ens33 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 +WIRED-PROPERTIES.CARRIER: on +IP4.ADDRESS[1]: 192.168.71.180/24 +IP4.GATEWAY: 192.168.71.2 +IP4.ROUTE[1]: dst = 0.0.0.0/0, nh = 192.168.71.2, mt = 100 +IP4.ROUTE[2]: dst = 192.168.71.0/24, nh = 0.0.0.0, mt = 100 +IP4.DNS[1]: 192.168.71.2 +IP4.DOMAIN[1]: localdomain +IP6.ADDRESS[1]: fe80::c1cb:715d:bc3e:b8a0/64 +IP6.GATEWAY: -- +IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 100 +IP6.ROUTE[2]: dst = ff00::/8, nh = ::, mt = 256, table=255 diff --git a/tests/fixtures/centos-7.7/nmcli-device-show-lo.out b/tests/fixtures/centos-7.7/nmcli-device-show-lo.out new file mode 100644 index 00000000..4214f760 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-device-show-lo.out @@ -0,0 +1,12 @@ +GENERAL.DEVICE: lo +GENERAL.TYPE: loopback +GENERAL.HWADDR: 00:00:00:00:00:00 +GENERAL.MTU: 65536 +GENERAL.STATE: 10 (unmanaged) +GENERAL.CONNECTION: -- +GENERAL.CON-PATH: -- +IP4.ADDRESS[1]: 127.0.0.1/8 +IP4.GATEWAY: -- +IP6.ADDRESS[1]: ::1/128 +IP6.GATEWAY: -- + diff --git a/tests/fixtures/centos-7.7/nmcli-device-show.out b/tests/fixtures/centos-7.7/nmcli-device-show.out new file mode 100644 index 00000000..8aec04bd --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-device-show.out @@ -0,0 +1,42 @@ +GENERAL.DEVICE: ens33 +GENERAL.TYPE: ethernet +GENERAL.HWADDR: 00:0C:29:3B:58:0E +GENERAL.MTU: 1500 +GENERAL.STATE: 100 (connected) +GENERAL.CONNECTION: ens33 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 +WIRED-PROPERTIES.CARRIER: on +IP4.ADDRESS[1]: 192.168.71.180/24 +IP4.GATEWAY: 192.168.71.2 +IP4.ROUTE[1]: dst = 0.0.0.0/0, nh = 192.168.71.2, mt = 100 +IP4.ROUTE[2]: dst = 192.168.71.0/24, nh = 0.0.0.0, mt = 100 +IP4.DNS[1]: 192.168.71.2 +IP4.DOMAIN[1]: localdomain +IP6.ADDRESS[1]: fe80::c1cb:715d:bc3e:b8a0/64 +IP6.GATEWAY: -- +IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 100 +IP6.ROUTE[2]: dst = ff00::/8, nh = ::, mt = 256, table=255 + +GENERAL.DEVICE: docker0 +GENERAL.TYPE: bridge +GENERAL.HWADDR: 02:42:99:67:E8:21 +GENERAL.MTU: 1500 +GENERAL.STATE: 10 (unmanaged) +GENERAL.CONNECTION: -- +GENERAL.CON-PATH: -- +IP4.ADDRESS[1]: 172.17.0.1/16 +IP4.GATEWAY: -- +IP4.ROUTE[1]: dst = 172.17.0.0/16, nh = 0.0.0.0, mt = 0 +IP6.GATEWAY: -- + +GENERAL.DEVICE: lo +GENERAL.TYPE: loopback +GENERAL.HWADDR: 00:00:00:00:00:00 +GENERAL.MTU: 65536 +GENERAL.STATE: 10 (unmanaged) +GENERAL.CONNECTION: -- +GENERAL.CON-PATH: -- +IP4.ADDRESS[1]: 127.0.0.1/8 +IP4.GATEWAY: -- +IP6.ADDRESS[1]: ::1/128 +IP6.GATEWAY: -- diff --git a/tests/fixtures/centos-7.7/nmcli-device.out b/tests/fixtures/centos-7.7/nmcli-device.out new file mode 100644 index 00000000..b5e73778 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-device.out @@ -0,0 +1,4 @@ +DEVICE TYPE STATE CONNECTION +ens33 ethernet connected ens33 +docker0 bridge unmanaged -- +lo loopback unmanaged -- diff --git a/tests/fixtures/centos-7.7/nmcli-general-all.out b/tests/fixtures/centos-7.7/nmcli-general-all.out new file mode 100644 index 00000000..18cac50b --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-general-all.out @@ -0,0 +1,3 @@ +RUNNING VERSION STATE STARTUP CONNECTIVITY NETWORKING WIFI-HW WIFI WWAN-HW WWAN +running 1.18.0 connected started full enabled enabled enabled enabled enabled + diff --git a/tests/fixtures/centos-7.7/nmcli-general-permissions.out b/tests/fixtures/centos-7.7/nmcli-general-permissions.out new file mode 100644 index 00000000..c1e94e0b --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-general-permissions.out @@ -0,0 +1,18 @@ +PERMISSION VALUE +org.freedesktop.NetworkManager.enable-disable-network yes +org.freedesktop.NetworkManager.enable-disable-wifi yes +org.freedesktop.NetworkManager.enable-disable-wwan yes +org.freedesktop.NetworkManager.enable-disable-wimax yes +org.freedesktop.NetworkManager.sleep-wake yes +org.freedesktop.NetworkManager.network-control yes +org.freedesktop.NetworkManager.wifi.share.protected yes +org.freedesktop.NetworkManager.wifi.share.open yes +org.freedesktop.NetworkManager.settings.modify.system yes +org.freedesktop.NetworkManager.settings.modify.own yes +org.freedesktop.NetworkManager.settings.modify.hostname yes +org.freedesktop.NetworkManager.settings.modify.global-dns yes +org.freedesktop.NetworkManager.reload yes +org.freedesktop.NetworkManager.checkpoint-rollback yes +org.freedesktop.NetworkManager.enable-disable-statistics yes +org.freedesktop.NetworkManager.enable-disable-connectivity-check yes +org.freedesktop.NetworkManager.wifi.scan unknown diff --git a/tests/fixtures/centos-7.7/nmcli.out b/tests/fixtures/centos-7.7/nmcli.out new file mode 100644 index 00000000..1ac1c16b --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli.out @@ -0,0 +1,29 @@ +ens33: connected to ens33 + "Intel 82545EM" + ethernet (e1000), 00:0C:29:3B:58:0E, hw, mtu 1500 + ip4 default + inet4 192.168.71.181/24 + route4 0.0.0.0/0 + route4 192.168.71.0/24 + inet6 fe80::c1cb:715d:bc3e:b8a0/64 + route6 fe80::/64 + route6 ff00::/8 + +docker0: unmanaged + "docker0" + bridge, 02:42:76:3F:0D:C3, sw, mtu 1500 + +lo: unmanaged + "lo" + loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536 + +DNS configuration: + servers: 192.168.71.2 + domains: localdomain + interface: ens33 + +Use "nmcli device show" to get complete information about known devices and +"nmcli connection show" to get an overview on active connection profiles. + +Consult nmcli(1) and nmcli-examples(7) manual pages for complete usage details. + From 2d6f666fa4c791e7995f6b0c1490dac73ce224c3 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 24 Feb 2022 12:21:13 -0800 Subject: [PATCH 02/38] add dev show and conn show parsers --- jc/parsers/nmcli.py | 77 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 16 deletions(-) diff --git a/jc/parsers/nmcli.py b/jc/parsers/nmcli.py index 504b6d43..11ac8eca 100644 --- a/jc/parsers/nmcli.py +++ b/jc/parsers/nmcli.py @@ -38,7 +38,7 @@ Examples: $ nmcli | jc --nmcli -p -r [] """ -from typing import List, Dict +from typing import List, Dict, Optional import jc.utils @@ -84,6 +84,59 @@ def _normalize_key(keyname: str) -> str: .replace('GENERAL_', '')\ .lower() +def _normalize_value(value: str) -> Optional[str]: + value = value.strip() + + if value == '""': + value = '' + + if value == '--': + return None + + return value + + + +def _device_show_parse(data: str) -> List[Dict]: + raw_output: List = [] + item: Dict = {} + current_item = '' + + for line in filter(None, data.splitlines()): + key, value = line.split(':', maxsplit=1) + key_n = _normalize_key(key) + value_n = _normalize_value(value) + + if item and 'device' in key_n and value_n != current_item: + raw_output.append(item) + item = {} + current_item = value + + item.update({key_n: value_n}) + + # get final item + if item: + raw_output.append(item) + + return raw_output + + +def _connection_show_x_parse(data: str) -> List[Dict]: + raw_output: List = [] + item: Dict = {} + + for line in filter(None, data.splitlines()): + key, value = line.split(':', maxsplit=1) + + key_n = _normalize_key(key) + value_n = _normalize_value(value) + item.update({key_n: value_n}) + + if item: + raw_output.append(item) + + return raw_output + def parse( data: str, @@ -107,24 +160,16 @@ def parse( jc.utils.input_type_check(data) raw_output: List = [] - item: Dict = {} - current_item = '' if jc.utils.has_data(data): - for line in filter(None, data.splitlines()): - key, value = line.split(':', maxsplit=1) - key = _normalize_key(key) - value = value.strip() + # nmcli device show + # nmcli device show lo + if data.startswith('GENERAL.DEVICE'): + raw_output = _device_show_parse(data) - if item and 'device' in key and value != current_item: - raw_output.append(item) - item = {} - current_item = value - - item.update({key: value}) - - if item: - raw_output.append(item) + # nmcli connection show lo + elif data.startswith('connection.id:'): + raw_output = _connection_show_x_parse(data) return raw_output if raw else _process(raw_output) From 3d01356461eb2790f859968da7f5cb4fd2ee9898 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 24 Feb 2022 14:53:26 -0800 Subject: [PATCH 03/38] add text_kv function --- jc/parsers/nmcli.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/jc/parsers/nmcli.py b/jc/parsers/nmcli.py index 11ac8eca..f08e124c 100644 --- a/jc/parsers/nmcli.py +++ b/jc/parsers/nmcli.py @@ -38,6 +38,7 @@ Examples: $ nmcli | jc --nmcli -p -r [] """ +import re from typing import List, Dict, Optional import jc.utils @@ -87,15 +88,30 @@ def _normalize_key(keyname: str) -> str: def _normalize_value(value: str) -> Optional[str]: value = value.strip() - if value == '""': - value = '' - if value == '--': return None + if value.startswith('"') and value.endswith('"'): + value = value.strip('"') + return value +def _add_text_kv(key: str, value: str) -> Optional[Dict]: + """ + Add keys with _text suffix if there is a text description inside + paranthesis at the end of a value. The value of the _text field will + only be the text inside the parenthesis. This allows cleanup of the + original field (convert to int/float/etc) without losing information. + """ + if value and '(' in value and value.endswith(')'): + new_val = re.search(r'\((\w+)\)$', value) + if new_val: + return ({key + '_text': new_val.group(1)}) + + return None + + def _device_show_parse(data: str) -> List[Dict]: raw_output: List = [] @@ -114,6 +130,10 @@ def _device_show_parse(data: str) -> List[Dict]: item.update({key_n: value_n}) + text_kv = _add_text_kv(key_n, value_n) + if text_kv: + item.update(text_kv) + # get final item if item: raw_output.append(item) @@ -132,6 +152,10 @@ def _connection_show_x_parse(data: str) -> List[Dict]: value_n = _normalize_value(value) item.update({key_n: value_n}) + text_kv = _add_text_kv(key_n, value_n) + if text_kv: + item.update(text_kv) + if item: raw_output.append(item) From 19dcef513565c34a31f6d735577da5e25f9bd2cd Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 24 Feb 2022 17:10:39 -0800 Subject: [PATCH 04/38] firm up flow. add/remove text. parse routes --- jc/parsers/nmcli.py | 71 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/jc/parsers/nmcli.py b/jc/parsers/nmcli.py index f08e124c..d3c1ce80 100644 --- a/jc/parsers/nmcli.py +++ b/jc/parsers/nmcli.py @@ -41,6 +41,7 @@ Examples: import re from typing import List, Dict, Optional import jc.utils +from jc.parsers.universal import sparse_table_parse class info(): @@ -97,7 +98,15 @@ def _normalize_value(value: str) -> Optional[str]: return value -def _add_text_kv(key: str, value: str) -> Optional[Dict]: +def _normalize_header(keyname: str) -> str: + return keyname.replace('.', '_')\ + .replace('[', '_')\ + .replace(']', ' ')\ + .replace('-', '_')\ + .lower() + + +def _add_text_kv(key: str, value: Optional[str]) -> Optional[Dict]: """ Add keys with _text suffix if there is a text description inside paranthesis at the end of a value. The value of the _text field will @@ -112,6 +121,28 @@ def _add_text_kv(key: str, value: str) -> Optional[Dict]: return None +def _remove_text_from_value(value: Optional[str]) -> Optional[str]: + """ + Remove the text summary part of a value. Used when an extra text + summary k/v pair are added. + """ + if value: + return re.sub(r"\s+\((\w+)\)$", '', value) + + return None + + +def _split_routes(value: str) -> Dict: + # dst = 192.168.71.0/24, nh = 0.0.0.0, mt = 100 + # dst = ff00::/8, nh = ::, mt = 256, table=255 + output_dict = {} + val_list = value.split(',') + for val in val_list: + k, v = val.split('=') + output_dict[k.strip()] = v.strip() + + return output_dict + def _device_show_parse(data: str) -> List[Dict]: raw_output: List = [] @@ -132,6 +163,7 @@ def _device_show_parse(data: str) -> List[Dict]: text_kv = _add_text_kv(key_n, value_n) if text_kv: + item[key_n] = _remove_text_from_value(value_n) item.update(text_kv) # get final item @@ -154,14 +186,35 @@ def _connection_show_x_parse(data: str) -> List[Dict]: text_kv = _add_text_kv(key_n, value_n) if text_kv: + item[key_n] = _remove_text_from_value(value_n) item.update(text_kv) + if '_route_' in key_n and key_n[-1].isdigit(): + item[key_n] = _split_routes(item[key_n]) + + if item: raw_output.append(item) return raw_output +def _general_permissions_parse(data: str) -> List[Dict]: + print('general permissions') + + +def _table_parse(data: str) -> List[Dict]: + data_list = list(filter(None, data.splitlines())) + data_list[0] = _normalize_header(data_list[0]) + raw_output = sparse_table_parse(data_list) + + for item in raw_output: + for key in item: + item[key] = _normalize_value(item[key]) + + return raw_output + + def parse( data: str, raw: bool = False, @@ -187,13 +240,27 @@ def parse( if jc.utils.has_data(data): + # nmcli (second line startswith \t) + if data.splitlines()[1].startswith('\t'): + print('nmcli only') + # nmcli device show # nmcli device show lo - if data.startswith('GENERAL.DEVICE'): + elif data.startswith('GENERAL.DEVICE'): raw_output = _device_show_parse(data) # nmcli connection show lo elif data.startswith('connection.id:'): raw_output = _connection_show_x_parse(data) + # nmcli general permissions (k/v pairs) + elif data.startswith('PERMISSION '): + raw_output = _general_permissions_parse(data) + + # nmcli general + # nmcli connection + # nmcli device + else: + raw_output = _table_parse(data) + return raw_output if raw else _process(raw_output) From 937fa5aad2519f588c6d0feb8f08211f6b99872f Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 24 Feb 2022 18:22:19 -0800 Subject: [PATCH 05/38] split dhcp options --- jc/parsers/nmcli.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/jc/parsers/nmcli.py b/jc/parsers/nmcli.py index d3c1ce80..1614299b 100644 --- a/jc/parsers/nmcli.py +++ b/jc/parsers/nmcli.py @@ -144,6 +144,17 @@ def _split_routes(value: str) -> Dict: return output_dict +def _split_options(value: str) -> Dict: + # ip_address = 192.168.71.180 + # requested_broadcast_address = 1 + output_dict = {} + k, v = value.split('=') + output_dict['name'] = k.strip() + output_dict['value'] = v.strip() + + return output_dict + + def _device_show_parse(data: str) -> List[Dict]: raw_output: List = [] item: Dict = {} @@ -166,6 +177,12 @@ def _device_show_parse(data: str) -> List[Dict]: item[key_n] = _remove_text_from_value(value_n) item.update(text_kv) + if '_option_' in key_n and key_n[-1].isdigit(): + item[key_n] = _split_options(item[key_n]) + + if '_route_' in key_n and key_n[-1].isdigit(): + item[key_n] = _split_routes(item[key_n]) + # get final item if item: raw_output.append(item) @@ -189,6 +206,9 @@ def _connection_show_x_parse(data: str) -> List[Dict]: item[key_n] = _remove_text_from_value(value_n) item.update(text_kv) + if '_option_' in key_n and key_n[-1].isdigit(): + item[key_n] = _split_options(item[key_n]) + if '_route_' in key_n and key_n[-1].isdigit(): item[key_n] = _split_routes(item[key_n]) From 7f409b7082aa9525cc9280e3c5c92bc82089cf14 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 24 Feb 2022 20:31:09 -0800 Subject: [PATCH 06/38] enhance ParseError cli message --- jc/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jc/cli.py b/jc/cli.py index f1fd5660..e4b15516 100644 --- a/jc/cli.py +++ b/jc/cli.py @@ -539,7 +539,7 @@ def main(): utils.error_message([ f'Parser issue with {parser_name}:', f'{e.__class__.__name__}: {e}', 'If this is the correct parser, try setting the locale to C (LANG=C).', - 'For details use the -d or -dd option. Use "jc -h" for help.' + f'For details use the -d or -dd option. Use "jc -h --{parser_name}" for help.' ]) sys.exit(combined_exit_code(magic_exit_code, JC_ERROR_EXIT)) From f4d11d697e000135720a971edf84dcad31a1bec8 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 24 Feb 2022 20:31:58 -0800 Subject: [PATCH 07/38] finish use cases and doc --- jc/parsers/nmcli.py | 170 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 155 insertions(+), 15 deletions(-) diff --git a/jc/parsers/nmcli.py b/jc/parsers/nmcli.py index 1614299b..dadff717 100644 --- a/jc/parsers/nmcli.py +++ b/jc/parsers/nmcli.py @@ -1,14 +1,21 @@ """jc - JSON CLI output utility `nmcli` command output parser -<> +Supports the following `nmcli` subcommands: +- `nmcli general` +- `nmcli general permissions` +- `nmcli connection` +- `nmcli connection show ` +- `nmcli device` +- `nmcli device show` +- `nmcli device show ` Usage (cli): - $ nmcli | jc --nmcli + $ nmcli device show lo | jc --nmcli or - $ jc nmcli + $ jc nmcli device show lo Usage (module): @@ -22,26 +29,123 @@ Usage (module): Schema: + Because there are so many options, the schema is best effort. Integer + and Float value conversions are attempted and the original values are + kept if they fail. If you don't want automatic conversion, then use the + -r or raw=True option to disable it. + + The structure is flat, for the most part, but there are a couple of + "well-known" keys that are further parsed into objects for convenience. + These are documented below. + [ { - "nmcli": string, - "bar": boolean, - "baz": integer + "": string/integer/float, [0] + "dhcp4_option_x": { + "name": string, + "value": string/integer/float, + }, + "ip4_route_x": { + "dst": string, + "nh": string, + "mt": integer + }, + "ip6_route_x": { + "dst": string, + "nh": string, + "mt": integer, + "table": integer + } } ] + [0] all values of `---` are converted to null + Examples: - $ nmcli | jc --nmcli -p - [] + $ nmcli connection show ens33 | jc --nmcli -p + [ + { + "connection_id": "ens33", + "connection_uuid": "d92ece08-9e02-47d5-b2d2-92c80e155744", + "connection_stable_id": null, + "connection_type": "802-3-ethernet", + "connection_interface_name": "ens33", + "connection_autoconnect": "yes", + ... + "ip4_address_1": "192.168.71.180/24", + "ip4_gateway": "192.168.71.2", + "ip4_route_1": { + "dst": "0.0.0.0/0", + "nh": "192.168.71.2", + "mt": 100 + }, + "ip4_route_2": { + "dst": "192.168.71.0/24", + "nh": "0.0.0.0", + "mt": 100 + }, + "ip4_dns_1": "192.168.71.2", + "ip4_domain_1": "localdomain", + "dhcp4_option_1": { + "name": "broadcast_address", + "value": "192.168.71.255" + }, + ... + "ip6_address_1": "fe80::c1cb:715d:bc3e:b8a0/64", + "ip6_gateway": null, + "ip6_route_1": { + "dst": "fe80::/64", + "nh": "::", + "mt": 100 + } + } + ] $ nmcli | jc --nmcli -p -r - [] + [ + { + "connection_id": "ens33", + "connection_uuid": "d92ece08-9e02-47d5-b2d2-92c80e155744", + "connection_stable_id": null, + "connection_type": "802-3-ethernet", + "connection_interface_name": "ens33", + "connection_autoconnect": "yes", + ... + "ip4_address_1": "192.168.71.180/24", + "ip4_gateway": "192.168.71.2", + "ip4_route_1": { + "dst": "0.0.0.0/0", + "nh": "192.168.71.2", + "mt": "100" + }, + "ip4_route_2": { + "dst": "192.168.71.0/24", + "nh": "0.0.0.0", + "mt": "100" + }, + "ip4_dns_1": "192.168.71.2", + "ip4_domain_1": "localdomain", + "dhcp4_option_1": { + "name": "broadcast_address", + "value": "192.168.71.255" + }, + ... + "ip6_address_1": "fe80::c1cb:715d:bc3e:b8a0/64", + "ip6_gateway": null, + "ip6_route_1": { + "dst": "fe80::/64", + "nh": "::", + "mt": "100" + } + } + ] """ import re from typing import List, Dict, Optional import jc.utils from jc.parsers.universal import sparse_table_parse +from jc.exceptions import ParseError class info(): @@ -70,10 +174,36 @@ def _process(proc_data: List[Dict]) -> List[Dict]: List of Dictionaries. Structured to conform to the schema. """ - # process the data here - # rebuild output for added semantic information - # use helper functions in jc.utils for int, float, bool - # conversions and timestamps + for entry in proc_data: + for key in entry: + # use normal int/float conversions since jc.utils.convert_to_int is too greedy + try: + if '.' in entry[key]: + entry[key] = float(entry[key]) + else: + entry[key] = int(entry[key]) + except Exception: + pass + + if '_option_' in key and key[-1].isdigit(): + for k in entry[key]: + try: + if '.' in entry[key][k]: + entry[key][k] = float(entry[key][k]) + else: + entry[key][k] = int(entry[key][k]) + except Exception: + pass + + if '_route_' in key and key[-1].isdigit(): + for k in entry[key]: + try: + if '.' in entry[key][k]: + entry[key][k] = float(entry[key][k]) + else: + entry[key][k] = int(entry[key][k]) + except Exception: + pass return proc_data @@ -220,7 +350,17 @@ def _connection_show_x_parse(data: str) -> List[Dict]: def _general_permissions_parse(data: str) -> List[Dict]: - print('general permissions') + raw_output = [] + output_dict = {} + for line in filter(None, data.splitlines()): + key, value = line.split() + key_n = _normalize_key(key) + output_dict[key_n] = value + + output_dict.pop('permission') + raw_output.append(output_dict) + + return raw_output def _table_parse(data: str) -> List[Dict]: @@ -262,7 +402,7 @@ def parse( # nmcli (second line startswith \t) if data.splitlines()[1].startswith('\t'): - print('nmcli only') + raise ParseError('Use device, connection, or general subcommands in nmcli.') # nmcli device show # nmcli device show lo From 2c5c57ae04df3b7abfb1c3423c3350c7c2ab5dcd Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 24 Feb 2022 20:33:10 -0800 Subject: [PATCH 08/38] version bump --- jc/lib.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jc/lib.py b/jc/lib.py index 6fe8311e..18c96d5f 100644 --- a/jc/lib.py +++ b/jc/lib.py @@ -9,7 +9,7 @@ import importlib from typing import Dict, List, Iterable, Union, Iterator from jc import appdirs -__version__ = '1.18.3' +__version__ = '1.18.4' parsers = [ 'acpi', diff --git a/setup.py b/setup.py index d0c112fa..72ba44ed 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open('README.md', 'r') as f: setuptools.setup( name='jc', - version='1.18.3', + version='1.18.4', author='Kelly Brazil', author_email='kellyjonbrazil@gmail.com', description='Converts the output of popular command-line tools and file-types to JSON.', From 1923925710dadc4116202855ae884ef18394d428 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 24 Feb 2022 20:35:00 -0800 Subject: [PATCH 09/38] update changelog --- CHANGELOG | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 89997433..229b55df 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ jc changelog +20220224 v1.18.4 +- Add nmcli command parser tested on linux +- Enhance parse error messages at the cli + 20220214 v1.18.3 - Add rsync command and log file parser tested on linux and macOS - Add rsync command and log file streaming parser tested on linux and macOS From f75b06abe4af152be094f8bc1ba5ce66b25e35e2 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 24 Feb 2022 20:43:20 -0800 Subject: [PATCH 10/38] doc update --- README.md | 1 + docs/parsers/nmcli.md | 172 ++++++++++++++++++++++++++++++++++++++++++ jc/parsers/nmcli.py | 3 +- man/jc.1 | 7 +- 4 files changed, 180 insertions(+), 3 deletions(-) create mode 100644 docs/parsers/nmcli.md diff --git a/README.md b/README.md index f9743e0d..3278bd36 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,7 @@ option. - `--lsusb` enables the `lsusb` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/lsusb)) - `--mount` enables the `mount` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/mount)) - `--netstat` enables the `netstat` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/netstat)) +- `--nmcli` enables the `nmcli` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/nmcli)) - `--ntpq` enables the `ntpq -p` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ntpq)) - `--passwd` enables the `/etc/passwd` file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/passwd)) - `--ping` enables the `ping` and `ping6` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ping)) diff --git a/docs/parsers/nmcli.md b/docs/parsers/nmcli.md new file mode 100644 index 00000000..3e715588 --- /dev/null +++ b/docs/parsers/nmcli.md @@ -0,0 +1,172 @@ +[Home](https://kellyjonbrazil.github.io/jc/) + + +# jc.parsers.nmcli + +jc - JSON CLI output utility `nmcli` command output parser + +Supports the following `nmcli` subcommands: +- `nmcli general` +- `nmcli general permissions` +- `nmcli connection` +- `nmcli connection show ` +- `nmcli device` +- `nmcli device show` +- `nmcli device show ` + +Usage (cli): + + $ nmcli device show lo | jc --nmcli + + or + + $ jc nmcli device show lo + +Usage (module): + + import jc + result = jc.parse('nmcli', nmcli_command_output) + + or + + import jc.parsers.nmcli + result = jc.parsers.nmcli.parse(nmcli_command_output) + +Schema: + + Because there are so many options, the schema is best effort. Integer + and Float value conversions are attempted and the original values are + kept if they fail. If you don't want automatic conversion, then use the + -r or raw=True option to disable it. + + The structure is flat, for the most part, but there are a couple of + "well-known" keys that are further parsed into objects for convenience. + These are documented below. + + [ + { + "": string/integer/float, [0] + "dhcp4_option_x": { + "name": string, + "value": string/integer/float, + }, + "ip4_route_x": { + "dst": string, + "nh": string, + "mt": integer + }, + "ip6_route_x": { + "dst": string, + "nh": string, + "mt": integer, + "table": integer + } + } + ] + + [0] all values of `---` are converted to null + +Examples: + + $ nmcli connection show ens33 | jc --nmcli -p + [ + { + "connection_id": "ens33", + "connection_uuid": "d92ece08-9e02-47d5-b2d2-92c80e155744", + "connection_stable_id": null, + "connection_type": "802-3-ethernet", + "connection_interface_name": "ens33", + "connection_autoconnect": "yes", + ... + "ip4_address_1": "192.168.71.180/24", + "ip4_gateway": "192.168.71.2", + "ip4_route_1": { + "dst": "0.0.0.0/0", + "nh": "192.168.71.2", + "mt": 100 + }, + "ip4_route_2": { + "dst": "192.168.71.0/24", + "nh": "0.0.0.0", + "mt": 100 + }, + "ip4_dns_1": "192.168.71.2", + "ip4_domain_1": "localdomain", + "dhcp4_option_1": { + "name": "broadcast_address", + "value": "192.168.71.255" + }, + ... + "ip6_address_1": "fe80::c1cb:715d:bc3e:b8a0/64", + "ip6_gateway": null, + "ip6_route_1": { + "dst": "fe80::/64", + "nh": "::", + "mt": 100 + } + } + ] + + $ nmcli | jc --nmcli -p -r + [ + { + "connection_id": "ens33", + "connection_uuid": "d92ece08-9e02-47d5-b2d2-92c80e155744", + "connection_stable_id": null, + "connection_type": "802-3-ethernet", + "connection_interface_name": "ens33", + "connection_autoconnect": "yes", + ... + "ip4_address_1": "192.168.71.180/24", + "ip4_gateway": "192.168.71.2", + "ip4_route_1": { + "dst": "0.0.0.0/0", + "nh": "192.168.71.2", + "mt": "100" + }, + "ip4_route_2": { + "dst": "192.168.71.0/24", + "nh": "0.0.0.0", + "mt": "100" + }, + "ip4_dns_1": "192.168.71.2", + "ip4_domain_1": "localdomain", + "dhcp4_option_1": { + "name": "broadcast_address", + "value": "192.168.71.255" + }, + ... + "ip6_address_1": "fe80::c1cb:715d:bc3e:b8a0/64", + "ip6_gateway": null, + "ip6_route_1": { + "dst": "fe80::/64", + "nh": "::", + "mt": "100" + } + } + ] + + + +### parse + +```python +def parse(data: str, raw: bool = False, quiet: bool = False) -> List[Dict] +``` + +Main text parsing function + +Parameters: + + data: (string) text data to parse + raw: (boolean) unprocessed output if True + quiet: (boolean) suppress warning messages if True + +Returns: + + List of Dictionaries. Raw or processed structured data. + +### Parser Information +Compatibility: linux + +Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/jc/parsers/nmcli.py b/jc/parsers/nmcli.py index dadff717..4cc074c2 100644 --- a/jc/parsers/nmcli.py +++ b/jc/parsers/nmcli.py @@ -342,7 +342,6 @@ def _connection_show_x_parse(data: str) -> List[Dict]: if '_route_' in key_n and key_n[-1].isdigit(): item[key_n] = _split_routes(item[key_n]) - if item: raw_output.append(item) @@ -402,7 +401,7 @@ def parse( # nmcli (second line startswith \t) if data.splitlines()[1].startswith('\t'): - raise ParseError('Use device, connection, or general subcommands in nmcli.') + raise ParseError('Use the device, connection, or general subcommand in nmcli.') # nmcli device show # nmcli device show lo diff --git a/man/jc.1 b/man/jc.1 index 1151b676..29a94931 100644 --- a/man/jc.1 +++ b/man/jc.1 @@ -1,4 +1,4 @@ -.TH jc 1 2022-02-14 1.18.3 "JSON CLI output utility" +.TH jc 1 2022-02-24 1.18.4 "JSON CLI output utility" .SH NAME jc \- JSONifies the output of many CLI tools and file-types .SH SYNOPSIS @@ -257,6 +257,11 @@ Key/Value file parser \fB--netstat\fP `netstat` command parser +.TP +.B +\fB--nmcli\fP +`nmcli` command parser + .TP .B \fB--ntpq\fP From 6ae1d03187c6d4b669f6f74db1be7c9cf07adaed Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 24 Feb 2022 20:47:15 -0800 Subject: [PATCH 11/38] doc fix --- docs/parsers/nmcli.md | 2 +- jc/parsers/nmcli.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/parsers/nmcli.md b/docs/parsers/nmcli.md index 3e715588..519d20fd 100644 --- a/docs/parsers/nmcli.md +++ b/docs/parsers/nmcli.md @@ -107,7 +107,7 @@ Examples: } ] - $ nmcli | jc --nmcli -p -r + $ nmcli connection show ens33 | jc --nmcli -p -r [ { "connection_id": "ens33", diff --git a/jc/parsers/nmcli.py b/jc/parsers/nmcli.py index 4cc074c2..794e95b5 100644 --- a/jc/parsers/nmcli.py +++ b/jc/parsers/nmcli.py @@ -102,7 +102,7 @@ Examples: } ] - $ nmcli | jc --nmcli -p -r + $ nmcli connection show ens33 | jc --nmcli -p -r [ { "connection_id": "ens33", From 4bdeb2b3aa063c2772f5c44e52acbe16e915cc3a Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 24 Feb 2022 20:52:18 -0800 Subject: [PATCH 12/38] simplify warning message --- jc/parsers/xrandr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jc/parsers/xrandr.py b/jc/parsers/xrandr.py index a2c94271..871f2fcc 100644 --- a/jc/parsers/xrandr.py +++ b/jc/parsers/xrandr.py @@ -288,7 +288,7 @@ def _parse_device(next_lines: List[str], quiet: bool = False) -> Optional[Device device[k] = int(v) except ValueError and not quiet: jc.utils.warning_message( - [f"Error: {next_line} : {k} - {v} is not int-able"] + [f"{next_line} : {k} - {v} is not int-able"] ) while next_lines: From dbcd9a4060647be24bca2a8d577f11925a9ac210 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 24 Feb 2022 20:52:28 -0800 Subject: [PATCH 13/38] bump version to 1.0 --- jc/parsers/zipinfo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jc/parsers/zipinfo.py b/jc/parsers/zipinfo.py index 9ab7912b..8d706dc3 100644 --- a/jc/parsers/zipinfo.py +++ b/jc/parsers/zipinfo.py @@ -85,7 +85,7 @@ import jc.parsers.universal class info(): """Provides parser metadata (version, author, etc.)""" - version = '0.01' + version = '1.0' description = '`zipinfo` command parser' author = 'Matt J' author_email = 'https://github.com/listuser' From 5505bde8ef77db0885f08d8d04160cbc4418dd67 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 24 Feb 2022 20:53:54 -0800 Subject: [PATCH 14/38] doc update --- docs/parsers/zipinfo.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/parsers/zipinfo.md b/docs/parsers/zipinfo.md index 665a1a31..eef68a9b 100644 --- a/docs/parsers/zipinfo.md +++ b/docs/parsers/zipinfo.md @@ -107,4 +107,4 @@ Returns: ### Parser Information Compatibility: linux, darwin -Version 0.01 by Matt J (https://github.com/listuser) +Version 1.0 by Matt J (https://github.com/listuser) From 7b9722d255a16981099dc803beda7abe0d46106a Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 24 Feb 2022 21:21:02 -0800 Subject: [PATCH 15/38] fix formatting --- man/jc.1 | 30 +++++++++++++----------------- templates/manpage_template | 30 +++++++++++++----------------- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/man/jc.1 b/man/jc.1 index 29a94931..b7298fda 100644 --- a/man/jc.1 +++ b/man/jc.1 @@ -563,34 +563,28 @@ You may want to ignore parsing errors when using streaming parsers since these m .RS Successfully parsed line with \fB-qq\fP option: .RS +.na +.nf { - "command_data": "data", - "_jc_meta": { - "success": true - } - } .RE Unsuccessfully parsed line with \fB-qq\fP option: .RS +.na +.nf { - "_jc_meta": { - "success": false, - "error": "error message", - "line": "original line data" - } - } +.fi .RE .RE @@ -599,21 +593,23 @@ Unsuccessfully parsed line with \fB-qq\fP option: Most operating systems will buffer output that is being piped from process to process. The buffer is usually around 4KB. When viewing the output in the terminal the OS buffer is not engaged so output is immediately displayed on the screen. When piping multiple processes together, though, it may seem as if the output is hanging when the input data is very slow (e.g. \fBping\fP): .RS +.na +.nf $ ping 1.1.1.1 | jc --ping-s | jq - +.fi .RE This is because the OS engages the 4KB buffer between \fBjc\fP and \fBjq\fP in this example. To display the data on the terminal in realtime, you can disable the buffer with the \fB-u\fP (unbuffer) cli option: .RS +.na +.nf $ ping 1.1.1.1 | jc --ping-s -u | jq - -{"type":"reply","pattern":null,"timestamp":null,"bytes":"64","response_ip":"1.1.1.1","icmp_seq":"1","ttl":"128","time_ms":"24.6","duplicate":false} - -{"type":"reply","pattern":null,"timestamp":null,"bytes":"64","response_ip":"1.1.1.1","icmp_seq":"2","ttl":"128","time_ms":"26.8","duplicate":false} - +{"type":"reply","pattern":null,"timestamp":null,"bytes":"64",...} +{"type":"reply","pattern":null,"timestamp":null,"bytes":"64",...} etc... +.fi Note: Unbuffered output can be slower for large data streams. .RE diff --git a/templates/manpage_template b/templates/manpage_template index cb9cfef2..38fc17fb 100644 --- a/templates/manpage_template +++ b/templates/manpage_template @@ -123,34 +123,28 @@ You may want to ignore parsing errors when using streaming parsers since these m .RS Successfully parsed line with \fB-qq\fP option: .RS +.na +.nf { - "command_data": "data", - "_jc_meta": { - "success": true - } - } .RE Unsuccessfully parsed line with \fB-qq\fP option: .RS +.na +.nf { - "_jc_meta": { - "success": false, - "error": "error message", - "line": "original line data" - } - } +.fi .RE .RE @@ -159,21 +153,23 @@ Unsuccessfully parsed line with \fB-qq\fP option: Most operating systems will buffer output that is being piped from process to process. The buffer is usually around 4KB. When viewing the output in the terminal the OS buffer is not engaged so output is immediately displayed on the screen. When piping multiple processes together, though, it may seem as if the output is hanging when the input data is very slow (e.g. \fBping\fP): .RS +.na +.nf $ ping 1.1.1.1 | jc --ping-s | jq - +.fi .RE This is because the OS engages the 4KB buffer between \fBjc\fP and \fBjq\fP in this example. To display the data on the terminal in realtime, you can disable the buffer with the \fB-u\fP (unbuffer) cli option: .RS +.na +.nf $ ping 1.1.1.1 | jc --ping-s -u | jq - -{"type":"reply","pattern":null,"timestamp":null,"bytes":"64","response_ip":"1.1.1.1","icmp_seq":"1","ttl":"128","time_ms":"24.6","duplicate":false} - -{"type":"reply","pattern":null,"timestamp":null,"bytes":"64","response_ip":"1.1.1.1","icmp_seq":"2","ttl":"128","time_ms":"26.8","duplicate":false} - +{"type":"reply","pattern":null,"timestamp":null,"bytes":"64",...} +{"type":"reply","pattern":null,"timestamp":null,"bytes":"64",...} etc... +.fi Note: Unbuffered output can be slower for large data streams. .RE From 554ca61d1764b81dea06b6b013d0444072f0662a Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Fri, 25 Feb 2022 11:19:20 -0800 Subject: [PATCH 16/38] add tests --- .../centos-7.7/nmcli-connection-all.json | 1 + .../nmcli-connection-show-ens33.json | 1 + .../fixtures/centos-7.7/nmcli-connection.json | 1 + .../fixtures/centos-7.7/nmcli-device-all.json | 1 + .../centos-7.7/nmcli-device-show-ens33.json | 1 + .../centos-7.7/nmcli-device-show-lo.json | 1 + .../centos-7.7/nmcli-device-show.json | 1 + tests/fixtures/centos-7.7/nmcli-device.json | 1 + .../centos-7.7/nmcli-general-all.json | 1 + .../centos-7.7/nmcli-general-permissions.json | 1 + tests/test_nmcli.py | 155 ++++++++++++++++++ 11 files changed, 165 insertions(+) create mode 100644 tests/fixtures/centos-7.7/nmcli-connection-all.json create mode 100644 tests/fixtures/centos-7.7/nmcli-connection-show-ens33.json create mode 100644 tests/fixtures/centos-7.7/nmcli-connection.json create mode 100644 tests/fixtures/centos-7.7/nmcli-device-all.json create mode 100644 tests/fixtures/centos-7.7/nmcli-device-show-ens33.json create mode 100644 tests/fixtures/centos-7.7/nmcli-device-show-lo.json create mode 100644 tests/fixtures/centos-7.7/nmcli-device-show.json create mode 100644 tests/fixtures/centos-7.7/nmcli-device.json create mode 100644 tests/fixtures/centos-7.7/nmcli-general-all.json create mode 100644 tests/fixtures/centos-7.7/nmcli-general-permissions.json create mode 100644 tests/test_nmcli.py diff --git a/tests/fixtures/centos-7.7/nmcli-connection-all.json b/tests/fixtures/centos-7.7/nmcli-connection-all.json new file mode 100644 index 00000000..df986a93 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-connection-all.json @@ -0,0 +1 @@ +[{"name":"ens33","uuid":"d92ece08-9e02-47d5-b2d2-92c80e155744","type":"ethernet","timestamp":1645643581,"timestamp_real":"Wed 23 Feb 2022 11:13:01 AM PST","autoconnect":"yes","autoconnect_priority":0,"readonly":"no","dbus_path":"/org/freedesktop/NetworkManager/Settings/1","active":"yes","device":"ens33","state":"activated","active_path":"/org/freedesktop/NetworkManager/ActiveConnection/1","slave":null,"filename":"/etc/sysconfig/network-scripts/ifcfg-ens33"}] diff --git a/tests/fixtures/centos-7.7/nmcli-connection-show-ens33.json b/tests/fixtures/centos-7.7/nmcli-connection-show-ens33.json new file mode 100644 index 00000000..cb2058f7 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-connection-show-ens33.json @@ -0,0 +1 @@ +[{"connection_id":"ens33","connection_uuid":"d92ece08-9e02-47d5-b2d2-92c80e155744","connection_stable_id":null,"connection_type":"802-3-ethernet","connection_interface_name":"ens33","connection_autoconnect":"yes","connection_autoconnect_priority":0,"connection_autoconnect_retries":-1,"connection_autoconnect_retries_text":"default","connection_multi_connect":0,"connection_multi_connect_text":"default","connection_auth_retries":-1,"connection_timestamp":1645570618,"connection_read_only":"no","connection_permissions":null,"connection_zone":null,"connection_master":null,"connection_slave_type":null,"connection_autoconnect_slaves":-1,"connection_autoconnect_slaves_text":"default","connection_secondaries":null,"connection_gateway_ping_timeout":0,"connection_metered":"unknown","connection_lldp":"default","connection_mdns":-1,"connection_mdns_text":"default","connection_llmnr":-1,"connection_llmnr_text":"default","802_3_ethernet_port":null,"802_3_ethernet_speed":0,"802_3_ethernet_duplex":null,"802_3_ethernet_auto_negotiate":"no","802_3_ethernet_mac_address":null,"802_3_ethernet_cloned_mac_address":null,"802_3_ethernet_generate_mac_address_mask":null,"802_3_ethernet_mac_address_blacklist":null,"802_3_ethernet_mtu":"auto","802_3_ethernet_s390_subchannels":null,"802_3_ethernet_s390_nettype":null,"802_3_ethernet_s390_options":null,"802_3_ethernet_wake_on_lan":"default","802_3_ethernet_wake_on_lan_password":null,"ipv4_method":"auto","ipv4_dns":null,"ipv4_dns_search":null,"ipv4_dns_options":"","ipv4_dns_priority":0,"ipv4_addresses":null,"ipv4_gateway":null,"ipv4_routes":null,"ipv4_route_metric":-1,"ipv4_route_table":0,"ipv4_route_table_text":"unspec","ipv4_routing_rules":null,"ipv4_ignore_auto_routes":"no","ipv4_ignore_auto_dns":"no","ipv4_dhcp_client_id":null,"ipv4_dhcp_timeout":0,"ipv4_dhcp_timeout_text":"default","ipv4_dhcp_send_hostname":"yes","ipv4_dhcp_hostname":null,"ipv4_dhcp_fqdn":null,"ipv4_never_default":"no","ipv4_may_fail":"yes","ipv4_dad_timeout":-1,"ipv4_dad_timeout_text":"default","ipv6_method":"auto","ipv6_dns":null,"ipv6_dns_search":null,"ipv6_dns_options":"","ipv6_dns_priority":0,"ipv6_addresses":null,"ipv6_gateway":null,"ipv6_routes":null,"ipv6_route_metric":-1,"ipv6_route_table":0,"ipv6_route_table_text":"unspec","ipv6_routing_rules":null,"ipv6_ignore_auto_routes":"no","ipv6_ignore_auto_dns":"no","ipv6_never_default":"no","ipv6_may_fail":"yes","ipv6_ip6_privacy":-1,"ipv6_ip6_privacy_text":"unknown","ipv6_addr_gen_mode":"stable-privacy","ipv6_dhcp_duid":null,"ipv6_dhcp_send_hostname":"yes","ipv6_dhcp_hostname":null,"ipv6_token":null,"proxy_method":"none","proxy_browser_only":"no","proxy_pac_url":null,"proxy_pac_script":null,"name":"ens33","uuid":"d92ece08-9e02-47d5-b2d2-92c80e155744","devices":"ens33","state":"activated","default":"yes","default6":"no","spec_object":null,"vpn":"no","dbus_path":"/org/freedesktop/NetworkManager/ActiveConnection/1","con_path":"/org/freedesktop/NetworkManager/Settings/1","zone":null,"master_path":null,"ip4_address_1":"192.168.71.180/24","ip4_gateway":"192.168.71.2","ip4_route_1":{"dst":"0.0.0.0/0","nh":"192.168.71.2","mt":100},"ip4_route_2":{"dst":"192.168.71.0/24","nh":"0.0.0.0","mt":100},"ip4_dns_1":"192.168.71.2","ip4_domain_1":"localdomain","dhcp4_option_1":{"name":"broadcast_address","value":"192.168.71.255"},"dhcp4_option_2":{"name":"dhcp_lease_time","value":1800},"dhcp4_option_3":{"name":"dhcp_message_type","value":5},"dhcp4_option_4":{"name":"dhcp_server_identifier","value":"192.168.71.254"},"dhcp4_option_5":{"name":"domain_name","value":"localdomain"},"dhcp4_option_6":{"name":"domain_name_servers","value":"192.168.71.2"},"dhcp4_option_7":{"name":"expiry","value":1645572241},"dhcp4_option_8":{"name":"ip_address","value":"192.168.71.180"},"dhcp4_option_9":{"name":"network_number","value":"192.168.71.0"},"dhcp4_option_10":{"name":"next_server","value":"192.168.71.254"},"dhcp4_option_11":{"name":"requested_broadcast_address","value":1},"dhcp4_option_12":{"name":"requested_classless_static_routes","value":1},"dhcp4_option_13":{"name":"requested_domain_name","value":1},"dhcp4_option_14":{"name":"requested_domain_name_servers","value":1},"dhcp4_option_15":{"name":"requested_domain_search","value":1},"dhcp4_option_16":{"name":"requested_host_name","value":1},"dhcp4_option_17":{"name":"requested_interface_mtu","value":1},"dhcp4_option_18":{"name":"requested_ms_classless_static_routes","value":1},"dhcp4_option_19":{"name":"requested_nis_domain","value":1},"dhcp4_option_20":{"name":"requested_nis_servers","value":1},"dhcp4_option_21":{"name":"requested_ntp_servers","value":1},"dhcp4_option_22":{"name":"requested_rfc3442_classless_static_routes","value":1},"dhcp4_option_23":{"name":"requested_root_path","value":1},"dhcp4_option_24":{"name":"requested_routers","value":1},"dhcp4_option_25":{"name":"requested_static_routes","value":1},"dhcp4_option_26":{"name":"requested_subnet_mask","value":1},"dhcp4_option_27":{"name":"requested_time_offset","value":1},"dhcp4_option_28":{"name":"requested_wpad","value":1},"dhcp4_option_29":{"name":"routers","value":"192.168.71.2"},"dhcp4_option_30":{"name":"subnet_mask","value":"255.255.255.0"},"ip6_address_1":"fe80::c1cb:715d:bc3e:b8a0/64","ip6_gateway":null,"ip6_route_1":{"dst":"fe80::/64","nh":"::","mt":100},"ip6_route_2":{"dst":"ff00::/8","nh":"::","mt":256,"table":255}}] diff --git a/tests/fixtures/centos-7.7/nmcli-connection.json b/tests/fixtures/centos-7.7/nmcli-connection.json new file mode 100644 index 00000000..823ebaa3 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-connection.json @@ -0,0 +1 @@ +[{"name":"ens33","uuid":"d92ece08-9e02-47d5-b2d2-92c80e155744","type":"ethernet","device":"ens33"}] diff --git a/tests/fixtures/centos-7.7/nmcli-device-all.json b/tests/fixtures/centos-7.7/nmcli-device-all.json new file mode 100644 index 00000000..482d2116 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-device-all.json @@ -0,0 +1 @@ +[{"device":"ens33","type":"ethernet","state":"connected","ip4_connectivity":"full","ip6_connectivity":"full","dbus_path":"/org/freedesktop/NetworkManager/Devices/2","connection":"ens33","con_uuid":"d92ece08-9e02-47d5-b2d2-92c80e155744","con_path":"/org/freedesktop/NetworkManager/ActiveConnection/1"},{"device":"docker0","type":"bridge","state":"unmanaged","ip4_connectivity":"unknown","ip6_connectivity":"unknown","dbus_path":"/org/freedesktop/NetworkManager/Devices/3","connection":null,"con_uuid":null,"con_path":null},{"device":"lo","type":"loopback","state":"unmanaged","ip4_connectivity":"unknown","ip6_connectivity":"unknown","dbus_path":"/org/freedesktop/NetworkManager/Devices/1","connection":null,"con_uuid":null,"con_path":null}] diff --git a/tests/fixtures/centos-7.7/nmcli-device-show-ens33.json b/tests/fixtures/centos-7.7/nmcli-device-show-ens33.json new file mode 100644 index 00000000..9d3e6629 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-device-show-ens33.json @@ -0,0 +1 @@ +[{"device":"ens33","type":"ethernet","hwaddr":"00:0C:29:3B:58:0E","mtu":1500,"state":100,"state_text":"connected","connection":"ens33","con_path":"/org/freedesktop/NetworkManager/ActiveConnection/1","wired_properties_carrier":"on","ip4_address_1":"192.168.71.180/24","ip4_gateway":"192.168.71.2","ip4_route_1":{"dst":"0.0.0.0/0","nh":"192.168.71.2","mt":100},"ip4_route_2":{"dst":"192.168.71.0/24","nh":"0.0.0.0","mt":100},"ip4_dns_1":"192.168.71.2","ip4_domain_1":"localdomain","ip6_address_1":"fe80::c1cb:715d:bc3e:b8a0/64","ip6_gateway":null,"ip6_route_1":{"dst":"fe80::/64","nh":"::","mt":100},"ip6_route_2":{"dst":"ff00::/8","nh":"::","mt":256,"table":255}}] diff --git a/tests/fixtures/centos-7.7/nmcli-device-show-lo.json b/tests/fixtures/centos-7.7/nmcli-device-show-lo.json new file mode 100644 index 00000000..b18607db --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-device-show-lo.json @@ -0,0 +1 @@ +[{"device":"lo","type":"loopback","hwaddr":"00:00:00:00:00:00","mtu":65536,"state":10,"state_text":"unmanaged","connection":null,"con_path":null,"ip4_address_1":"127.0.0.1/8","ip4_gateway":null,"ip6_address_1":"::1/128","ip6_gateway":null}] diff --git a/tests/fixtures/centos-7.7/nmcli-device-show.json b/tests/fixtures/centos-7.7/nmcli-device-show.json new file mode 100644 index 00000000..78b87947 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-device-show.json @@ -0,0 +1 @@ +[{"device":"ens33","type":"ethernet","hwaddr":"00:0C:29:3B:58:0E","mtu":1500,"state":100,"state_text":"connected","connection":"ens33","con_path":"/org/freedesktop/NetworkManager/ActiveConnection/1","wired_properties_carrier":"on","ip4_address_1":"192.168.71.180/24","ip4_gateway":"192.168.71.2","ip4_route_1":{"dst":"0.0.0.0/0","nh":"192.168.71.2","mt":100},"ip4_route_2":{"dst":"192.168.71.0/24","nh":"0.0.0.0","mt":100},"ip4_dns_1":"192.168.71.2","ip4_domain_1":"localdomain","ip6_address_1":"fe80::c1cb:715d:bc3e:b8a0/64","ip6_gateway":null,"ip6_route_1":{"dst":"fe80::/64","nh":"::","mt":100},"ip6_route_2":{"dst":"ff00::/8","nh":"::","mt":256,"table":255}},{"device":"docker0","type":"bridge","hwaddr":"02:42:99:67:E8:21","mtu":1500,"state":10,"state_text":"unmanaged","connection":null,"con_path":null,"ip4_address_1":"172.17.0.1/16","ip4_gateway":null,"ip4_route_1":{"dst":"172.17.0.0/16","nh":"0.0.0.0","mt":0},"ip6_gateway":null},{"device":"lo","type":"loopback","hwaddr":"00:00:00:00:00:00","mtu":65536,"state":10,"state_text":"unmanaged","connection":null,"con_path":null,"ip4_address_1":"127.0.0.1/8","ip4_gateway":null,"ip6_address_1":"::1/128","ip6_gateway":null}] diff --git a/tests/fixtures/centos-7.7/nmcli-device.json b/tests/fixtures/centos-7.7/nmcli-device.json new file mode 100644 index 00000000..24eb3c58 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-device.json @@ -0,0 +1 @@ +[{"device":"ens33","type":"ethernet","state":"connected","connection":"ens33"},{"device":"docker0","type":"bridge","state":"unmanaged","connection":null},{"device":"lo","type":"loopback","state":"unmanaged","connection":null}] diff --git a/tests/fixtures/centos-7.7/nmcli-general-all.json b/tests/fixtures/centos-7.7/nmcli-general-all.json new file mode 100644 index 00000000..fd1a97dd --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-general-all.json @@ -0,0 +1 @@ +[{"running":"running","version":"1.18.0","state":"connected","startup":"started","connectivity":"full","networking":"enabled","wifi_hw":"enabled","wifi":"enabled","wwan_hw":"enabled","wwan":"enabled"}] diff --git a/tests/fixtures/centos-7.7/nmcli-general-permissions.json b/tests/fixtures/centos-7.7/nmcli-general-permissions.json new file mode 100644 index 00000000..1e63dbf0 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-general-permissions.json @@ -0,0 +1 @@ +[{"org_freedesktop_networkmanager_enable_disable_network":"yes","org_freedesktop_networkmanager_enable_disable_wifi":"yes","org_freedesktop_networkmanager_enable_disable_wwan":"yes","org_freedesktop_networkmanager_enable_disable_wimax":"yes","org_freedesktop_networkmanager_sleep_wake":"yes","org_freedesktop_networkmanager_network_control":"yes","org_freedesktop_networkmanager_wifi_share_protected":"yes","org_freedesktop_networkmanager_wifi_share_open":"yes","org_freedesktop_networkmanager_settings_modify_system":"yes","org_freedesktop_networkmanager_settings_modify_own":"yes","org_freedesktop_networkmanager_settings_modify_hostname":"yes","org_freedesktop_networkmanager_settings_modify_global_dns":"yes","org_freedesktop_networkmanager_reload":"yes","org_freedesktop_networkmanager_checkpoint_rollback":"yes","org_freedesktop_networkmanager_enable_disable_statistics":"yes","org_freedesktop_networkmanager_enable_disable_connectivity_check":"yes","org_freedesktop_networkmanager_wifi_scan":"unknown"}] diff --git a/tests/test_nmcli.py b/tests/test_nmcli.py new file mode 100644 index 00000000..b0f75718 --- /dev/null +++ b/tests/test_nmcli.py @@ -0,0 +1,155 @@ +import os +import unittest +import json +import jc.parsers.nmcli +from jc.exceptions import ParseError + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class MyTests(unittest.TestCase): + + def setUp(self): + # input + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-connection-all.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_connection_all = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-connection-show-ens33.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_connection_show_ens33 = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-connection.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_connection = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-all.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_device_all = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-show-ens33.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_device_show_ens33 = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-show-lo.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_device_show_lo = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-show.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_device_show = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_device = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-general-all.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_general_all = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-general-permissions.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_general_permissions = f.read() + + + # output + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-connection-all.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_connection_all_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-connection-show-ens33.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_connection_show_ens33_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-connection.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_connection_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-all.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_device_all_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-show-ens33.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_device_show_ens33_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-show-lo.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_device_show_lo_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-show.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_device_show_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_device_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-general-all.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_general_all_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-general-permissions.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_general_permissions_json = json.loads(f.read()) + + + + def test_nmcli_nodata(self): + """ + Test 'nmcli' with no data + """ + self.assertEqual(jc.parsers.nmcli.parse('', quiet=True), []) + + def test_nmcli_centos_7_7(self): + """ + Test 'nmcli' on Centos 7.7 - this should raise a ParseError exception + """ + self.assertRaises(ParseError, jc.parsers.nmcli.parse, self.centos_7_7_nmcli, quiet=True) + + def test_nmcli_connection_all_centos_7_7(self): + """ + Test 'nmcli -f all connection' on Centos 7.7 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_connection_all, quiet=True), self.centos_7_7_nmcli_connection_all_json) + + def test_nmcli_connection_show_ens33_centos_7_7(self): + """ + Test 'nmcli connection show ens33' on Centos 7.7 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_connection_show_ens33, quiet=True), self.centos_7_7_nmcli_connection_show_ens33_json) + + def test_nmcli_connection_centos_7_7(self): + """ + Test 'nmcli connection' on Centos 7.7 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_connection, quiet=True), self.centos_7_7_nmcli_connection_json) + + def test_nmcli_device_all_centos_7_7(self): + """ + Test 'nmcli -f all device' on Centos 7.7 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_device_all, quiet=True), self.centos_7_7_nmcli_device_all_json) + + def test_nmcli_device_show_ens33_centos_7_7(self): + """ + Test 'nmcli device show ens33' on Centos 7.7 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_device_show_ens33, quiet=True), self.centos_7_7_nmcli_device_show_ens33_json) + + def test_nmcli_device_show_lo_centos_7_7(self): + """ + Test 'nmcli device show lo' on Centos 7.7 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_device_show_lo, quiet=True), self.centos_7_7_nmcli_device_show_lo_json) + + def test_nmcli_device_show_centos_7_7(self): + """ + Test 'nmcli device show' on Centos 7.7 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_device_show, quiet=True), self.centos_7_7_nmcli_device_show_json) + + def test_nmcli_device_centos_7_7(self): + """ + Test 'nmcli device' on Centos 7.7 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_device, quiet=True), self.centos_7_7_nmcli_device_json) + + def test_nmcli_general_all_centos_7_7(self): + """ + Test 'nmcli -f all general' on Centos 7.7 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_general_all, quiet=True), self.centos_7_7_nmcli_general_all_json) + + def test_nmcli_general_permissions_centos_7_7(self): + """ + Test 'nmcli general permissions' on Centos 7.7 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_general_permissions, quiet=True), self.centos_7_7_nmcli_general_permissions_json) + + +if __name__ == '__main__': + unittest.main() From b7c6faf3daf8eb0c42a222778baa440c5a018c75 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Fri, 25 Feb 2022 11:23:20 -0800 Subject: [PATCH 17/38] enhance error message --- jc/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jc/cli.py b/jc/cli.py index e4b15516..b3644720 100644 --- a/jc/cli.py +++ b/jc/cli.py @@ -563,7 +563,7 @@ def main(): f'{parser_name} parser could not parse the input data.', f'{streaming_msg}', 'If this is the correct parser, try setting the locale to C (LANG=C).', - 'For details use the -d or -dd option. Use "jc -h" for help.' + f'For details use the -d or -dd option. Use "jc -h --{parser_name}" for help.' ]) sys.exit(combined_exit_code(magic_exit_code, JC_ERROR_EXIT)) From 002caa9fb3b65f1ae64df25cc39c3de130403e76 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 28 Feb 2022 12:19:02 -0800 Subject: [PATCH 18/38] add fedora tests --- .../fedora32/nmcli-connection-show-ens33.json | 1 + .../fedora32/nmcli-connection-show-ens33.out | 148 ++++++++++++++++++ .../fedora32/nmcli-device-show-ens33.json | 1 + .../fedora32/nmcli-device-show-ens33.out | 26 +++ .../fixtures/fedora32/nmcli-device-show.json | 1 + tests/fixtures/fedora32/nmcli-device-show.out | 39 +++++ tests/test_nmcli.py | 36 +++++ 7 files changed, 252 insertions(+) create mode 100644 tests/fixtures/fedora32/nmcli-connection-show-ens33.json create mode 100644 tests/fixtures/fedora32/nmcli-connection-show-ens33.out create mode 100644 tests/fixtures/fedora32/nmcli-device-show-ens33.json create mode 100644 tests/fixtures/fedora32/nmcli-device-show-ens33.out create mode 100644 tests/fixtures/fedora32/nmcli-device-show.json create mode 100644 tests/fixtures/fedora32/nmcli-device-show.out diff --git a/tests/fixtures/fedora32/nmcli-connection-show-ens33.json b/tests/fixtures/fedora32/nmcli-connection-show-ens33.json new file mode 100644 index 00000000..97355923 --- /dev/null +++ b/tests/fixtures/fedora32/nmcli-connection-show-ens33.json @@ -0,0 +1 @@ +[{"connection_id":"ens33","connection_uuid":"fbea23dd-6738-403f-b3a5-5d4a3444216a","connection_stable_id":null,"connection_type":"802-3-ethernet","connection_interface_name":"ens33","connection_autoconnect":"yes","connection_autoconnect_priority":0,"connection_autoconnect_retries":-1,"connection_autoconnect_retries_text":"default","connection_multi_connect":0,"connection_multi_connect_text":"default","connection_auth_retries":-1,"connection_timestamp":1646019157,"connection_read_only":"no","connection_permissions":null,"connection_zone":null,"connection_master":null,"connection_slave_type":null,"connection_autoconnect_slaves":-1,"connection_autoconnect_slaves_text":"default","connection_secondaries":null,"connection_gateway_ping_timeout":0,"connection_metered":"unknown","connection_lldp":"default","connection_mdns":-1,"connection_mdns_text":"default","connection_llmnr":-1,"connection_llmnr_text":"default","connection_wait_device_timeout":-1,"802_3_ethernet_port":null,"802_3_ethernet_speed":0,"802_3_ethernet_duplex":null,"802_3_ethernet_auto_negotiate":"no","802_3_ethernet_mac_address":null,"802_3_ethernet_cloned_mac_address":null,"802_3_ethernet_generate_mac_address_mask":null,"802_3_ethernet_mac_address_blacklist":null,"802_3_ethernet_mtu":"auto","802_3_ethernet_s390_subchannels":null,"802_3_ethernet_s390_nettype":null,"802_3_ethernet_s390_options":null,"802_3_ethernet_wake_on_lan":"default","802_3_ethernet_wake_on_lan_password":null,"ipv4_method":"auto","ipv4_dns":null,"ipv4_dns_search":null,"ipv4_dns_options":null,"ipv4_dns_priority":0,"ipv4_addresses":null,"ipv4_gateway":null,"ipv4_routes":null,"ipv4_route_metric":-1,"ipv4_route_table":0,"ipv4_route_table_text":"unspec","ipv4_routing_rules":null,"ipv4_ignore_auto_routes":"no","ipv4_ignore_auto_dns":"no","ipv4_dhcp_client_id":null,"ipv4_dhcp_iaid":null,"ipv4_dhcp_timeout":0,"ipv4_dhcp_timeout_text":"default","ipv4_dhcp_send_hostname":"yes","ipv4_dhcp_hostname":null,"ipv4_dhcp_fqdn":null,"ipv4_dhcp_hostname_flags":"0x0","ipv4_dhcp_hostname_flags_text":"none","ipv4_never_default":"no","ipv4_may_fail":"yes","ipv4_dad_timeout":-1,"ipv4_dad_timeout_text":"default","ipv6_method":"auto","ipv6_dns":null,"ipv6_dns_search":null,"ipv6_dns_options":null,"ipv6_dns_priority":0,"ipv6_addresses":null,"ipv6_gateway":null,"ipv6_routes":null,"ipv6_route_metric":-1,"ipv6_route_table":0,"ipv6_route_table_text":"unspec","ipv6_routing_rules":null,"ipv6_ignore_auto_routes":"no","ipv6_ignore_auto_dns":"no","ipv6_never_default":"no","ipv6_may_fail":"yes","ipv6_ip6_privacy":-1,"ipv6_ip6_privacy_text":"unknown","ipv6_addr_gen_mode":"stable-privacy","ipv6_ra_timeout":0,"ipv6_ra_timeout_text":"default","ipv6_dhcp_duid":null,"ipv6_dhcp_iaid":null,"ipv6_dhcp_timeout":0,"ipv6_dhcp_timeout_text":"default","ipv6_dhcp_send_hostname":"yes","ipv6_dhcp_hostname":null,"ipv6_dhcp_hostname_flags":"0x0","ipv6_dhcp_hostname_flags_text":"none","ipv6_token":null,"proxy_method":"none","proxy_browser_only":"no","proxy_pac_url":null,"proxy_pac_script":null,"name":"ens33","uuid":"fbea23dd-6738-403f-b3a5-5d4a3444216a","devices":"ens33","ip_iface":"ens33","state":"activated","default":"yes","default6":"yes","spec_object":null,"vpn":"no","dbus_path":"/org/freedesktop/NetworkManager/ActiveConnection/2","con_path":"/org/freedesktop/NetworkManager/Settings/1","zone":null,"master_path":null,"ip4_address_1":"10.0.0.178/24","ip4_gateway":"10.0.0.1","ip4_route_1":{"dst":"0.0.0.0/0","nh":"10.0.0.1","mt":100},"ip4_route_2":{"dst":"10.0.0.0/24","nh":"0.0.0.0","mt":100},"ip4_dns_1":"75.75.75.75","ip4_dns_2":"75.75.76.76","ip4_domain_1":"hsd1.ca.comcast.net","dhcp4_option_1":{"name":"dhcp_lease_time","value":172800},"dhcp4_option_2":{"name":"domain_name","value":"hsd1.ca.comcast.net"},"dhcp4_option_3":{"name":"domain_name_servers","value":"75.75.75.75 75.75.76.76"},"dhcp4_option_4":{"name":"expiry","value":1646191487},"dhcp4_option_5":{"name":"ip_address","value":"10.0.0.178"},"dhcp4_option_6":{"name":"next_server","value":"10.0.0.1"},"dhcp4_option_7":{"name":"requested_broadcast_address","value":1},"dhcp4_option_8":{"name":"requested_domain_name","value":1},"dhcp4_option_9":{"name":"requested_domain_name_servers","value":1},"dhcp4_option_10":{"name":"requested_domain_search","value":1},"dhcp4_option_11":{"name":"requested_host_name","value":1},"dhcp4_option_12":{"name":"requested_interface_mtu","value":1},"dhcp4_option_13":{"name":"requested_ms_classless_static_routes","value":1},"dhcp4_option_14":{"name":"requested_nis_domain","value":1},"dhcp4_option_15":{"name":"requested_nis_servers","value":1},"dhcp4_option_16":{"name":"requested_ntp_servers","value":1},"dhcp4_option_17":{"name":"requested_rfc3442_classless_static_routes","value":1},"dhcp4_option_18":{"name":"requested_root_path","value":1},"dhcp4_option_19":{"name":"requested_routers","value":1},"dhcp4_option_20":{"name":"requested_static_routes","value":1},"dhcp4_option_21":{"name":"requested_subnet_mask","value":1},"dhcp4_option_22":{"name":"requested_time_offset","value":1},"dhcp4_option_23":{"name":"requested_wpad","value":1},"dhcp4_option_24":{"name":"routers","value":"10.0.0.1"},"dhcp4_option_25":{"name":"subnet_mask","value":"255.255.255.0"},"ip6_address_1":"2601:641:482:9cc0::2d6d/128","ip6_address_2":"fe80::9263:6fcc:6db6:8b56/64","ip6_gateway":"fe80::f88c:f4ff:fef1:d8f9","ip6_route_1":{"dst":"fd29:95c1:bb51::/64","nh":"fe80::1453:e8bf:c07a:2ca8","mt":100},"ip6_route_2":{"dst":"2601:641:482:9cc0::/60","nh":"::","mt":100},"ip6_route_3":{"dst":"::/0","nh":"fe80::f88c:f4ff:fef1:d8f9","mt":100},"ip6_route_4":{"dst":"ff00::/8","nh":"::","mt":256,"table":255},"ip6_route_5":{"dst":"fe80::/64","nh":"::","mt":100},"ip6_route_6":{"dst":"2601:641:482:9cc0::2d6d/128","nh":"::","mt":100},"ip6_dns_1":"2001:558:feed::1","ip6_dns_2":"2001:558:feed::2","dhcp6_option_1":{"name":"dhcp6_name_servers","value":"2001:558:feed::1 2001:558:feed::2"},"dhcp6_option_2":{"name":"ip6_address","value":"2601:641:482:9cc0::2d6d"}}] diff --git a/tests/fixtures/fedora32/nmcli-connection-show-ens33.out b/tests/fixtures/fedora32/nmcli-connection-show-ens33.out new file mode 100644 index 00000000..876b57e9 --- /dev/null +++ b/tests/fixtures/fedora32/nmcli-connection-show-ens33.out @@ -0,0 +1,148 @@ +connection.id: ens33 +connection.uuid: fbea23dd-6738-403f-b3a5-5d4a3444216a +connection.stable-id: -- +connection.type: 802-3-ethernet +connection.interface-name: ens33 +connection.autoconnect: yes +connection.autoconnect-priority: 0 +connection.autoconnect-retries: -1 (default) +connection.multi-connect: 0 (default) +connection.auth-retries: -1 +connection.timestamp: 1646019157 +connection.read-only: no +connection.permissions: -- +connection.zone: -- +connection.master: -- +connection.slave-type: -- +connection.autoconnect-slaves: -1 (default) +connection.secondaries: -- +connection.gateway-ping-timeout: 0 +connection.metered: unknown +connection.lldp: default +connection.mdns: -1 (default) +connection.llmnr: -1 (default) +connection.wait-device-timeout: -1 +802-3-ethernet.port: -- +802-3-ethernet.speed: 0 +802-3-ethernet.duplex: -- +802-3-ethernet.auto-negotiate: no +802-3-ethernet.mac-address: -- +802-3-ethernet.cloned-mac-address: -- +802-3-ethernet.generate-mac-address-mask:-- +802-3-ethernet.mac-address-blacklist: -- +802-3-ethernet.mtu: auto +802-3-ethernet.s390-subchannels: -- +802-3-ethernet.s390-nettype: -- +802-3-ethernet.s390-options: -- +802-3-ethernet.wake-on-lan: default +802-3-ethernet.wake-on-lan-password: -- +ipv4.method: auto +ipv4.dns: -- +ipv4.dns-search: -- +ipv4.dns-options: -- +ipv4.dns-priority: 0 +ipv4.addresses: -- +ipv4.gateway: -- +ipv4.routes: -- +ipv4.route-metric: -1 +ipv4.route-table: 0 (unspec) +ipv4.routing-rules: -- +ipv4.ignore-auto-routes: no +ipv4.ignore-auto-dns: no +ipv4.dhcp-client-id: -- +ipv4.dhcp-iaid: -- +ipv4.dhcp-timeout: 0 (default) +ipv4.dhcp-send-hostname: yes +ipv4.dhcp-hostname: -- +ipv4.dhcp-fqdn: -- +ipv4.dhcp-hostname-flags: 0x0 (none) +ipv4.never-default: no +ipv4.may-fail: yes +ipv4.dad-timeout: -1 (default) +ipv6.method: auto +ipv6.dns: -- +ipv6.dns-search: -- +ipv6.dns-options: -- +ipv6.dns-priority: 0 +ipv6.addresses: -- +ipv6.gateway: -- +ipv6.routes: -- +ipv6.route-metric: -1 +ipv6.route-table: 0 (unspec) +ipv6.routing-rules: -- +ipv6.ignore-auto-routes: no +ipv6.ignore-auto-dns: no +ipv6.never-default: no +ipv6.may-fail: yes +ipv6.ip6-privacy: -1 (unknown) +ipv6.addr-gen-mode: stable-privacy +ipv6.ra-timeout: 0 (default) +ipv6.dhcp-duid: -- +ipv6.dhcp-iaid: -- +ipv6.dhcp-timeout: 0 (default) +ipv6.dhcp-send-hostname: yes +ipv6.dhcp-hostname: -- +ipv6.dhcp-hostname-flags: 0x0 (none) +ipv6.token: -- +proxy.method: none +proxy.browser-only: no +proxy.pac-url: -- +proxy.pac-script: -- +GENERAL.NAME: ens33 +GENERAL.UUID: fbea23dd-6738-403f-b3a5-5d4a3444216a +GENERAL.DEVICES: ens33 +GENERAL.IP-IFACE: ens33 +GENERAL.STATE: activated +GENERAL.DEFAULT: yes +GENERAL.DEFAULT6: yes +GENERAL.SPEC-OBJECT: -- +GENERAL.VPN: no +GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/2 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/1 +GENERAL.ZONE: -- +GENERAL.MASTER-PATH: -- +IP4.ADDRESS[1]: 10.0.0.178/24 +IP4.GATEWAY: 10.0.0.1 +IP4.ROUTE[1]: dst = 0.0.0.0/0, nh = 10.0.0.1, mt = 100 +IP4.ROUTE[2]: dst = 10.0.0.0/24, nh = 0.0.0.0, mt = 100 +IP4.DNS[1]: 75.75.75.75 +IP4.DNS[2]: 75.75.76.76 +IP4.DOMAIN[1]: hsd1.ca.comcast.net +DHCP4.OPTION[1]: dhcp_lease_time = 172800 +DHCP4.OPTION[2]: domain_name = hsd1.ca.comcast.net +DHCP4.OPTION[3]: domain_name_servers = 75.75.75.75 75.75.76.76 +DHCP4.OPTION[4]: expiry = 1646191487 +DHCP4.OPTION[5]: ip_address = 10.0.0.178 +DHCP4.OPTION[6]: next_server = 10.0.0.1 +DHCP4.OPTION[7]: requested_broadcast_address = 1 +DHCP4.OPTION[8]: requested_domain_name = 1 +DHCP4.OPTION[9]: requested_domain_name_servers = 1 +DHCP4.OPTION[10]: requested_domain_search = 1 +DHCP4.OPTION[11]: requested_host_name = 1 +DHCP4.OPTION[12]: requested_interface_mtu = 1 +DHCP4.OPTION[13]: requested_ms_classless_static_routes = 1 +DHCP4.OPTION[14]: requested_nis_domain = 1 +DHCP4.OPTION[15]: requested_nis_servers = 1 +DHCP4.OPTION[16]: requested_ntp_servers = 1 +DHCP4.OPTION[17]: requested_rfc3442_classless_static_routes = 1 +DHCP4.OPTION[18]: requested_root_path = 1 +DHCP4.OPTION[19]: requested_routers = 1 +DHCP4.OPTION[20]: requested_static_routes = 1 +DHCP4.OPTION[21]: requested_subnet_mask = 1 +DHCP4.OPTION[22]: requested_time_offset = 1 +DHCP4.OPTION[23]: requested_wpad = 1 +DHCP4.OPTION[24]: routers = 10.0.0.1 +DHCP4.OPTION[25]: subnet_mask = 255.255.255.0 +IP6.ADDRESS[1]: 2601:641:482:9cc0::2d6d/128 +IP6.ADDRESS[2]: fe80::9263:6fcc:6db6:8b56/64 +IP6.GATEWAY: fe80::f88c:f4ff:fef1:d8f9 +IP6.ROUTE[1]: dst = fd29:95c1:bb51::/64, nh = fe80::1453:e8bf:c07a:2ca8, mt = 100 +IP6.ROUTE[2]: dst = 2601:641:482:9cc0::/60, nh = ::, mt = 100 +IP6.ROUTE[3]: dst = ::/0, nh = fe80::f88c:f4ff:fef1:d8f9, mt = 100 +IP6.ROUTE[4]: dst = ff00::/8, nh = ::, mt = 256, table=255 +IP6.ROUTE[5]: dst = fe80::/64, nh = ::, mt = 100 +IP6.ROUTE[6]: dst = 2601:641:482:9cc0::2d6d/128, nh = ::, mt = 100 +IP6.DNS[1]: 2001:558:feed::1 +IP6.DNS[2]: 2001:558:feed::2 +DHCP6.OPTION[1]: dhcp6_name_servers = 2001:558:feed::1 2001:558:feed::2 +DHCP6.OPTION[2]: ip6_address = 2601:641:482:9cc0::2d6d diff --git a/tests/fixtures/fedora32/nmcli-device-show-ens33.json b/tests/fixtures/fedora32/nmcli-device-show-ens33.json new file mode 100644 index 00000000..0f722b60 --- /dev/null +++ b/tests/fixtures/fedora32/nmcli-device-show-ens33.json @@ -0,0 +1 @@ +[{"device":"ens33","type":"ethernet","hwaddr":"00:0C:29:66:16:68","mtu":1500,"state":100,"state_text":"connected","connection":"ens33","con_path":"/org/freedesktop/NetworkManager/ActiveConnection/2","wired_properties_carrier":"on","ip4_address_1":"10.0.0.178/24","ip4_gateway":"10.0.0.1","ip4_route_1":{"dst":"0.0.0.0/0","nh":"10.0.0.1","mt":100},"ip4_route_2":{"dst":"10.0.0.0/24","nh":"0.0.0.0","mt":100},"ip4_dns_1":"75.75.75.75","ip4_dns_2":"75.75.76.76","ip4_domain_1":"hsd1.ca.comcast.net","ip6_address_1":"2601:641:482:9cc0::2d6d/128","ip6_address_2":"fe80::9263:6fcc:6db6:8b56/64","ip6_gateway":"fe80::f88c:f4ff:fef1:d8f9","ip6_route_1":{"dst":"fd29:95c1:bb51::/64","nh":"fe80::1453:e8bf:c07a:2ca8","mt":100},"ip6_route_2":{"dst":"2601:641:482:9cc0::/60","nh":"::","mt":100},"ip6_route_3":{"dst":"::/0","nh":"fe80::f88c:f4ff:fef1:d8f9","mt":100},"ip6_route_4":{"dst":"ff00::/8","nh":"::","mt":256,"table":255},"ip6_route_5":{"dst":"fe80::/64","nh":"::","mt":100},"ip6_route_6":{"dst":"2601:641:482:9cc0::2d6d/128","nh":"::","mt":100},"ip6_dns_1":"2001:558:feed::1","ip6_dns_2":"2001:558:feed::2"}] diff --git a/tests/fixtures/fedora32/nmcli-device-show-ens33.out b/tests/fixtures/fedora32/nmcli-device-show-ens33.out new file mode 100644 index 00000000..987d1b4f --- /dev/null +++ b/tests/fixtures/fedora32/nmcli-device-show-ens33.out @@ -0,0 +1,26 @@ +GENERAL.DEVICE: ens33 +GENERAL.TYPE: ethernet +GENERAL.HWADDR: 00:0C:29:66:16:68 +GENERAL.MTU: 1500 +GENERAL.STATE: 100 (connected) +GENERAL.CONNECTION: ens33 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/2 +WIRED-PROPERTIES.CARRIER: on +IP4.ADDRESS[1]: 10.0.0.178/24 +IP4.GATEWAY: 10.0.0.1 +IP4.ROUTE[1]: dst = 0.0.0.0/0, nh = 10.0.0.1, mt = 100 +IP4.ROUTE[2]: dst = 10.0.0.0/24, nh = 0.0.0.0, mt = 100 +IP4.DNS[1]: 75.75.75.75 +IP4.DNS[2]: 75.75.76.76 +IP4.DOMAIN[1]: hsd1.ca.comcast.net +IP6.ADDRESS[1]: 2601:641:482:9cc0::2d6d/128 +IP6.ADDRESS[2]: fe80::9263:6fcc:6db6:8b56/64 +IP6.GATEWAY: fe80::f88c:f4ff:fef1:d8f9 +IP6.ROUTE[1]: dst = fd29:95c1:bb51::/64, nh = fe80::1453:e8bf:c07a:2ca8, mt = 100 +IP6.ROUTE[2]: dst = 2601:641:482:9cc0::/60, nh = ::, mt = 100 +IP6.ROUTE[3]: dst = ::/0, nh = fe80::f88c:f4ff:fef1:d8f9, mt = 100 +IP6.ROUTE[4]: dst = ff00::/8, nh = ::, mt = 256, table=255 +IP6.ROUTE[5]: dst = fe80::/64, nh = ::, mt = 100 +IP6.ROUTE[6]: dst = 2601:641:482:9cc0::2d6d/128, nh = ::, mt = 100 +IP6.DNS[1]: 2001:558:feed::1 +IP6.DNS[2]: 2001:558:feed::2 diff --git a/tests/fixtures/fedora32/nmcli-device-show.json b/tests/fixtures/fedora32/nmcli-device-show.json new file mode 100644 index 00000000..9146c8fa --- /dev/null +++ b/tests/fixtures/fedora32/nmcli-device-show.json @@ -0,0 +1 @@ +[{"device":"ens33","type":"ethernet","hwaddr":"00:0C:29:66:16:68","mtu":1500,"state":100,"state_text":"connected","connection":"ens33","con_path":"/org/freedesktop/NetworkManager/ActiveConnection/2","wired_properties_carrier":"on","ip4_address_1":"10.0.0.178/24","ip4_gateway":"10.0.0.1","ip4_route_1":{"dst":"0.0.0.0/0","nh":"10.0.0.1","mt":100},"ip4_route_2":{"dst":"10.0.0.0/24","nh":"0.0.0.0","mt":100},"ip4_dns_1":"75.75.75.75","ip4_dns_2":"75.75.76.76","ip4_domain_1":"hsd1.ca.comcast.net","ip6_address_1":"2601:641:482:9cc0::2d6d/128","ip6_address_2":"fe80::9263:6fcc:6db6:8b56/64","ip6_gateway":"fe80::f88c:f4ff:fef1:d8f9","ip6_route_1":{"dst":"fd29:95c1:bb51::/64","nh":"fe80::1453:e8bf:c07a:2ca8","mt":100},"ip6_route_2":{"dst":"2601:641:482:9cc0::/60","nh":"::","mt":100},"ip6_route_3":{"dst":"::/0","nh":"fe80::f88c:f4ff:fef1:d8f9","mt":100},"ip6_route_4":{"dst":"ff00::/8","nh":"::","mt":256,"table":255},"ip6_route_5":{"dst":"fe80::/64","nh":"::","mt":100},"ip6_route_6":{"dst":"2601:641:482:9cc0::2d6d/128","nh":"::","mt":100},"ip6_dns_1":"2001:558:feed::1","ip6_dns_2":"2001:558:feed::2"},{"device":"lo","type":"loopback","hwaddr":"00:00:00:00:00:00","mtu":65536,"state":10,"state_text":"unmanaged","connection":null,"con_path":null,"ip4_address_1":"127.0.0.1/8","ip4_gateway":null,"ip6_address_1":"::1/128","ip6_gateway":null,"ip6_route_1":{"dst":"::1/128","nh":"::","mt":256}}] diff --git a/tests/fixtures/fedora32/nmcli-device-show.out b/tests/fixtures/fedora32/nmcli-device-show.out new file mode 100644 index 00000000..907d2786 --- /dev/null +++ b/tests/fixtures/fedora32/nmcli-device-show.out @@ -0,0 +1,39 @@ +GENERAL.DEVICE: ens33 +GENERAL.TYPE: ethernet +GENERAL.HWADDR: 00:0C:29:66:16:68 +GENERAL.MTU: 1500 +GENERAL.STATE: 100 (connected) +GENERAL.CONNECTION: ens33 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/2 +WIRED-PROPERTIES.CARRIER: on +IP4.ADDRESS[1]: 10.0.0.178/24 +IP4.GATEWAY: 10.0.0.1 +IP4.ROUTE[1]: dst = 0.0.0.0/0, nh = 10.0.0.1, mt = 100 +IP4.ROUTE[2]: dst = 10.0.0.0/24, nh = 0.0.0.0, mt = 100 +IP4.DNS[1]: 75.75.75.75 +IP4.DNS[2]: 75.75.76.76 +IP4.DOMAIN[1]: hsd1.ca.comcast.net +IP6.ADDRESS[1]: 2601:641:482:9cc0::2d6d/128 +IP6.ADDRESS[2]: fe80::9263:6fcc:6db6:8b56/64 +IP6.GATEWAY: fe80::f88c:f4ff:fef1:d8f9 +IP6.ROUTE[1]: dst = fd29:95c1:bb51::/64, nh = fe80::1453:e8bf:c07a:2ca8, mt = 100 +IP6.ROUTE[2]: dst = 2601:641:482:9cc0::/60, nh = ::, mt = 100 +IP6.ROUTE[3]: dst = ::/0, nh = fe80::f88c:f4ff:fef1:d8f9, mt = 100 +IP6.ROUTE[4]: dst = ff00::/8, nh = ::, mt = 256, table=255 +IP6.ROUTE[5]: dst = fe80::/64, nh = ::, mt = 100 +IP6.ROUTE[6]: dst = 2601:641:482:9cc0::2d6d/128, nh = ::, mt = 100 +IP6.DNS[1]: 2001:558:feed::1 +IP6.DNS[2]: 2001:558:feed::2 + +GENERAL.DEVICE: lo +GENERAL.TYPE: loopback +GENERAL.HWADDR: 00:00:00:00:00:00 +GENERAL.MTU: 65536 +GENERAL.STATE: 10 (unmanaged) +GENERAL.CONNECTION: -- +GENERAL.CON-PATH: -- +IP4.ADDRESS[1]: 127.0.0.1/8 +IP4.GATEWAY: -- +IP6.ADDRESS[1]: ::1/128 +IP6.GATEWAY: -- +IP6.ROUTE[1]: dst = ::1/128, nh = ::, mt = 256 diff --git a/tests/test_nmcli.py b/tests/test_nmcli.py index b0f75718..22248af1 100644 --- a/tests/test_nmcli.py +++ b/tests/test_nmcli.py @@ -44,6 +44,15 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-general-permissions.out'), 'r', encoding='utf-8') as f: self.centos_7_7_nmcli_general_permissions = f.read() + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/nmcli-connection-show-ens33.out'), 'r', encoding='utf-8') as f: + self.fedora32_nmcli_connection_show_ens33 = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/nmcli-device-show-ens33.out'), 'r', encoding='utf-8') as f: + self.fedora32_nmcli_device_show_ens33 = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/nmcli-device-show.out'), 'r', encoding='utf-8') as f: + self.fedora32_nmcli_device_show = f.read() + # output with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-connection-all.json'), 'r', encoding='utf-8') as f: @@ -76,6 +85,15 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-general-permissions.json'), 'r', encoding='utf-8') as f: self.centos_7_7_nmcli_general_permissions_json = json.loads(f.read()) + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/nmcli-connection-show-ens33.json'), 'r', encoding='utf-8') as f: + self.fedora32_nmcli_connection_show_ens33_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/nmcli-device-show-ens33.json'), 'r', encoding='utf-8') as f: + self.fedora32_nmcli_device_show_ens33_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/nmcli-device-show.json'), 'r', encoding='utf-8') as f: + self.fedora32_nmcli_device_show_json = json.loads(f.read()) + def test_nmcli_nodata(self): @@ -150,6 +168,24 @@ class MyTests(unittest.TestCase): """ self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_general_permissions, quiet=True), self.centos_7_7_nmcli_general_permissions_json) + def test_nmcli_connection_show_ens33_fedora32(self): + """ + Test 'nmcli connection show ens33' on fedora32 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.fedora32_nmcli_connection_show_ens33, quiet=True), self.fedora32_nmcli_connection_show_ens33_json) + + def test_nmcli_device_show_ens33_fedora32(self): + """ + Test 'nmcli device show ens33' on fedora32 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.fedora32_nmcli_device_show_ens33, quiet=True), self.fedora32_nmcli_device_show_ens33_json) + + def test_nmcli_device_show_ens33_fedora32(self): + """ + Test 'nmcli device show' on fedora32 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.fedora32_nmcli_device_show, quiet=True), self.fedora32_nmcli_device_show_json) + if __name__ == '__main__': unittest.main() From e2ffef57b9a474048fe72cf42aebfa6bfaf2e42b Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 28 Feb 2022 12:20:39 -0800 Subject: [PATCH 19/38] fix test --- tests/test_nmcli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_nmcli.py b/tests/test_nmcli.py index 22248af1..9091564f 100644 --- a/tests/test_nmcli.py +++ b/tests/test_nmcli.py @@ -180,7 +180,7 @@ class MyTests(unittest.TestCase): """ self.assertEqual(jc.parsers.nmcli.parse(self.fedora32_nmcli_device_show_ens33, quiet=True), self.fedora32_nmcli_device_show_ens33_json) - def test_nmcli_device_show_ens33_fedora32(self): + def test_nmcli_device_show_fedora32(self): """ Test 'nmcli device show' on fedora32 """ From d65f7ae992abc33140c00714d442290103661757 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 28 Feb 2022 12:26:06 -0800 Subject: [PATCH 20/38] add nmcli --- EXAMPLES.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/EXAMPLES.md b/EXAMPLES.md index a2f57254..943933db 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -2387,6 +2387,47 @@ netstat -i | jc --netstat -p # or: jc -p netstat -i } ] ``` +### nmcli +```bash +nmcli connection show ens33 | jc --nmcli -p # or jc -p nmcli connection show ens33 +``` +```json +[ + { + "connection_id": "ens33", + "connection_uuid": "d92ece08-9e02-47d5-b2d2-92c80e155744", + "connection_stable_id": null, + "connection_type": "802-3-ethernet", + "connection_interface_name": "ens33", + "connection_autoconnect": "yes", + "ip4_address_1": "192.168.71.180/24", + "ip4_gateway": "192.168.71.2", + "ip4_route_1": { + "dst": "0.0.0.0/0", + "nh": "192.168.71.2", + "mt": 100 + }, + "ip4_route_2": { + "dst": "192.168.71.0/24", + "nh": "0.0.0.0", + "mt": 100 + }, + "ip4_dns_1": "192.168.71.2", + "ip4_domain_1": "localdomain", + "dhcp4_option_1": { + "name": "broadcast_address", + "value": "192.168.71.255" + }, + "ip6_address_1": "fe80::c1cb:715d:bc3e:b8a0/64", + "ip6_gateway": null, + "ip6_route_1": { + "dst": "fe80::/64", + "nh": "::", + "mt": 100 + } + } + ] +``` ### ntpq ```bash ntpq -p | jc --ntpq -p # or: jc -p ntpq -p From ed205f7720d98c225c917c252ed7a6c9e6e8c2b8 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 28 Feb 2022 12:55:05 -0800 Subject: [PATCH 21/38] doc update --- docs/parsers/nmcli.md | 8 ++++---- jc/parsers/nmcli.py | 8 ++++---- man/jc.1 | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/parsers/nmcli.md b/docs/parsers/nmcli.md index 519d20fd..9d735c61 100644 --- a/docs/parsers/nmcli.md +++ b/docs/parsers/nmcli.md @@ -34,10 +34,10 @@ Usage (module): Schema: - Because there are so many options, the schema is best effort. Integer - and Float value conversions are attempted and the original values are - kept if they fail. If you don't want automatic conversion, then use the - -r or raw=True option to disable it. + Because there are so many options, the schema is not strictly defined. + Integer and Float value conversions are attempted and the original + values are kept if they fail. If you don't want automatic conversion, + then use the -r or raw=True option to disable it. The structure is flat, for the most part, but there are a couple of "well-known" keys that are further parsed into objects for convenience. diff --git a/jc/parsers/nmcli.py b/jc/parsers/nmcli.py index 794e95b5..f7be36cd 100644 --- a/jc/parsers/nmcli.py +++ b/jc/parsers/nmcli.py @@ -29,10 +29,10 @@ Usage (module): Schema: - Because there are so many options, the schema is best effort. Integer - and Float value conversions are attempted and the original values are - kept if they fail. If you don't want automatic conversion, then use the - -r or raw=True option to disable it. + Because there are so many options, the schema is not strictly defined. + Integer and Float value conversions are attempted and the original + values are kept if they fail. If you don't want automatic conversion, + then use the -r or raw=True option to disable it. The structure is flat, for the most part, but there are a couple of "well-known" keys that are further parsed into objects for convenience. diff --git a/man/jc.1 b/man/jc.1 index b7298fda..2f99e9fb 100644 --- a/man/jc.1 +++ b/man/jc.1 @@ -1,4 +1,4 @@ -.TH jc 1 2022-02-24 1.18.4 "JSON CLI output utility" +.TH jc 1 2022-02-28 1.18.4 "JSON CLI output utility" .SH NAME jc \- JSONifies the output of many CLI tools and file-types .SH SYNOPSIS From 8c8afc1a922e3c30fcf501d169b33a68b65cd3e0 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Wed, 2 Mar 2022 10:15:01 -0800 Subject: [PATCH 22/38] formatting --- docs/readme.md | 42 ++++++++++++++++++++++++++++++------------ jc/__init__.py | 42 ++++++++++++++++++++++++++++++------------ 2 files changed, 60 insertions(+), 24 deletions(-) diff --git a/docs/readme.md b/docs/readme.md index 7410dd4f..13c93812 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -57,29 +57,47 @@ modules directly: ## Available Functions -Use `help(jc.lib)` for details: +Use `help(jc.lib)` for details. + +### parse() parse(parser_module_name: str, data: str | Iterable) -> dict | list[dict] | Iterable[dict] - High-level API to easily access the parser. This API will find both - built-in parsers and local plugin parsers. + +High-level API to easily access the parser. This API will find both +built-in parsers and local plugin parsers. + +### parser_info() parser_info(parser_module_name: str) -> dict - Get the metadata for a particular parser. + +Get the metadata for a particular parser. + +### all_parser_info() all_parser_info() -> list[dict] - Get the metadata for all parsers. + +Get the metadata for all parsers. + +### get_help() get_help(parser_module_name: str) -> None - Convenience function to display the help screen for a parser using - its module name. + +Convenience function to display the help screen for a parser using +its module name. + +### parser_mod_list() parser_mod_list() -> list - Get a list of all available parser module names to be used in - parse(), parser_info(), and get_help(). + +Get a list of all available parser module names to be used in +`parse()`, `parser_info()`, and `get_help()`. + +### plugin_parser_mod_list() plugin_parser_mod_list() -> list - Get a list of plugin parser module names to be used in - parse(), parser_info(), and get_help(). This list is a subset of - parser_mod_list(). + +Get a list of plugin parser module names to be used in +`parse()`, `parser_info()`, and `get_help()`. This list is a subset of +`parser_mod_list()`. diff --git a/jc/__init__.py b/jc/__init__.py index a59ba5b2..7b6b6a04 100644 --- a/jc/__init__.py +++ b/jc/__init__.py @@ -53,31 +53,49 @@ modules directly: ## Available Functions -Use `help(jc.lib)` for details: +Use `help(jc.lib)` for details. + +### parse() parse(parser_module_name: str, data: str | Iterable) -> dict | list[dict] | Iterable[dict] - High-level API to easily access the parser. This API will find both - built-in parsers and local plugin parsers. + +High-level API to easily access the parser. This API will find both +built-in parsers and local plugin parsers. + +### parser_info() parser_info(parser_module_name: str) -> dict - Get the metadata for a particular parser. + +Get the metadata for a particular parser. + +### all_parser_info() all_parser_info() -> list[dict] - Get the metadata for all parsers. + +Get the metadata for all parsers. + +### get_help() get_help(parser_module_name: str) -> None - Convenience function to display the help screen for a parser using - its module name. + +Convenience function to display the help screen for a parser using +its module name. + +### parser_mod_list() parser_mod_list() -> list - Get a list of all available parser module names to be used in - parse(), parser_info(), and get_help(). + +Get a list of all available parser module names to be used in +`parse()`, `parser_info()`, and `get_help()`. + +### plugin_parser_mod_list() plugin_parser_mod_list() -> list - Get a list of plugin parser module names to be used in - parse(), parser_info(), and get_help(). This list is a subset of - parser_mod_list(). + +Get a list of plugin parser module names to be used in +`parse()`, `parser_info()`, and `get_help()`. This list is a subset of +`parser_mod_list()`. """ from .lib import (__version__, parse, parser_mod_list, plugin_parser_mod_list, parser_info, all_parser_info, get_help) From 4a1ee151b3cb054d84cd964fd62f5855f765751d Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Wed, 2 Mar 2022 10:57:09 -0800 Subject: [PATCH 23/38] add dhcp6 options to docs --- docs/parsers/nmcli.md | 4 ++++ jc/parsers/nmcli.py | 16 +++++----------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/docs/parsers/nmcli.md b/docs/parsers/nmcli.md index 9d735c61..518f24bf 100644 --- a/docs/parsers/nmcli.md +++ b/docs/parsers/nmcli.md @@ -50,6 +50,10 @@ Schema: "name": string, "value": string/integer/float, }, + "dhcp6_option_x": { + "name": string, + "value": string/integer/float, + }, "ip4_route_x": { "dst": string, "nh": string, diff --git a/jc/parsers/nmcli.py b/jc/parsers/nmcli.py index f7be36cd..d71575a4 100644 --- a/jc/parsers/nmcli.py +++ b/jc/parsers/nmcli.py @@ -45,6 +45,10 @@ Schema: "name": string, "value": string/integer/float, }, + "dhcp6_option_x": { + "name": string, + "value": string/integer/float, + }, "ip4_route_x": { "dst": string, "nh": string, @@ -185,17 +189,7 @@ def _process(proc_data: List[Dict]) -> List[Dict]: except Exception: pass - if '_option_' in key and key[-1].isdigit(): - for k in entry[key]: - try: - if '.' in entry[key][k]: - entry[key][k] = float(entry[key][k]) - else: - entry[key][k] = int(entry[key][k]) - except Exception: - pass - - if '_route_' in key and key[-1].isdigit(): + if ('_option_' in key or '_route_' in key) and key[-1].isdigit(): for k in entry[key]: try: if '.' in entry[key][k]: From 4758e28a36e2a55497e4f722d386a6b5cc30dc4d Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Wed, 2 Mar 2022 15:24:18 -0800 Subject: [PATCH 24/38] formatting --- docs/readme.md | 18 ++++++++++-------- jc/__init__.py | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/docs/readme.md b/docs/readme.md index 13c93812..c5387f75 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -59,41 +59,43 @@ modules directly: Use `help(jc.lib)` for details. -### parse() +### parse - parse(parser_module_name: str, data: str | Iterable) - -> dict | list[dict] | Iterable[dict] + parse( + parser_module_name: str, + data: str | Iterable + ) -> dict | list[dict] | Iterable[dict] High-level API to easily access the parser. This API will find both built-in parsers and local plugin parsers. -### parser_info() +### parser_info parser_info(parser_module_name: str) -> dict Get the metadata for a particular parser. -### all_parser_info() +### all_parser_info all_parser_info() -> list[dict] Get the metadata for all parsers. -### get_help() +### get_help get_help(parser_module_name: str) -> None Convenience function to display the help screen for a parser using its module name. -### parser_mod_list() +### parser_mod_list parser_mod_list() -> list Get a list of all available parser module names to be used in `parse()`, `parser_info()`, and `get_help()`. -### plugin_parser_mod_list() +### plugin_parser_mod_list plugin_parser_mod_list() -> list diff --git a/jc/__init__.py b/jc/__init__.py index 7b6b6a04..ca1f952a 100644 --- a/jc/__init__.py +++ b/jc/__init__.py @@ -55,41 +55,43 @@ modules directly: Use `help(jc.lib)` for details. -### parse() +### parse - parse(parser_module_name: str, data: str | Iterable) - -> dict | list[dict] | Iterable[dict] + parse( + parser_module_name: str, + data: str | Iterable + ) -> dict | list[dict] | Iterable[dict] High-level API to easily access the parser. This API will find both built-in parsers and local plugin parsers. -### parser_info() +### parser_info parser_info(parser_module_name: str) -> dict Get the metadata for a particular parser. -### all_parser_info() +### all_parser_info all_parser_info() -> list[dict] Get the metadata for all parsers. -### get_help() +### get_help get_help(parser_module_name: str) -> None Convenience function to display the help screen for a parser using its module name. -### parser_mod_list() +### parser_mod_list parser_mod_list() -> list Get a list of all available parser module names to be used in `parse()`, `parser_info()`, and `get_help()`. -### plugin_parser_mod_list() +### plugin_parser_mod_list plugin_parser_mod_list() -> list From 7ede7be7bf7b1a7d29d158b3b21c20fff4990e72 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 3 Mar 2022 17:36:40 -0800 Subject: [PATCH 25/38] add standard and streaming list functions --- jc/__init__.py | 17 +++++++++++++++++ jc/lib.py | 25 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/jc/__init__.py b/jc/__init__.py index ca1f952a..4d9f44ca 100644 --- a/jc/__init__.py +++ b/jc/__init__.py @@ -98,6 +98,23 @@ Get a list of all available parser module names to be used in Get a list of plugin parser module names to be used in `parse()`, `parser_info()`, and `get_help()`. This list is a subset of `parser_mod_list()`. + +### standard_parser_mod_list + + standard_parser_mod_list() -> list + +Get a list of standard parser module names to be used in +`parse()`, `parser_info()`, and `get_help()`. This list is a subset of +`parser_mod_list()` and does not contain any streaming parsers. + +### streaming_parser_mod_list + + streaming_parser_mod_list() -> list + +Get a list of streaming parser module names to be used in +`parse()`, `parser_info()`, and `get_help()`. This list is a subset of +`parser_mod_list()`. """ from .lib import (__version__, parse, parser_mod_list, plugin_parser_mod_list, + standard_parser_mod_list, streaming_parser_mod_list, parser_info, all_parser_info, get_help) diff --git a/jc/lib.py b/jc/lib.py index 18c96d5f..b8403c96 100644 --- a/jc/lib.py +++ b/jc/lib.py @@ -228,6 +228,31 @@ def plugin_parser_mod_list() -> List[str]: """ return [_cliname_to_modname(p) for p in local_parsers] +def standard_parser_mod_list() -> List[str]: + """ + Returns a list of standard parser module names. This function is a + subset of `parser_mod_list()` and does not contain any streaming + parsers. + """ + plist = [] + for p in parsers: + parser = _get_parser(p) + if not getattr(parser.info, 'streaming', None): + plist.append(p) + return plist + +def streaming_parser_mod_list() -> List[str]: + """ + Returns a list of streaming parser module names. This function is a + subset of `parser_mod_list()`. + """ + plist = [] + for p in parsers: + parser = _get_parser(p) + if getattr(parser.info, 'streaming', None): + plist.append(p) + return plist + def parser_info(parser_mod_name: str) -> Dict: """ Returns a dictionary that includes the module metadata. From e49df7208377ab34a74240a06f35f17fee4b8203 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 3 Mar 2022 17:37:01 -0800 Subject: [PATCH 26/38] use streaming parser list to find streaming parsers --- jc/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jc/cli.py b/jc/cli.py index b3644720..02359ec7 100644 --- a/jc/cli.py +++ b/jc/cli.py @@ -11,7 +11,7 @@ import shlex import subprocess import json from .lib import (__version__, all_parser_info, parsers, - _parser_argument, _get_parser) + _parser_argument, _get_parser, streaming_parser_mod_list) from . import utils from . import tracebackplus from .exceptions import LibraryNotInstalled, ParseError @@ -502,7 +502,7 @@ def main(): # differentiate between regular and streaming parsers # streaming - if getattr(parser.info, 'streaming', None): + if parser_name in streaming_parser_mod_list(): result = parser.parse(sys.stdin, raw=raw, quiet=quiet, From 6be3d3d98222a262c5138bb09f2951ccfab96110 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 3 Mar 2022 17:38:47 -0800 Subject: [PATCH 27/38] doc update --- CHANGELOG | 3 ++- docs/lib.md | 25 +++++++++++++++++++++++++ docs/readme.md | 16 ++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 229b55df..a3b291e9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,8 +1,9 @@ jc changelog -20220224 v1.18.4 +20220303 v1.18.4 - Add nmcli command parser tested on linux - Enhance parse error messages at the cli +- Add standard and streaming parser list functions to the public API 20220214 v1.18.3 - Add rsync command and log file parser tested on linux and macOS diff --git a/docs/lib.md b/docs/lib.md index 6b79fe1d..e3fad7fa 100644 --- a/docs/lib.md +++ b/docs/lib.md @@ -4,6 +4,8 @@ * [parse](#jc.lib.parse) * [parser\_mod\_list](#jc.lib.parser_mod_list) * [plugin\_parser\_mod\_list](#jc.lib.plugin_parser_mod_list) + * [standard\_parser\_mod\_list](#jc.lib.standard_parser_mod_list) + * [streaming\_parser\_mod\_list](#jc.lib.streaming_parser_mod_list) * [parser\_info](#jc.lib.parser_info) * [all\_parser\_info](#jc.lib.all_parser_info) * [get\_help](#jc.lib.get_help) @@ -100,6 +102,29 @@ def plugin_parser_mod_list() -> List[str] Returns a list of plugin parser module names. This function is a subset of `parser_mod_list()`. + + +### standard\_parser\_mod\_list + +```python +def standard_parser_mod_list() -> List[str] +``` + +Returns a list of standard parser module names. This function is a +subset of `parser_mod_list()` and does not contain any streaming +parsers. + + + +### streaming\_parser\_mod\_list + +```python +def streaming_parser_mod_list() -> List[str] +``` + +Returns a list of streaming parser module names. This function is a +subset of `parser_mod_list()`. + ### parser\_info diff --git a/docs/readme.md b/docs/readme.md index c5387f75..e5c3d8ec 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -103,3 +103,19 @@ Get a list of plugin parser module names to be used in `parse()`, `parser_info()`, and `get_help()`. This list is a subset of `parser_mod_list()`. +### standard_parser_mod_list + + standard_parser_mod_list() -> list + +Get a list of standard parser module names to be used in +`parse()`, `parser_info()`, and `get_help()`. This list is a subset of +`parser_mod_list()` and does not contain any streaming parsers. + +### streaming_parser_mod_list + + streaming_parser_mod_list() -> list + +Get a list of streaming parser module names to be used in +`parse()`, `parser_info()`, and `get_help()`. This list is a subset of +`parser_mod_list()`. + From a9f53ee258e18bc90934e263d8dc96feee84e939 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 3 Mar 2022 17:50:19 -0800 Subject: [PATCH 28/38] optimize streaming parser detection in cli --- jc/cli.py | 4 ++-- jc/lib.py | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/jc/cli.py b/jc/cli.py index 02359ec7..6dd1a147 100644 --- a/jc/cli.py +++ b/jc/cli.py @@ -11,7 +11,7 @@ import shlex import subprocess import json from .lib import (__version__, all_parser_info, parsers, - _parser_argument, _get_parser, streaming_parser_mod_list) + _parser_argument, _get_parser, _parser_is_streaming) from . import utils from . import tracebackplus from .exceptions import LibraryNotInstalled, ParseError @@ -502,7 +502,7 @@ def main(): # differentiate between regular and streaming parsers # streaming - if parser_name in streaming_parser_mod_list(): + if _parser_is_streaming(parser): result = parser.parse(sys.stdin, raw=raw, quiet=quiet, diff --git a/jc/lib.py b/jc/lib.py index b8403c96..72b34d30 100644 --- a/jc/lib.py +++ b/jc/lib.py @@ -144,6 +144,17 @@ def _get_parser(parser_mod_name): modpath = 'jcparsers.' if parser_cli_name in local_parsers else 'jc.parsers.' return importlib.import_module(f'{modpath}{parser_mod_name}') +def _parser_is_streaming(parser): + """ + Returns True if this is a streaming parser, else False + + parser is a parser module object. + """ + if getattr(parser.info, 'streaming', None): + return True + + return False + def parse( parser_mod_name: str, data: Union[str, Iterable[str]], @@ -237,7 +248,7 @@ def standard_parser_mod_list() -> List[str]: plist = [] for p in parsers: parser = _get_parser(p) - if not getattr(parser.info, 'streaming', None): + if not _parser_is_streaming(parser): plist.append(p) return plist @@ -249,7 +260,7 @@ def streaming_parser_mod_list() -> List[str]: plist = [] for p in parsers: parser = _get_parser(p) - if getattr(parser.info, 'streaming', None): + if _parser_is_streaming(parser): plist.append(p) return plist From 9a3602e70b865a3015bd700b30d1076e17511a9b Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Fri, 4 Mar 2022 08:57:11 -0800 Subject: [PATCH 29/38] doc update --- docs/lib.md | 4 +--- jc/lib.py | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/docs/lib.md b/docs/lib.md index e3fad7fa..b659b66d 100644 --- a/docs/lib.md +++ b/docs/lib.md @@ -36,9 +36,7 @@ Example: >>> jc.parse('date', 'Tue Jan 18 10:23:07 PST 2022') {'year': 2022, 'month': 'Jan', 'month_num': 1, 'day'...} -To get a list of available parser module names, use `parser_mod_list()` -or `plugin_parser_mod_list()`. `plugin_parser_mod_list()` is a subset -of `parser_mod_list()`. +To get a list of available parser module names, use `parser_mod_list()`. You can also use the lower-level parser modules directly: diff --git a/jc/lib.py b/jc/lib.py index 72b34d30..4252b864 100644 --- a/jc/lib.py +++ b/jc/lib.py @@ -175,9 +175,7 @@ def parse( >>> jc.parse('date', 'Tue Jan 18 10:23:07 PST 2022') {'year': 2022, 'month': 'Jan', 'month_num': 1, 'day'...} - To get a list of available parser module names, use `parser_mod_list()` - or `plugin_parser_mod_list()`. `plugin_parser_mod_list()` is a subset - of `parser_mod_list()`. + To get a list of available parser module names, use `parser_mod_list()`. You can also use the lower-level parser modules directly: From cb2dfeac8d44b733ad9d364e8c6d233a381bfae1 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Fri, 4 Mar 2022 13:27:39 -0800 Subject: [PATCH 30/38] change name to JSON Convert --- README.md | 4 +--- docgen.sh | 6 +++--- docs/lib.md | 25 +++++++++++++++---------- docs/parsers/acpi.md | 4 ++-- docs/parsers/airport.md | 4 ++-- docs/parsers/airport_s.md | 4 ++-- docs/parsers/arp.md | 4 ++-- docs/parsers/blkid.md | 4 ++-- docs/parsers/cksum.md | 4 ++-- docs/parsers/crontab.md | 4 ++-- docs/parsers/crontab_u.md | 4 ++-- docs/parsers/csv.md | 4 ++-- docs/parsers/csv_s.md | 4 ++-- docs/parsers/date.md | 4 ++-- docs/parsers/df.md | 4 ++-- docs/parsers/dig.md | 4 ++-- docs/parsers/dir.md | 4 ++-- docs/parsers/dmidecode.md | 4 ++-- docs/parsers/dpkg_l.md | 4 ++-- docs/parsers/du.md | 4 ++-- docs/parsers/env.md | 4 ++-- docs/parsers/file.md | 4 ++-- docs/parsers/finger.md | 4 ++-- docs/parsers/free.md | 4 ++-- docs/parsers/fstab.md | 4 ++-- docs/parsers/group.md | 4 ++-- docs/parsers/gshadow.md | 4 ++-- docs/parsers/hash.md | 4 ++-- docs/parsers/hashsum.md | 4 ++-- docs/parsers/hciconfig.md | 4 ++-- docs/parsers/history.md | 4 ++-- docs/parsers/hosts.md | 4 ++-- docs/parsers/id.md | 4 ++-- docs/parsers/ifconfig.md | 4 ++-- docs/parsers/ini.md | 4 ++-- docs/parsers/iostat.md | 4 ++-- docs/parsers/iostat_s.md | 4 ++-- docs/parsers/iptables.md | 4 ++-- docs/parsers/iw_scan.md | 4 ++-- docs/parsers/jar_manifest.md | 4 ++-- docs/parsers/jobs.md | 4 ++-- docs/parsers/kv.md | 4 ++-- docs/parsers/last.md | 4 ++-- docs/parsers/ls.md | 4 ++-- docs/parsers/ls_s.md | 4 ++-- docs/parsers/lsblk.md | 4 ++-- docs/parsers/lsmod.md | 4 ++-- docs/parsers/lsof.md | 4 ++-- docs/parsers/lsusb.md | 4 ++-- docs/parsers/mount.md | 4 ++-- docs/parsers/netstat.md | 4 ++-- docs/parsers/nmcli.md | 4 ++-- docs/parsers/ntpq.md | 4 ++-- docs/parsers/passwd.md | 4 ++-- docs/parsers/ping.md | 4 ++-- docs/parsers/ping_s.md | 4 ++-- docs/parsers/pip_list.md | 4 ++-- docs/parsers/pip_show.md | 4 ++-- docs/parsers/ps.md | 4 ++-- docs/parsers/route.md | 4 ++-- docs/parsers/rpm_qi.md | 4 ++-- docs/parsers/rsync.md | 4 ++-- docs/parsers/rsync_s.md | 9 ++++++--- docs/parsers/sfdisk.md | 4 ++-- docs/parsers/shadow.md | 4 ++-- docs/parsers/ss.md | 4 ++-- docs/parsers/stat.md | 4 ++-- docs/parsers/stat_s.md | 4 ++-- docs/parsers/sysctl.md | 4 ++-- docs/parsers/systemctl.md | 4 ++-- docs/parsers/systemctl_lj.md | 4 ++-- docs/parsers/systemctl_ls.md | 4 ++-- docs/parsers/systemctl_luf.md | 4 ++-- docs/parsers/systeminfo.md | 4 ++-- docs/parsers/time.md | 4 ++-- docs/parsers/timedatectl.md | 4 ++-- docs/parsers/tracepath.md | 4 ++-- docs/parsers/traceroute.md | 4 ++-- docs/parsers/ufw.md | 4 ++-- docs/parsers/ufw_appinfo.md | 4 ++-- docs/parsers/uname.md | 4 ++-- docs/parsers/universal.md | 6 +++--- docs/parsers/upower.md | 4 ++-- docs/parsers/uptime.md | 4 ++-- docs/parsers/vmstat.md | 4 ++-- docs/parsers/vmstat_s.md | 4 ++-- docs/parsers/w.md | 4 ++-- docs/parsers/wc.md | 4 ++-- docs/parsers/who.md | 4 ++-- docs/parsers/xml.md | 4 ++-- docs/parsers/xrandr.md | 4 ++-- docs/parsers/yaml.md | 4 ++-- docs/parsers/zipinfo.md | 4 ++-- docs/readme.md | 2 +- docs/streaming.md | 17 +++++++++-------- docs/utils.md | 29 ++++++++++++++++------------- jc/__init__.py | 2 +- jc/cli.py | 4 ++-- jc/exceptions.py | 2 +- jc/lib.py | 2 +- jc/parsers/acpi.py | 2 +- jc/parsers/airport.py | 2 +- jc/parsers/airport_s.py | 2 +- jc/parsers/arp.py | 2 +- jc/parsers/blkid.py | 2 +- jc/parsers/cksum.py | 2 +- jc/parsers/crontab.py | 2 +- jc/parsers/crontab_u.py | 2 +- jc/parsers/csv.py | 2 +- jc/parsers/csv_s.py | 2 +- jc/parsers/date.py | 2 +- jc/parsers/df.py | 2 +- jc/parsers/dig.py | 2 +- jc/parsers/dir.py | 2 +- jc/parsers/dmidecode.py | 2 +- jc/parsers/dpkg_l.py | 2 +- jc/parsers/du.py | 2 +- jc/parsers/env.py | 2 +- jc/parsers/file.py | 2 +- jc/parsers/finger.py | 2 +- jc/parsers/foo.py | 2 +- jc/parsers/foo_s.py | 2 +- jc/parsers/free.py | 2 +- jc/parsers/fstab.py | 2 +- jc/parsers/group.py | 2 +- jc/parsers/gshadow.py | 2 +- jc/parsers/hash.py | 2 +- jc/parsers/hashsum.py | 2 +- jc/parsers/hciconfig.py | 2 +- jc/parsers/history.py | 2 +- jc/parsers/hosts.py | 2 +- jc/parsers/id.py | 2 +- jc/parsers/ifconfig.py | 2 +- jc/parsers/ini.py | 2 +- jc/parsers/iostat.py | 2 +- jc/parsers/iostat_s.py | 2 +- jc/parsers/iptables.py | 2 +- jc/parsers/iw_scan.py | 2 +- jc/parsers/jar_manifest.py | 2 +- jc/parsers/jobs.py | 2 +- jc/parsers/kv.py | 2 +- jc/parsers/last.py | 2 +- jc/parsers/ls.py | 2 +- jc/parsers/ls_s.py | 2 +- jc/parsers/lsblk.py | 2 +- jc/parsers/lsmod.py | 2 +- jc/parsers/lsof.py | 2 +- jc/parsers/lsusb.py | 2 +- jc/parsers/mount.py | 2 +- jc/parsers/netstat.py | 2 +- jc/parsers/netstat_freebsd_osx.py | 2 +- jc/parsers/netstat_linux.py | 2 +- jc/parsers/nmcli.py | 2 +- jc/parsers/ntpq.py | 2 +- jc/parsers/passwd.py | 2 +- jc/parsers/ping.py | 2 +- jc/parsers/ping_s.py | 2 +- jc/parsers/pip_list.py | 2 +- jc/parsers/pip_show.py | 2 +- jc/parsers/ps.py | 2 +- jc/parsers/route.py | 2 +- jc/parsers/rpm_qi.py | 2 +- jc/parsers/rsync.py | 2 +- jc/parsers/rsync_s.py | 2 +- jc/parsers/sfdisk.py | 2 +- jc/parsers/shadow.py | 2 +- jc/parsers/ss.py | 2 +- jc/parsers/stat.py | 2 +- jc/parsers/stat_s.py | 2 +- jc/parsers/sysctl.py | 2 +- jc/parsers/systemctl.py | 2 +- jc/parsers/systemctl_lj.py | 2 +- jc/parsers/systemctl_ls.py | 2 +- jc/parsers/systemctl_luf.py | 2 +- jc/parsers/systeminfo.py | 2 +- jc/parsers/time.py | 2 +- jc/parsers/timedatectl.py | 2 +- jc/parsers/tracepath.py | 2 +- jc/parsers/traceroute.py | 2 +- jc/parsers/ufw.py | 2 +- jc/parsers/ufw_appinfo.py | 2 +- jc/parsers/uname.py | 2 +- jc/parsers/universal.py | 2 +- jc/parsers/upower.py | 2 +- jc/parsers/uptime.py | 2 +- jc/parsers/vmstat.py | 2 +- jc/parsers/vmstat_s.py | 2 +- jc/parsers/w.py | 2 +- jc/parsers/wc.py | 2 +- jc/parsers/who.py | 2 +- jc/parsers/xml.py | 2 +- jc/parsers/xrandr.py | 2 +- jc/parsers/yaml.py | 2 +- jc/parsers/zipinfo.py | 2 +- jc/streaming.py | 2 +- jc/utils.py | 2 +- man/jc.1 | 2 +- templates/manpage_template | 2 +- templates/readme_template | 4 +--- 199 files changed, 334 insertions(+), 326 deletions(-) diff --git a/README.md b/README.md index 3278bd36..42b194d1 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ ![Tests](https://github.com/kellyjonbrazil/jc/workflows/Tests/badge.svg?branch=master) ![Pypi](https://img.shields.io/pypi/v/jc.svg) -> `jc` was recently featured in the [Console Open Source Newsletter](https://console.substack.com/p/console-89) - > Check out the `jc` Python [package documentation](https://github.com/kellyjonbrazil/jc/tree/master/docs) for developers > Try the `jc` [web demo](https://jc-web-demo.herokuapp.com/) @@ -13,7 +11,7 @@ Ansible filter plugin in the `community.general` collection. See this for an example. # JC -JSON CLI output utility +JSON Convert `jc` JSONifies the output of many CLI tools and file-types for easier parsing in scripts. See the [**Parsers**](#parsers) section for supported commands and diff --git a/docgen.sh b/docgen.sh index 38495775..8b2b272d 100755 --- a/docgen.sh +++ b/docgen.sh @@ -18,7 +18,7 @@ readme_config=$(cat <<'EOF' "Class": 3, "Method": 3, "Function": 3, - "Data": 3 + "Variable": 3 } } } @@ -43,7 +43,7 @@ toc_config=$(cat <<'EOF' "Class": 3, "Method": 3, "Function": 3, - "Data": 3 + "Variable": 3 } } } @@ -68,7 +68,7 @@ parser_config=$(cat <<'EOF' "Class": 3, "Method": 3, "Function": 3, - "Data": 3 + "Variable": 3 } } } diff --git a/docs/lib.md b/docs/lib.md index b659b66d..67e5ea34 100644 --- a/docs/lib.md +++ b/docs/lib.md @@ -14,15 +14,20 @@ # jc.lib -jc - JSON CLI output utility +jc - JSON Convert JC lib module -### parse +#### parse ```python -def parse(parser_mod_name: str, data: Union[str, Iterable[str]], quiet: bool = False, raw: bool = False, ignore_exceptions: bool = None, **kwargs) -> Union[Dict, List[Dict], Iterator[Dict]] +def parse(parser_mod_name: str, + data: Union[str, Iterable[str]], + quiet: bool = False, + raw: bool = False, + ignore_exceptions: bool = None, + **kwargs) -> Union[Dict, List[Dict], Iterator[Dict]] ``` Parse the string data using the supplied parser module. @@ -81,7 +86,7 @@ Returns: -### parser\_mod\_list +#### parser\_mod\_list ```python def parser_mod_list() -> List[str] @@ -91,7 +96,7 @@ Returns a list of all available parser module names. -### plugin\_parser\_mod\_list +#### plugin\_parser\_mod\_list ```python def plugin_parser_mod_list() -> List[str] @@ -102,7 +107,7 @@ subset of `parser_mod_list()`. -### standard\_parser\_mod\_list +#### standard\_parser\_mod\_list ```python def standard_parser_mod_list() -> List[str] @@ -114,7 +119,7 @@ parsers. -### streaming\_parser\_mod\_list +#### streaming\_parser\_mod\_list ```python def streaming_parser_mod_list() -> List[str] @@ -125,7 +130,7 @@ subset of `parser_mod_list()`. -### parser\_info +#### parser\_info ```python def parser_info(parser_mod_name: str) -> Dict @@ -138,7 +143,7 @@ This function will accept **module_name**, **cli-name**, and -### all\_parser\_info +#### all\_parser\_info ```python def all_parser_info() -> List[Dict] @@ -148,7 +153,7 @@ Returns a list of dictionaries that includes metadata for all modules. -### get\_help +#### get\_help ```python def get_help(parser_mod_name: str) -> None diff --git a/docs/parsers/acpi.md b/docs/parsers/acpi.md index d6adf5a8..e486954f 100644 --- a/docs/parsers/acpi.md +++ b/docs/parsers/acpi.md @@ -3,7 +3,7 @@ # jc.parsers.acpi -jc - JSON CLI output utility `acpi` command output parser +jc - JSON Convert `acpi` command output parser Usage (cli): @@ -234,7 +234,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/airport.md b/docs/parsers/airport.md index 24abb893..e9fa5490 100644 --- a/docs/parsers/airport.md +++ b/docs/parsers/airport.md @@ -3,7 +3,7 @@ # jc.parsers.airport -jc - JSON CLI output utility `airport -I` command output parser +jc - JSON Convert `airport -I` command output parser The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`. @@ -87,7 +87,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/airport_s.md b/docs/parsers/airport_s.md index ae9afae4..84b8e4a0 100644 --- a/docs/parsers/airport_s.md +++ b/docs/parsers/airport_s.md @@ -3,7 +3,7 @@ # jc.parsers.airport\_s -jc - JSON CLI output utility `airport -s` command output parser +jc - JSON Convert `airport -s` command output parser The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`. @@ -115,7 +115,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/arp.md b/docs/parsers/arp.md index 09ca6d08..136476b6 100644 --- a/docs/parsers/arp.md +++ b/docs/parsers/arp.md @@ -3,7 +3,7 @@ # jc.parsers.arp -jc - JSON CLI output utility `arp` command output parser +jc - JSON Convert `arp` command output parser Supports `arp` and `arp -a` output. @@ -124,7 +124,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/blkid.md b/docs/parsers/blkid.md index b94411f2..11f81041 100644 --- a/docs/parsers/blkid.md +++ b/docs/parsers/blkid.md @@ -3,7 +3,7 @@ # jc.parsers.blkid -jc - JSON CLI output utility `blkid` command output parser +jc - JSON Convert `blkid` command output parser Usage (cli): @@ -127,7 +127,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/cksum.md b/docs/parsers/cksum.md index 0ba7468e..aee5efc4 100644 --- a/docs/parsers/cksum.md +++ b/docs/parsers/cksum.md @@ -3,7 +3,7 @@ # jc.parsers.cksum -jc - JSON CLI output utility `cksum` command output parser +jc - JSON Convert `cksum` command output parser This parser works with the following checksum calculation utilities: - `sum` @@ -61,7 +61,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/crontab.md b/docs/parsers/crontab.md index d4f518b6..ae9c4c31 100644 --- a/docs/parsers/crontab.md +++ b/docs/parsers/crontab.md @@ -3,7 +3,7 @@ # jc.parsers.crontab -jc - JSON CLI output utility `crontab -l` command output and crontab +jc - JSON Convert `crontab -l` command output and crontab file parser Supports `crontab -l` command output and crontab files. @@ -180,7 +180,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/crontab_u.md b/docs/parsers/crontab_u.md index 718cb49a..bfcd45a6 100644 --- a/docs/parsers/crontab_u.md +++ b/docs/parsers/crontab_u.md @@ -3,7 +3,7 @@ # jc.parsers.crontab\_u -jc - JSON CLI output utility `crontab -l` command output and crontab +jc - JSON Convert `crontab -l` command output and crontab file parser This version of the `crontab -l` parser supports output that contains user @@ -177,7 +177,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/csv.md b/docs/parsers/csv.md index 95656d8e..d98a4945 100644 --- a/docs/parsers/csv.md +++ b/docs/parsers/csv.md @@ -3,7 +3,7 @@ # jc.parsers.csv -jc - JSON CLI output utility `csv` file parser +jc - JSON Convert `csv` file parser The `csv` parser will attempt to automatically detect the delimiter character. If the delimiter cannot be detected it will default to comma. @@ -84,7 +84,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/csv_s.md b/docs/parsers/csv_s.md index 6362a7a1..902d117b 100644 --- a/docs/parsers/csv_s.md +++ b/docs/parsers/csv_s.md @@ -3,7 +3,7 @@ # jc.parsers.csv\_s -jc - JSON CLI output utility `csv` file streaming parser +jc - JSON Convert `csv` file streaming parser > This streaming parser outputs JSON Lines @@ -70,7 +70,7 @@ Examples: -### parse +#### parse ```python @add_jc_meta diff --git a/docs/parsers/date.md b/docs/parsers/date.md index e4966ba9..d348d089 100644 --- a/docs/parsers/date.md +++ b/docs/parsers/date.md @@ -3,7 +3,7 @@ # jc.parsers.date -jc - JSON CLI output utility `date` command output parser +jc - JSON Convert `date` command output parser The `epoch` calculated timestamp field is naive. (i.e. based on the local time of the system the parser is run on) @@ -84,7 +84,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/df.md b/docs/parsers/df.md index 4e787857..25ee0773 100644 --- a/docs/parsers/df.md +++ b/docs/parsers/df.md @@ -3,7 +3,7 @@ # jc.parsers.df -jc - JSON CLI output utility `df` command output parser +jc - JSON Convert `df` command output parser Usage (cli): @@ -104,7 +104,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/dig.md b/docs/parsers/dig.md index d1459682..70bd67ea 100644 --- a/docs/parsers/dig.md +++ b/docs/parsers/dig.md @@ -3,7 +3,7 @@ # jc.parsers.dig -jc - JSON CLI output utility `dig` command output parser +jc - JSON Convert `dig` command output parser Options supported: - `+noall +answer` options are supported in cases where only the answer @@ -329,7 +329,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/dir.md b/docs/parsers/dir.md index 02e08ac5..84a76476 100644 --- a/docs/parsers/dir.md +++ b/docs/parsers/dir.md @@ -3,7 +3,7 @@ # jc.parsers.dir -jc - JSON CLI output utility `dir` command output parser +jc - JSON Convert `dir` command output parser Options supported: - `/T timefield` @@ -127,7 +127,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/dmidecode.md b/docs/parsers/dmidecode.md index 8591a534..a7664b6d 100644 --- a/docs/parsers/dmidecode.md +++ b/docs/parsers/dmidecode.md @@ -3,7 +3,7 @@ # jc.parsers.dmidecode -jc - JSON CLI output utility `dmidecode` command output parser +jc - JSON Convert `dmidecode` command output parser Usage (cli): @@ -132,7 +132,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/dpkg_l.md b/docs/parsers/dpkg_l.md index 0daa5f96..6b24634c 100644 --- a/docs/parsers/dpkg_l.md +++ b/docs/parsers/dpkg_l.md @@ -3,7 +3,7 @@ # jc.parsers.dpkg\_l -jc - JSON CLI output utility `dpkg -l` command output parser +jc - JSON Convert `dpkg -l` command output parser Set the `COLUMNS` environment variable to a large value to avoid field truncation. For example: @@ -138,7 +138,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/du.md b/docs/parsers/du.md index 6168bfda..12ec1ca4 100644 --- a/docs/parsers/du.md +++ b/docs/parsers/du.md @@ -3,7 +3,7 @@ # jc.parsers.du -jc - JSON CLI output utility `du` command output parser +jc - JSON Convert `du` command output parser Usage (cli): @@ -94,7 +94,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/env.md b/docs/parsers/env.md index 428f02d1..dd625602 100644 --- a/docs/parsers/env.md +++ b/docs/parsers/env.md @@ -3,7 +3,7 @@ # jc.parsers.env -jc - JSON CLI output utility `env` and `printenv` command output parser +jc - JSON Convert `env` and `printenv` command output parser This parser will output a list of dictionaries each containing `name` and `value` keys. If you would like a simple dictionary output, then use the @@ -79,7 +79,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/file.md b/docs/parsers/file.md index aefb2165..b95f0d29 100644 --- a/docs/parsers/file.md +++ b/docs/parsers/file.md @@ -3,7 +3,7 @@ # jc.parsers.file -jc - JSON CLI output utility `file` command output parser +jc - JSON Convert `file` command output parser Usage (cli): @@ -69,7 +69,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/finger.md b/docs/parsers/finger.md index a48edaa9..56daa2bc 100644 --- a/docs/parsers/finger.md +++ b/docs/parsers/finger.md @@ -3,7 +3,7 @@ # jc.parsers.finger -jc - JSON CLI output utility `finger` command output parser +jc - JSON Convert `finger` command output parser Supports `-s` output option. Does not support the `-l` detail option. @@ -97,7 +97,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/free.md b/docs/parsers/free.md index 4e3fa757..1b8fd722 100644 --- a/docs/parsers/free.md +++ b/docs/parsers/free.md @@ -3,7 +3,7 @@ # jc.parsers.free -jc - JSON CLI output utility `free` command output parser +jc - JSON Convert `free` command output parser Usage (cli): @@ -79,7 +79,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/fstab.md b/docs/parsers/fstab.md index 4d4707ec..5f4a2773 100644 --- a/docs/parsers/fstab.md +++ b/docs/parsers/fstab.md @@ -3,7 +3,7 @@ # jc.parsers.fstab -jc - JSON CLI output utility `fstab` file parser +jc - JSON Convert `fstab` file parser Usage (cli): @@ -92,7 +92,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/group.md b/docs/parsers/group.md index 14037ccc..0e3fb442 100644 --- a/docs/parsers/group.md +++ b/docs/parsers/group.md @@ -3,7 +3,7 @@ # jc.parsers.group -jc - JSON CLI output utility `/etc/group` file parser +jc - JSON Convert `/etc/group` file parser Usage (cli): @@ -116,7 +116,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/gshadow.md b/docs/parsers/gshadow.md index d70b01ca..1a1b7a70 100644 --- a/docs/parsers/gshadow.md +++ b/docs/parsers/gshadow.md @@ -3,7 +3,7 @@ # jc.parsers.gshadow -jc - JSON CLI output utility `/etc/gshadow` file parser +jc - JSON Convert `/etc/gshadow` file parser Usage (cli): @@ -84,7 +84,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/hash.md b/docs/parsers/hash.md index 319591d2..ca6109e0 100644 --- a/docs/parsers/hash.md +++ b/docs/parsers/hash.md @@ -3,7 +3,7 @@ # jc.parsers.hash -jc - JSON CLI output utility `hash` command output parser +jc - JSON Convert `hash` command output parser Usage (cli): @@ -44,7 +44,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/hashsum.md b/docs/parsers/hashsum.md index a2ca926c..984babe3 100644 --- a/docs/parsers/hashsum.md +++ b/docs/parsers/hashsum.md @@ -3,7 +3,7 @@ # jc.parsers.hashsum -jc - JSON CLI output utility `hash sum` command output parser +jc - JSON Convert `hash sum` command output parser This parser works with the following hash calculation utilities: - `md5` @@ -75,7 +75,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/hciconfig.md b/docs/parsers/hciconfig.md index 7a486eb6..9fe21dcb 100644 --- a/docs/parsers/hciconfig.md +++ b/docs/parsers/hciconfig.md @@ -3,7 +3,7 @@ # jc.parsers.hciconfig -jc - JSON CLI output utility `hciconfig` command output parser +jc - JSON Convert `hciconfig` command output parser Usage (cli): @@ -324,7 +324,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/history.md b/docs/parsers/history.md index 54ce0dea..19b5be41 100644 --- a/docs/parsers/history.md +++ b/docs/parsers/history.md @@ -3,7 +3,7 @@ # jc.parsers.history -jc - JSON CLI output utility `history` command output parser +jc - JSON Convert `history` command output parser This parser will output a list of dictionaries each containing `line` and `command` keys. If you would like a simple dictionary output, then use the @@ -70,7 +70,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/hosts.md b/docs/parsers/hosts.md index 9b9d165b..2aecaac7 100644 --- a/docs/parsers/hosts.md +++ b/docs/parsers/hosts.md @@ -3,7 +3,7 @@ # jc.parsers.hosts -jc - JSON CLI output utility `/etc/hosts` file parser +jc - JSON Convert `/etc/hosts` file parser Usage (cli): @@ -81,7 +81,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/id.md b/docs/parsers/id.md index f231d485..ac8efbc0 100644 --- a/docs/parsers/id.md +++ b/docs/parsers/id.md @@ -3,7 +3,7 @@ # jc.parsers.id -jc - JSON CLI output utility `id` command output parser +jc - JSON Convert `id` command output parser Usage (cli): @@ -112,7 +112,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/ifconfig.md b/docs/parsers/ifconfig.md index b742d594..686426d7 100644 --- a/docs/parsers/ifconfig.md +++ b/docs/parsers/ifconfig.md @@ -3,7 +3,7 @@ # jc.parsers.ifconfig -jc - JSON CLI output utility `ifconfig` command output parser +jc - JSON Convert `ifconfig` command output parser Note: No `ifconfig` options are supported. @@ -193,7 +193,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/ini.md b/docs/parsers/ini.md index f5d7892d..eac8190d 100644 --- a/docs/parsers/ini.md +++ b/docs/parsers/ini.md @@ -3,7 +3,7 @@ # jc.parsers.ini -jc - JSON CLI output utility `INI` file parser +jc - JSON Convert `INI` file parser Parses standard `INI` files and files containing simple key/value pairs. Delimiter can be `=` or `:`. Missing values are supported. Comment prefix @@ -73,7 +73,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/iostat.md b/docs/parsers/iostat.md index e0843778..fdf63c60 100644 --- a/docs/parsers/iostat.md +++ b/docs/parsers/iostat.md @@ -3,7 +3,7 @@ # jc.parsers.iostat -jc - JSON CLI output utility `iostat` command output parser +jc - JSON Convert `iostat` command output parser Note: `iostat` version 11 and higher include a JSON output option @@ -166,7 +166,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/iostat_s.md b/docs/parsers/iostat_s.md index 1fc68dac..162fd3a9 100644 --- a/docs/parsers/iostat_s.md +++ b/docs/parsers/iostat_s.md @@ -3,7 +3,7 @@ # jc.parsers.iostat\_s -jc - JSON CLI output utility `iostat` command output streaming parser +jc - JSON Convert `iostat` command output streaming parser > This streaming parser outputs JSON Lines @@ -107,7 +107,7 @@ Examples: -### parse +#### parse ```python @add_jc_meta diff --git a/docs/parsers/iptables.md b/docs/parsers/iptables.md index 3066c881..9a98a899 100644 --- a/docs/parsers/iptables.md +++ b/docs/parsers/iptables.md @@ -3,7 +3,7 @@ # jc.parsers.iptables -jc - JSON CLI output utility `iptables` command output parser +jc - JSON Convert `iptables` command output parser Supports `-vLn` and `--line-numbers` for all tables. @@ -170,7 +170,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/iw_scan.md b/docs/parsers/iw_scan.md index df0ed6df..5dd0bd85 100644 --- a/docs/parsers/iw_scan.md +++ b/docs/parsers/iw_scan.md @@ -3,7 +3,7 @@ # jc.parsers.iw\_scan -jc - JSON CLI output utility `iw dev scan` command output parser +jc - JSON Convert `iw dev scan` command output parser This parser is considered beta quality. Not all fields are parsed and there are not enough samples to test. @@ -128,7 +128,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/jar_manifest.md b/docs/parsers/jar_manifest.md index 7e2b44d2..2b14cebc 100644 --- a/docs/parsers/jar_manifest.md +++ b/docs/parsers/jar_manifest.md @@ -3,7 +3,7 @@ # jc.parsers.jar\_manifest -jc - JSON CLI output utility `MANIFEST.MF` file parser +jc - JSON Convert `MANIFEST.MF` file parser Usage (cli): @@ -84,7 +84,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/jobs.md b/docs/parsers/jobs.md index d24d7e2b..69209734 100644 --- a/docs/parsers/jobs.md +++ b/docs/parsers/jobs.md @@ -3,7 +3,7 @@ # jc.parsers.jobs -jc - JSON CLI output utility `jobs` command output parser +jc - JSON Convert `jobs` command output parser Also supports the `-l` option. @@ -100,7 +100,7 @@ Example: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/kv.md b/docs/parsers/kv.md index 024e1a88..4b71f64d 100644 --- a/docs/parsers/kv.md +++ b/docs/parsers/kv.md @@ -3,7 +3,7 @@ # jc.parsers.kv -jc - JSON CLI output utility `Key/Value` file parser +jc - JSON Convert `Key/Value` file parser Supports files containing simple key/value pairs. Delimiter can be `=` or `:`. Missing values are supported. Comment prefix can be `#` or `;`. @@ -60,7 +60,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/last.md b/docs/parsers/last.md index aa9de406..b2dfb32c 100644 --- a/docs/parsers/last.md +++ b/docs/parsers/last.md @@ -3,7 +3,7 @@ # jc.parsers.last -jc - JSON CLI output utility `last` and `lastb` command output parser +jc - JSON Convert `last` and `lastb` command output parser Supports `-w` and `-F` options. @@ -111,7 +111,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/ls.md b/docs/parsers/ls.md index 2ae42823..d3b0ea8b 100644 --- a/docs/parsers/ls.md +++ b/docs/parsers/ls.md @@ -3,7 +3,7 @@ # jc.parsers.ls -jc - JSON CLI output utility `ls` and `vdir` command output parser +jc - JSON Convert `ls` and `vdir` command output parser Options supported: - `lbaR1` @@ -123,7 +123,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/ls_s.md b/docs/parsers/ls_s.md index bd0e5979..82ce4f6a 100644 --- a/docs/parsers/ls_s.md +++ b/docs/parsers/ls_s.md @@ -3,7 +3,7 @@ # jc.parsers.ls\_s -jc - JSON CLI output utility `ls` and `vdir` command output streaming +jc - JSON Convert `ls` and `vdir` command output streaming parser > This streaming parser outputs JSON Lines @@ -84,7 +84,7 @@ Examples: -### parse +#### parse ```python @add_jc_meta diff --git a/docs/parsers/lsblk.md b/docs/parsers/lsblk.md index 137bb66b..24c8d6e8 100644 --- a/docs/parsers/lsblk.md +++ b/docs/parsers/lsblk.md @@ -3,7 +3,7 @@ # jc.parsers.lsblk -jc - JSON CLI output utility `lsblk` command output parser +jc - JSON Convert `lsblk` command output parser Usage (cli): @@ -281,7 +281,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/lsmod.md b/docs/parsers/lsmod.md index 918196c2..dda48fb4 100644 --- a/docs/parsers/lsmod.md +++ b/docs/parsers/lsmod.md @@ -3,7 +3,7 @@ # jc.parsers.lsmod -jc - JSON CLI output utility `lsmod` command output parser +jc - JSON Convert `lsmod` command output parser Usage (cli): @@ -132,7 +132,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/lsof.md b/docs/parsers/lsof.md index 91d8b439..90945628 100644 --- a/docs/parsers/lsof.md +++ b/docs/parsers/lsof.md @@ -3,7 +3,7 @@ # jc.parsers.lsof -jc - JSON CLI output utility `lsof` command output parser +jc - JSON Convert `lsof` command output parser Usage (cli): @@ -126,7 +126,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/lsusb.md b/docs/parsers/lsusb.md index 4243593c..9be5c776 100644 --- a/docs/parsers/lsusb.md +++ b/docs/parsers/lsusb.md @@ -3,7 +3,7 @@ # jc.parsers.lsusb -jc - JSON CLI output utility `lsusb` command output parser +jc - JSON Convert `lsusb` command output parser Supports the `-v` option or no options. @@ -268,7 +268,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/mount.md b/docs/parsers/mount.md index 4eb3ba20..cee2b027 100644 --- a/docs/parsers/mount.md +++ b/docs/parsers/mount.md @@ -3,7 +3,7 @@ # jc.parsers.mount -jc - JSON CLI output utility `mount` command output parser +jc - JSON Convert `mount` command output parser Usage (cli): @@ -82,7 +82,7 @@ Example: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/netstat.md b/docs/parsers/netstat.md index c48fbcfc..260237ef 100644 --- a/docs/parsers/netstat.md +++ b/docs/parsers/netstat.md @@ -3,7 +3,7 @@ # jc.parsers.netstat -jc - JSON CLI output utility `netstat` command output parser +jc - JSON Convert `netstat` command output parser Caveats: - Use of multiple `l` options is not supported on OSX (e.g. `netstat -rlll`) @@ -362,7 +362,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/nmcli.md b/docs/parsers/nmcli.md index 518f24bf..b0971100 100644 --- a/docs/parsers/nmcli.md +++ b/docs/parsers/nmcli.md @@ -3,7 +3,7 @@ # jc.parsers.nmcli -jc - JSON CLI output utility `nmcli` command output parser +jc - JSON Convert `nmcli` command output parser Supports the following `nmcli` subcommands: - `nmcli general` @@ -152,7 +152,7 @@ Examples: -### parse +#### parse ```python def parse(data: str, raw: bool = False, quiet: bool = False) -> List[Dict] diff --git a/docs/parsers/ntpq.md b/docs/parsers/ntpq.md index 15ca65db..73e30589 100644 --- a/docs/parsers/ntpq.md +++ b/docs/parsers/ntpq.md @@ -3,7 +3,7 @@ # jc.parsers.ntpq -jc - JSON CLI output utility `ntpq -p` command output parser +jc - JSON Convert `ntpq -p` command output parser Usage (cli): @@ -213,7 +213,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/passwd.md b/docs/parsers/passwd.md index e0682d55..f30b1f39 100644 --- a/docs/parsers/passwd.md +++ b/docs/parsers/passwd.md @@ -3,7 +3,7 @@ # jc.parsers.passwd -jc - JSON CLI output utility `/etc/passwd` file Parser +jc - JSON Convert `/etc/passwd` file Parser Usage (cli): @@ -101,7 +101,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/ping.md b/docs/parsers/ping.md index 3ffce210..eaea4e9c 100644 --- a/docs/parsers/ping.md +++ b/docs/parsers/ping.md @@ -3,7 +3,7 @@ # jc.parsers.ping -jc - JSON CLI output utility `ping` command output parser +jc - JSON Convert `ping` command output parser Supports `ping` and `ping6` output. @@ -169,7 +169,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/ping_s.md b/docs/parsers/ping_s.md index b904e2b7..7fc3c204 100644 --- a/docs/parsers/ping_s.md +++ b/docs/parsers/ping_s.md @@ -3,7 +3,7 @@ # jc.parsers.ping\_s -jc - JSON CLI output utility `ping` command output streaming parser +jc - JSON Convert `ping` command output streaming parser > This streaming parser outputs JSON Lines @@ -90,7 +90,7 @@ Examples: -### parse +#### parse ```python @add_jc_meta diff --git a/docs/parsers/pip_list.md b/docs/parsers/pip_list.md index de814615..c05f99cb 100644 --- a/docs/parsers/pip_list.md +++ b/docs/parsers/pip_list.md @@ -3,7 +3,7 @@ # jc.parsers.pip\_list -jc - JSON CLI output utility `pip-list` command output parser +jc - JSON Convert `pip-list` command output parser Usage (cli): @@ -54,7 +54,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/pip_show.md b/docs/parsers/pip_show.md index 9de9de46..b378f604 100644 --- a/docs/parsers/pip_show.md +++ b/docs/parsers/pip_show.md @@ -3,7 +3,7 @@ # jc.parsers.pip\_show -jc - JSON CLI output utility `pip-show` command output parser +jc - JSON Convert `pip-show` command output parser Usage (cli): @@ -72,7 +72,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/ps.md b/docs/parsers/ps.md index b2e21c5c..51aece3a 100644 --- a/docs/parsers/ps.md +++ b/docs/parsers/ps.md @@ -3,7 +3,7 @@ # jc.parsers.ps -jc - JSON CLI output utility `ps` command output parser +jc - JSON Convert `ps` command output parser `ps` options supported: - `ef` @@ -213,7 +213,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/route.md b/docs/parsers/route.md index c44d9a2a..961f21d8 100644 --- a/docs/parsers/route.md +++ b/docs/parsers/route.md @@ -3,7 +3,7 @@ # jc.parsers.route -jc - JSON CLI output utility `route` command output parser +jc - JSON Convert `route` command output parser Usage (cli): @@ -115,7 +115,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/rpm_qi.md b/docs/parsers/rpm_qi.md index 3d316d03..7e1c5782 100644 --- a/docs/parsers/rpm_qi.md +++ b/docs/parsers/rpm_qi.md @@ -3,7 +3,7 @@ # jc.parsers.rpm\_qi -jc - JSON CLI output utility `rpm -qi` command output parser +jc - JSON Convert `rpm -qi` command output parser Works with `rpm -qi [package]` or `rpm -qia`. @@ -168,7 +168,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/rsync.md b/docs/parsers/rsync.md index 04f8c664..1271c1e7 100644 --- a/docs/parsers/rsync.md +++ b/docs/parsers/rsync.md @@ -3,7 +3,7 @@ # jc.parsers.rsync -jc - JSON CLI output utility `rsync` command output parser +jc - JSON Convert `rsync` command output parser Supports the `-i` or `--itemize-changes` options with all levels of verbosity. This parser will process the STDOUT output or a log file @@ -141,7 +141,7 @@ Examples: -### parse +#### parse ```python def parse(data: str, raw: bool = False, quiet: bool = False) -> List[Dict] diff --git a/docs/parsers/rsync_s.md b/docs/parsers/rsync_s.md index 27b2c9a7..f42fc855 100644 --- a/docs/parsers/rsync_s.md +++ b/docs/parsers/rsync_s.md @@ -3,7 +3,7 @@ # jc.parsers.rsync\_s -jc - JSON CLI output utility `rsync` command output streaming parser +jc - JSON Convert `rsync` command output streaming parser > This streaming parser outputs JSON Lines @@ -95,11 +95,14 @@ Examples: -### parse +#### parse ```python @add_jc_meta -def parse(data: Iterable[str], raw: bool = False, quiet: bool = False, ignore_exceptions: bool = False) -> Union[Iterable[Dict], tuple] +def parse(data: Iterable[str], + raw: bool = False, + quiet: bool = False, + ignore_exceptions: bool = False) -> Union[Iterable[Dict], tuple] ``` Main text parsing generator function. Returns an iterator object. diff --git a/docs/parsers/sfdisk.md b/docs/parsers/sfdisk.md index eb0d8cde..91ee9862 100644 --- a/docs/parsers/sfdisk.md +++ b/docs/parsers/sfdisk.md @@ -3,7 +3,7 @@ # jc.parsers.sfdisk -jc - JSON CLI output utility `sfdisk` command output parser +jc - JSON Convert `sfdisk` command output parser Supports the following `sfdisk` options: - `-l` @@ -209,7 +209,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/shadow.md b/docs/parsers/shadow.md index b184b650..fae577e2 100644 --- a/docs/parsers/shadow.md +++ b/docs/parsers/shadow.md @@ -3,7 +3,7 @@ # jc.parsers.shadow -jc - JSON CLI output utility `/etc/shadow` file parser +jc - JSON Convert `/etc/shadow` file parser Usage (cli): @@ -108,7 +108,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/ss.md b/docs/parsers/ss.md index 17031b5e..bbe984f8 100644 --- a/docs/parsers/ss.md +++ b/docs/parsers/ss.md @@ -3,7 +3,7 @@ # jc.parsers.ss -jc - JSON CLI output utility `ss` command output parser +jc - JSON Convert `ss` command output parser Extended information options like -e and -p are not supported and may cause parsing irregularities. @@ -287,7 +287,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/stat.md b/docs/parsers/stat.md index b5db81dd..c950a568 100644 --- a/docs/parsers/stat.md +++ b/docs/parsers/stat.md @@ -3,7 +3,7 @@ # jc.parsers.stat -jc - JSON CLI output utility `stat` command output parser +jc - JSON Convert `stat` command output parser The `xxx_epoch` calculated timestamp fields are naive. (i.e. based on the local time of the system the parser is run on) @@ -177,7 +177,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/stat_s.md b/docs/parsers/stat_s.md index 4a59f84d..1b438ab2 100644 --- a/docs/parsers/stat_s.md +++ b/docs/parsers/stat_s.md @@ -3,7 +3,7 @@ # jc.parsers.stat\_s -jc - JSON CLI output utility `stat` command output streaming parser +jc - JSON Convert `stat` command output streaming parser > This streaming parser outputs JSON Lines @@ -88,7 +88,7 @@ Examples: -### parse +#### parse ```python @add_jc_meta diff --git a/docs/parsers/sysctl.md b/docs/parsers/sysctl.md index 1b77027a..c19ca743 100644 --- a/docs/parsers/sysctl.md +++ b/docs/parsers/sysctl.md @@ -3,7 +3,7 @@ # jc.parsers.sysctl -jc - JSON CLI output utility `sysctl -a` command output parser +jc - JSON Convert `sysctl -a` command output parser Note: Since `sysctl` output is not easily parsable only a very simple key/value object will be output. An attempt is made to convert obvious @@ -64,7 +64,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/systemctl.md b/docs/parsers/systemctl.md index 2359a0f4..085ad486 100644 --- a/docs/parsers/systemctl.md +++ b/docs/parsers/systemctl.md @@ -3,7 +3,7 @@ # jc.parsers.systemctl -jc - JSON CLI output utility `systemctl` command output parser +jc - JSON Convert `systemctl` command output parser Usage (cli): @@ -65,7 +65,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/systemctl_lj.md b/docs/parsers/systemctl_lj.md index 324375d0..007e8261 100644 --- a/docs/parsers/systemctl_lj.md +++ b/docs/parsers/systemctl_lj.md @@ -3,7 +3,7 @@ # jc.parsers.systemctl\_lj -jc - JSON CLI output utility `systemctl list-jobs` command output parser +jc - JSON Convert `systemctl list-jobs` command output parser Usage (cli): @@ -82,7 +82,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/systemctl_ls.md b/docs/parsers/systemctl_ls.md index caca4b71..f5783a95 100644 --- a/docs/parsers/systemctl_ls.md +++ b/docs/parsers/systemctl_ls.md @@ -3,7 +3,7 @@ # jc.parsers.systemctl\_ls -jc - JSON CLI output utility `systemctl list-sockets` command output +jc - JSON Convert `systemctl list-sockets` command output parser Usage (cli): @@ -58,7 +58,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/systemctl_luf.md b/docs/parsers/systemctl_luf.md index 9624439e..79a858a2 100644 --- a/docs/parsers/systemctl_luf.md +++ b/docs/parsers/systemctl_luf.md @@ -3,7 +3,7 @@ # jc.parsers.systemctl\_luf -jc - JSON CLI output utility `systemctl list-unit-files` command output +jc - JSON Convert `systemctl list-unit-files` command output parser Usage (cli): @@ -54,7 +54,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/systeminfo.md b/docs/parsers/systeminfo.md index bd85b45f..616e23dd 100644 --- a/docs/parsers/systeminfo.md +++ b/docs/parsers/systeminfo.md @@ -3,7 +3,7 @@ # jc.parsers.systeminfo -jc - JSON CLI output utility `systeminfo` command output parser +jc - JSON Convert `systeminfo` command output parser Blank or missing elements are set to `null`. @@ -218,7 +218,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/time.md b/docs/parsers/time.md index 6ade177f..ed79b975 100644 --- a/docs/parsers/time.md +++ b/docs/parsers/time.md @@ -3,7 +3,7 @@ # jc.parsers.time -jc - JSON CLI output utility `/usr/bin/time` command output parser +jc - JSON Convert `/usr/bin/time` command output parser Output from `/usr/bin/time` is sent to `STDERR`, so the `-o` option can be used to redirect the output to a file that can be read by `jc`. @@ -139,7 +139,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/timedatectl.md b/docs/parsers/timedatectl.md index 0e40adbe..94d50ed1 100644 --- a/docs/parsers/timedatectl.md +++ b/docs/parsers/timedatectl.md @@ -3,7 +3,7 @@ # jc.parsers.timedatectl -jc - JSON CLI output utility `timedatectl` command output parser +jc - JSON Convert `timedatectl` command output parser The `epoch_utc` calculated timestamp field is timezone-aware and is only available if the `universal_time` field is available. @@ -71,7 +71,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/tracepath.md b/docs/parsers/tracepath.md index 19636189..73d4f6ef 100644 --- a/docs/parsers/tracepath.md +++ b/docs/parsers/tracepath.md @@ -3,7 +3,7 @@ # jc.parsers.tracepath -jc - JSON CLI output utility `tracepath` command output parser +jc - JSON Convert `tracepath` command output parser Supports `tracepath` and `tracepath6` output. @@ -138,7 +138,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/traceroute.md b/docs/parsers/traceroute.md index 1ab094fb..2a0ff614 100644 --- a/docs/parsers/traceroute.md +++ b/docs/parsers/traceroute.md @@ -3,7 +3,7 @@ # jc.parsers.traceroute -jc - JSON CLI output utility `traceroute` command output parser +jc - JSON Convert `traceroute` command output parser Supports `traceroute` and `traceroute6` output. @@ -127,7 +127,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/ufw.md b/docs/parsers/ufw.md index ddc29105..fa26ae84 100644 --- a/docs/parsers/ufw.md +++ b/docs/parsers/ufw.md @@ -3,7 +3,7 @@ # jc.parsers.ufw -jc - JSON CLI output utility `ufw status` command output parser +jc - JSON Convert `ufw status` command output parser Usage (cli): @@ -207,7 +207,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/ufw_appinfo.md b/docs/parsers/ufw_appinfo.md index 0ad1eecc..54711331 100644 --- a/docs/parsers/ufw_appinfo.md +++ b/docs/parsers/ufw_appinfo.md @@ -3,7 +3,7 @@ # jc.parsers.ufw\_appinfo -jc - JSON CLI output utility `ufw app info [application]` command +jc - JSON Convert `ufw app info [application]` command output parser Supports individual apps via `ufw app info [application]` and all apps list @@ -145,7 +145,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/uname.md b/docs/parsers/uname.md index 71e67ddc..b4a9329e 100644 --- a/docs/parsers/uname.md +++ b/docs/parsers/uname.md @@ -3,7 +3,7 @@ # jc.parsers.uname -jc - JSON CLI output utility `uname -a` command output parser +jc - JSON Convert `uname -a` command output parser Note: Must use `uname -a` @@ -54,7 +54,7 @@ Example: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/universal.md b/docs/parsers/universal.md index 00dca1d3..ae227a9d 100644 --- a/docs/parsers/universal.md +++ b/docs/parsers/universal.md @@ -8,11 +8,11 @@ # jc.parsers.universal -jc - JSON CLI output utility universal Parsers +jc - JSON Convert universal Parsers -### simple\_table\_parse +#### simple\_table\_parse ```python def simple_table_parse(data: List[str]) -> List[Dict] @@ -37,7 +37,7 @@ Returns: -### sparse\_table\_parse +#### sparse\_table\_parse ```python def sparse_table_parse(data: List[str], delim: str = '\u2063') -> List[Dict] diff --git a/docs/parsers/upower.md b/docs/parsers/upower.md index be0384ad..55a9a4c6 100644 --- a/docs/parsers/upower.md +++ b/docs/parsers/upower.md @@ -3,7 +3,7 @@ # jc.parsers.upower -jc - JSON CLI output utility `upower` command output parser +jc - JSON Convert `upower` command output parser The `updated_epoch` calculated timestamp field is naive. (i.e. based on the local time of the system the parser is run on) @@ -205,7 +205,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/uptime.md b/docs/parsers/uptime.md index 9d5375bd..f63a3d42 100644 --- a/docs/parsers/uptime.md +++ b/docs/parsers/uptime.md @@ -3,7 +3,7 @@ # jc.parsers.uptime -jc - JSON CLI output utility `uptime` command output parser +jc - JSON Convert `uptime` command output parser Usage (cli): @@ -72,7 +72,7 @@ Example: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/vmstat.md b/docs/parsers/vmstat.md index c6e76a38..1690b11e 100644 --- a/docs/parsers/vmstat.md +++ b/docs/parsers/vmstat.md @@ -3,7 +3,7 @@ # jc.parsers.vmstat -jc - JSON CLI output utility `vmstat` command output parser +jc - JSON Convert `vmstat` command output parser Options supported: `-a`, `-w`, `-d`, `-t` @@ -133,7 +133,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/vmstat_s.md b/docs/parsers/vmstat_s.md index 2445f1b6..8d39e959 100644 --- a/docs/parsers/vmstat_s.md +++ b/docs/parsers/vmstat_s.md @@ -3,7 +3,7 @@ # jc.parsers.vmstat\_s -jc - JSON CLI output utility `vmstat` command output streaming parser +jc - JSON Convert `vmstat` command output streaming parser > This streaming parser outputs JSON Lines @@ -107,7 +107,7 @@ Examples: -### parse +#### parse ```python @add_jc_meta diff --git a/docs/parsers/w.md b/docs/parsers/w.md index 378fa467..e754b7c8 100644 --- a/docs/parsers/w.md +++ b/docs/parsers/w.md @@ -3,7 +3,7 @@ # jc.parsers.w -jc - JSON CLI output utility `w` command output parser +jc - JSON Convert `w` command output parser Usage (cli): @@ -110,7 +110,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/wc.md b/docs/parsers/wc.md index 49f2f82b..f58d1058 100644 --- a/docs/parsers/wc.md +++ b/docs/parsers/wc.md @@ -3,7 +3,7 @@ # jc.parsers.wc -jc - JSON CLI output utility `wc` command output parser +jc - JSON Convert `wc` command output parser Usage (cli): @@ -61,7 +61,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/who.md b/docs/parsers/who.md index 94953475..7dfdd25e 100644 --- a/docs/parsers/who.md +++ b/docs/parsers/who.md @@ -3,7 +3,7 @@ # jc.parsers.who -jc - JSON CLI output utility `who` command output parser +jc - JSON Convert `who` command output parser Accepts any of the following who options (or no options): `-aTH` @@ -142,7 +142,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/xml.md b/docs/parsers/xml.md index 1dab4203..fa866d76 100644 --- a/docs/parsers/xml.md +++ b/docs/parsers/xml.md @@ -3,7 +3,7 @@ # jc.parsers.xml -jc - JSON CLI output utility `XML` file parser +jc - JSON Convert `XML` file parser Usage (cli): @@ -77,7 +77,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/xrandr.md b/docs/parsers/xrandr.md index eb095eec..d5c05e8f 100644 --- a/docs/parsers/xrandr.md +++ b/docs/parsers/xrandr.md @@ -3,7 +3,7 @@ # jc.parsers.xrandr -jc - JSON CLI output utility `xrandr` command output parser +jc - JSON Convert `xrandr` command output parser Usage (cli): @@ -144,7 +144,7 @@ Examples: -### parse +#### parse ```python def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict diff --git a/docs/parsers/yaml.md b/docs/parsers/yaml.md index 6e4d8cd2..18234a8c 100644 --- a/docs/parsers/yaml.md +++ b/docs/parsers/yaml.md @@ -3,7 +3,7 @@ # jc.parsers.yaml -jc - JSON CLI output utility `YAML` file parser +jc - JSON Convert `YAML` file parser Usage (cli): @@ -91,7 +91,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/zipinfo.md b/docs/parsers/zipinfo.md index eef68a9b..e56ad2f0 100644 --- a/docs/parsers/zipinfo.md +++ b/docs/parsers/zipinfo.md @@ -3,7 +3,7 @@ # jc.parsers.zipinfo -jc - JSON CLI output utility `zipinfo` command output parser +jc - JSON Convert `zipinfo` command output parser Options supported: - none @@ -86,7 +86,7 @@ Examples: -### parse +#### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/readme.md b/docs/readme.md index e5c3d8ec..0f1c71aa 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -2,7 +2,7 @@ # jc -JC - JSON CLI output utility +JC - JSON Convert * kellyjonbrazil@gmail.com diff --git a/docs/streaming.md b/docs/streaming.md index b8971010..f97f9d9f 100644 --- a/docs/streaming.md +++ b/docs/streaming.md @@ -12,11 +12,11 @@ # jc.streaming -jc - JSON CLI output utility streaming utils +jc - JSON Convert streaming utils -### streaming\_input\_type\_check +#### streaming\_input\_type\_check ```python def streaming_input_type_check(data: Iterable) -> None @@ -27,7 +27,7 @@ Ensure input data is an iterable, but not a string or bytes. Raises -### streaming\_line\_input\_type\_check +#### streaming\_line\_input\_type\_check ```python def streaming_line_input_type_check(line: str) -> None @@ -37,7 +37,7 @@ Ensure each line is a string. Raises `TypeError` if not. -### stream\_success +#### stream\_success ```python def stream_success(output_line: Dict, ignore_exceptions: bool) -> Dict @@ -47,7 +47,7 @@ Add `_jc_meta` object to output line if `ignore_exceptions=True` -### stream\_error +#### stream\_error ```python def stream_error(e: BaseException, line: str) -> Dict @@ -57,7 +57,7 @@ Return an error `_jc_meta` field. -### add\_jc\_meta +#### add\_jc\_meta ```python def add_jc_meta(func) @@ -102,10 +102,11 @@ In all cases above: -### raise\_or\_yield +#### raise\_or\_yield ```python -def raise_or_yield(ignore_exceptions: bool, e: BaseException, line: str) -> tuple +def raise_or_yield(ignore_exceptions: bool, e: BaseException, + line: str) -> tuple ``` Return the exception object and line string if ignore_exceptions is diff --git a/docs/utils.md b/docs/utils.md index c8c24180..de72f4f7 100644 --- a/docs/utils.md +++ b/docs/utils.md @@ -16,11 +16,11 @@ # jc.utils -jc - JSON CLI output utility utils +jc - JSON Convert utils -### warning\_message +#### warning\_message ```python def warning_message(message_lines: List[str]) -> None @@ -40,7 +40,7 @@ Returns: -### error\_message +#### error\_message ```python def error_message(message_lines: List[str]) -> None @@ -60,10 +60,12 @@ Returns: -### compatibility +#### compatibility ```python -def compatibility(mod_name: str, compatible: List, quiet: bool = False) -> None +def compatibility(mod_name: str, + compatible: List, + quiet: bool = False) -> None ``` Checks for the parser's compatibility with the running OS @@ -85,7 +87,7 @@ Returns: -### has\_data +#### has\_data ```python def has_data(data: str) -> bool @@ -105,7 +107,7 @@ Returns: -### convert\_to\_int +#### convert\_to\_int ```python def convert_to_int(value: Union[str, float]) -> Optional[int] @@ -124,7 +126,7 @@ Returns: -### convert\_to\_float +#### convert\_to\_float ```python def convert_to_float(value: Union[str, int]) -> Optional[float] @@ -143,7 +145,7 @@ Returns: -### convert\_to\_bool +#### convert\_to\_bool ```python def convert_to_bool(value: Union[str, int, float]) -> bool @@ -163,7 +165,7 @@ Returns: -### input\_type\_check +#### input\_type\_check ```python def input_type_check(data: str) -> None @@ -173,7 +175,7 @@ Ensure input data is a string. Raises `TypeError` if not. -### timestamp Objects +## timestamp Objects ```python class timestamp() @@ -181,10 +183,11 @@ class timestamp() -### \_\_init\_\_ +#### \_\_init\_\_ ```python -def __init__(datetime_string: str, format_hint: Union[List, Tuple, None] = None) -> None +def __init__(datetime_string: str, + format_hint: Union[List, Tuple, None] = None) -> None ``` Input a datetime text string of several formats and convert to a diff --git a/jc/__init__.py b/jc/__init__.py index 4d9f44ca..ea5ccc20 100644 --- a/jc/__init__.py +++ b/jc/__init__.py @@ -1,4 +1,4 @@ -"""JC - JSON CLI output utility +"""JC - JSON Convert * kellyjonbrazil@gmail.com diff --git a/jc/cli.py b/jc/cli.py index 6dd1a147..149f5c6b 100644 --- a/jc/cli.py +++ b/jc/cli.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility +"""jc - JSON Convert JC cli module """ @@ -34,7 +34,7 @@ JC_ERROR_EXIT = 100 class info(): version = __version__ - description = 'JSON CLI output utility' + description = 'JSON Convert' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' website = 'https://github.com/kellyjonbrazil/jc' diff --git a/jc/exceptions.py b/jc/exceptions.py index 32218db6..932e728e 100644 --- a/jc/exceptions.py +++ b/jc/exceptions.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility exceptions""" +"""jc - JSON Convert exceptions""" class ParseError(Exception): diff --git a/jc/lib.py b/jc/lib.py index 4252b864..f5d382d1 100644 --- a/jc/lib.py +++ b/jc/lib.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility +"""jc - JSON Convert JC lib module """ diff --git a/jc/parsers/acpi.py b/jc/parsers/acpi.py index 4e9e41fe..46182eed 100644 --- a/jc/parsers/acpi.py +++ b/jc/parsers/acpi.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `acpi` command output parser +"""jc - JSON Convert `acpi` command output parser Usage (cli): diff --git a/jc/parsers/airport.py b/jc/parsers/airport.py index 715510f2..ae1d4291 100644 --- a/jc/parsers/airport.py +++ b/jc/parsers/airport.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `airport -I` command output parser +"""jc - JSON Convert `airport -I` command output parser The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`. diff --git a/jc/parsers/airport_s.py b/jc/parsers/airport_s.py index 5648195c..bf478efa 100644 --- a/jc/parsers/airport_s.py +++ b/jc/parsers/airport_s.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `airport -s` command output parser +"""jc - JSON Convert `airport -s` command output parser The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`. diff --git a/jc/parsers/arp.py b/jc/parsers/arp.py index 2f4e8a58..53f0c981 100644 --- a/jc/parsers/arp.py +++ b/jc/parsers/arp.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `arp` command output parser +"""jc - JSON Convert `arp` command output parser Supports `arp` and `arp -a` output. diff --git a/jc/parsers/blkid.py b/jc/parsers/blkid.py index ce5df6be..2e94b63f 100644 --- a/jc/parsers/blkid.py +++ b/jc/parsers/blkid.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `blkid` command output parser +"""jc - JSON Convert `blkid` command output parser Usage (cli): diff --git a/jc/parsers/cksum.py b/jc/parsers/cksum.py index 02b812f6..ea50103c 100644 --- a/jc/parsers/cksum.py +++ b/jc/parsers/cksum.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `cksum` command output parser +"""jc - JSON Convert `cksum` command output parser This parser works with the following checksum calculation utilities: - `sum` diff --git a/jc/parsers/crontab.py b/jc/parsers/crontab.py index 1736671e..59c0fe81 100644 --- a/jc/parsers/crontab.py +++ b/jc/parsers/crontab.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `crontab -l` command output and crontab +"""jc - JSON Convert `crontab -l` command output and crontab file parser Supports `crontab -l` command output and crontab files. diff --git a/jc/parsers/crontab_u.py b/jc/parsers/crontab_u.py index 0cd10f88..8ec1f13f 100644 --- a/jc/parsers/crontab_u.py +++ b/jc/parsers/crontab_u.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `crontab -l` command output and crontab +"""jc - JSON Convert `crontab -l` command output and crontab file parser This version of the `crontab -l` parser supports output that contains user diff --git a/jc/parsers/csv.py b/jc/parsers/csv.py index 2910c832..0df902ec 100644 --- a/jc/parsers/csv.py +++ b/jc/parsers/csv.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `csv` file parser +"""jc - JSON Convert `csv` file parser The `csv` parser will attempt to automatically detect the delimiter character. If the delimiter cannot be detected it will default to comma. diff --git a/jc/parsers/csv_s.py b/jc/parsers/csv_s.py index e4c573c4..86108659 100644 --- a/jc/parsers/csv_s.py +++ b/jc/parsers/csv_s.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `csv` file streaming parser +"""jc - JSON Convert `csv` file streaming parser > This streaming parser outputs JSON Lines diff --git a/jc/parsers/date.py b/jc/parsers/date.py index df710f69..313ec444 100644 --- a/jc/parsers/date.py +++ b/jc/parsers/date.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `date` command output parser +"""jc - JSON Convert `date` command output parser The `epoch` calculated timestamp field is naive. (i.e. based on the local time of the system the parser is run on) diff --git a/jc/parsers/df.py b/jc/parsers/df.py index 9b2e857b..cb1edb3e 100644 --- a/jc/parsers/df.py +++ b/jc/parsers/df.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `df` command output parser +"""jc - JSON Convert `df` command output parser Usage (cli): diff --git a/jc/parsers/dig.py b/jc/parsers/dig.py index 0af225b1..d5757b09 100644 --- a/jc/parsers/dig.py +++ b/jc/parsers/dig.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `dig` command output parser +"""jc - JSON Convert `dig` command output parser Options supported: - `+noall +answer` options are supported in cases where only the answer diff --git a/jc/parsers/dir.py b/jc/parsers/dir.py index f9f168b1..a7665628 100644 --- a/jc/parsers/dir.py +++ b/jc/parsers/dir.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `dir` command output parser +"""jc - JSON Convert `dir` command output parser Options supported: - `/T timefield` diff --git a/jc/parsers/dmidecode.py b/jc/parsers/dmidecode.py index f87e06bf..0ec59c03 100644 --- a/jc/parsers/dmidecode.py +++ b/jc/parsers/dmidecode.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `dmidecode` command output parser +"""jc - JSON Convert `dmidecode` command output parser Usage (cli): diff --git a/jc/parsers/dpkg_l.py b/jc/parsers/dpkg_l.py index 260f1433..46f192d0 100644 --- a/jc/parsers/dpkg_l.py +++ b/jc/parsers/dpkg_l.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `dpkg -l` command output parser +"""jc - JSON Convert `dpkg -l` command output parser Set the `COLUMNS` environment variable to a large value to avoid field truncation. For example: diff --git a/jc/parsers/du.py b/jc/parsers/du.py index e91aaee0..c2fa2f0d 100644 --- a/jc/parsers/du.py +++ b/jc/parsers/du.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `du` command output parser +"""jc - JSON Convert `du` command output parser Usage (cli): diff --git a/jc/parsers/env.py b/jc/parsers/env.py index d6155df3..50cfaed4 100644 --- a/jc/parsers/env.py +++ b/jc/parsers/env.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `env` and `printenv` command output parser +"""jc - JSON Convert `env` and `printenv` command output parser This parser will output a list of dictionaries each containing `name` and `value` keys. If you would like a simple dictionary output, then use the diff --git a/jc/parsers/file.py b/jc/parsers/file.py index d0cefe9f..1fbb3c67 100644 --- a/jc/parsers/file.py +++ b/jc/parsers/file.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `file` command output parser +"""jc - JSON Convert `file` command output parser Usage (cli): diff --git a/jc/parsers/finger.py b/jc/parsers/finger.py index d2b45eca..5da95946 100644 --- a/jc/parsers/finger.py +++ b/jc/parsers/finger.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `finger` command output parser +"""jc - JSON Convert `finger` command output parser Supports `-s` output option. Does not support the `-l` detail option. diff --git a/jc/parsers/foo.py b/jc/parsers/foo.py index afd56deb..c3a19357 100644 --- a/jc/parsers/foo.py +++ b/jc/parsers/foo.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `foo` command output parser +"""jc - JSON Convert `foo` command output parser <> diff --git a/jc/parsers/foo_s.py b/jc/parsers/foo_s.py index eadfc202..1113202d 100644 --- a/jc/parsers/foo_s.py +++ b/jc/parsers/foo_s.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `foo` command output streaming parser +"""jc - JSON Convert `foo` command output streaming parser > This streaming parser outputs JSON Lines diff --git a/jc/parsers/free.py b/jc/parsers/free.py index a7af04d5..21a4dc45 100644 --- a/jc/parsers/free.py +++ b/jc/parsers/free.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `free` command output parser +"""jc - JSON Convert `free` command output parser Usage (cli): diff --git a/jc/parsers/fstab.py b/jc/parsers/fstab.py index 6d2689da..3608253b 100644 --- a/jc/parsers/fstab.py +++ b/jc/parsers/fstab.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `fstab` file parser +"""jc - JSON Convert `fstab` file parser Usage (cli): diff --git a/jc/parsers/group.py b/jc/parsers/group.py index bf9bef87..7818ada2 100644 --- a/jc/parsers/group.py +++ b/jc/parsers/group.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `/etc/group` file parser +"""jc - JSON Convert `/etc/group` file parser Usage (cli): diff --git a/jc/parsers/gshadow.py b/jc/parsers/gshadow.py index d5df2b3b..581c1e26 100644 --- a/jc/parsers/gshadow.py +++ b/jc/parsers/gshadow.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `/etc/gshadow` file parser +"""jc - JSON Convert `/etc/gshadow` file parser Usage (cli): diff --git a/jc/parsers/hash.py b/jc/parsers/hash.py index 1efa91c6..b5f87c4c 100644 --- a/jc/parsers/hash.py +++ b/jc/parsers/hash.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `hash` command output parser +"""jc - JSON Convert `hash` command output parser Usage (cli): diff --git a/jc/parsers/hashsum.py b/jc/parsers/hashsum.py index 3f3356eb..0d963ca7 100644 --- a/jc/parsers/hashsum.py +++ b/jc/parsers/hashsum.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `hash sum` command output parser +"""jc - JSON Convert `hash sum` command output parser This parser works with the following hash calculation utilities: - `md5` diff --git a/jc/parsers/hciconfig.py b/jc/parsers/hciconfig.py index 9aff32f9..5e9551bb 100644 --- a/jc/parsers/hciconfig.py +++ b/jc/parsers/hciconfig.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `hciconfig` command output parser +"""jc - JSON Convert `hciconfig` command output parser Usage (cli): diff --git a/jc/parsers/history.py b/jc/parsers/history.py index 2ed864a6..9ee422ff 100644 --- a/jc/parsers/history.py +++ b/jc/parsers/history.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `history` command output parser +"""jc - JSON Convert `history` command output parser This parser will output a list of dictionaries each containing `line` and `command` keys. If you would like a simple dictionary output, then use the diff --git a/jc/parsers/hosts.py b/jc/parsers/hosts.py index 6f9a5071..e6f8d679 100644 --- a/jc/parsers/hosts.py +++ b/jc/parsers/hosts.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `/etc/hosts` file parser +"""jc - JSON Convert `/etc/hosts` file parser Usage (cli): diff --git a/jc/parsers/id.py b/jc/parsers/id.py index 3e14d467..046a28f9 100644 --- a/jc/parsers/id.py +++ b/jc/parsers/id.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `id` command output parser +"""jc - JSON Convert `id` command output parser Usage (cli): diff --git a/jc/parsers/ifconfig.py b/jc/parsers/ifconfig.py index 8367671f..3c6abc88 100644 --- a/jc/parsers/ifconfig.py +++ b/jc/parsers/ifconfig.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `ifconfig` command output parser +"""jc - JSON Convert `ifconfig` command output parser Note: No `ifconfig` options are supported. diff --git a/jc/parsers/ini.py b/jc/parsers/ini.py index 23a9d15a..192e3292 100644 --- a/jc/parsers/ini.py +++ b/jc/parsers/ini.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `INI` file parser +"""jc - JSON Convert `INI` file parser Parses standard `INI` files and files containing simple key/value pairs. Delimiter can be `=` or `:`. Missing values are supported. Comment prefix diff --git a/jc/parsers/iostat.py b/jc/parsers/iostat.py index 6eaf3ca6..59a43a6d 100644 --- a/jc/parsers/iostat.py +++ b/jc/parsers/iostat.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `iostat` command output parser +"""jc - JSON Convert `iostat` command output parser Note: `iostat` version 11 and higher include a JSON output option diff --git a/jc/parsers/iostat_s.py b/jc/parsers/iostat_s.py index d98f58bc..980e7908 100644 --- a/jc/parsers/iostat_s.py +++ b/jc/parsers/iostat_s.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `iostat` command output streaming parser +"""jc - JSON Convert `iostat` command output streaming parser > This streaming parser outputs JSON Lines diff --git a/jc/parsers/iptables.py b/jc/parsers/iptables.py index a0e755b9..b7de3886 100644 --- a/jc/parsers/iptables.py +++ b/jc/parsers/iptables.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `iptables` command output parser +"""jc - JSON Convert `iptables` command output parser Supports `-vLn` and `--line-numbers` for all tables. diff --git a/jc/parsers/iw_scan.py b/jc/parsers/iw_scan.py index 3c984719..883c3c76 100644 --- a/jc/parsers/iw_scan.py +++ b/jc/parsers/iw_scan.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `iw dev scan` command output parser +"""jc - JSON Convert `iw dev scan` command output parser This parser is considered beta quality. Not all fields are parsed and there are not enough samples to test. diff --git a/jc/parsers/jar_manifest.py b/jc/parsers/jar_manifest.py index e9afa424..3a68b9cc 100644 --- a/jc/parsers/jar_manifest.py +++ b/jc/parsers/jar_manifest.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `MANIFEST.MF` file parser +"""jc - JSON Convert `MANIFEST.MF` file parser Usage (cli): diff --git a/jc/parsers/jobs.py b/jc/parsers/jobs.py index cd7fd10b..b10ae7ae 100644 --- a/jc/parsers/jobs.py +++ b/jc/parsers/jobs.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `jobs` command output parser +"""jc - JSON Convert `jobs` command output parser Also supports the `-l` option. diff --git a/jc/parsers/kv.py b/jc/parsers/kv.py index a179bff4..db2d1544 100644 --- a/jc/parsers/kv.py +++ b/jc/parsers/kv.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `Key/Value` file parser +"""jc - JSON Convert `Key/Value` file parser Supports files containing simple key/value pairs. Delimiter can be `=` or `:`. Missing values are supported. Comment prefix can be `#` or `;`. diff --git a/jc/parsers/last.py b/jc/parsers/last.py index ba6c7d16..2598e37c 100644 --- a/jc/parsers/last.py +++ b/jc/parsers/last.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `last` and `lastb` command output parser +"""jc - JSON Convert `last` and `lastb` command output parser Supports `-w` and `-F` options. diff --git a/jc/parsers/ls.py b/jc/parsers/ls.py index fba2c2a4..226060de 100644 --- a/jc/parsers/ls.py +++ b/jc/parsers/ls.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `ls` and `vdir` command output parser +"""jc - JSON Convert `ls` and `vdir` command output parser Options supported: - `lbaR1` diff --git a/jc/parsers/ls_s.py b/jc/parsers/ls_s.py index 0ca3261c..f59c1bd6 100644 --- a/jc/parsers/ls_s.py +++ b/jc/parsers/ls_s.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `ls` and `vdir` command output streaming +"""jc - JSON Convert `ls` and `vdir` command output streaming parser > This streaming parser outputs JSON Lines diff --git a/jc/parsers/lsblk.py b/jc/parsers/lsblk.py index 45ddd844..4ee44d69 100644 --- a/jc/parsers/lsblk.py +++ b/jc/parsers/lsblk.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `lsblk` command output parser +"""jc - JSON Convert `lsblk` command output parser Usage (cli): diff --git a/jc/parsers/lsmod.py b/jc/parsers/lsmod.py index 26720e17..1342d5cd 100644 --- a/jc/parsers/lsmod.py +++ b/jc/parsers/lsmod.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `lsmod` command output parser +"""jc - JSON Convert `lsmod` command output parser Usage (cli): diff --git a/jc/parsers/lsof.py b/jc/parsers/lsof.py index 89c962d5..08804dd0 100644 --- a/jc/parsers/lsof.py +++ b/jc/parsers/lsof.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `lsof` command output parser +"""jc - JSON Convert `lsof` command output parser Usage (cli): diff --git a/jc/parsers/lsusb.py b/jc/parsers/lsusb.py index 87d2cc55..4650d60d 100644 --- a/jc/parsers/lsusb.py +++ b/jc/parsers/lsusb.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `lsusb` command output parser +"""jc - JSON Convert `lsusb` command output parser Supports the `-v` option or no options. diff --git a/jc/parsers/mount.py b/jc/parsers/mount.py index 25c7c48f..6b7fc095 100644 --- a/jc/parsers/mount.py +++ b/jc/parsers/mount.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `mount` command output parser +"""jc - JSON Convert `mount` command output parser Usage (cli): diff --git a/jc/parsers/netstat.py b/jc/parsers/netstat.py index e3e9d3b5..f417c241 100644 --- a/jc/parsers/netstat.py +++ b/jc/parsers/netstat.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `netstat` command output parser +"""jc - JSON Convert `netstat` command output parser Caveats: - Use of multiple `l` options is not supported on OSX (e.g. `netstat -rlll`) diff --git a/jc/parsers/netstat_freebsd_osx.py b/jc/parsers/netstat_freebsd_osx.py index e593ad36..eb610ea8 100644 --- a/jc/parsers/netstat_freebsd_osx.py +++ b/jc/parsers/netstat_freebsd_osx.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility FreeBSD and OSX netstat Parser""" +"""jc - JSON Convert FreeBSD and OSX netstat Parser""" def normalize_headers(header): diff --git a/jc/parsers/netstat_linux.py b/jc/parsers/netstat_linux.py index ccafef9d..c43a61af 100644 --- a/jc/parsers/netstat_linux.py +++ b/jc/parsers/netstat_linux.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility Linux netstat Parser""" +"""jc - JSON Convert Linux netstat Parser""" import string diff --git a/jc/parsers/nmcli.py b/jc/parsers/nmcli.py index d71575a4..e89516cd 100644 --- a/jc/parsers/nmcli.py +++ b/jc/parsers/nmcli.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `nmcli` command output parser +"""jc - JSON Convert `nmcli` command output parser Supports the following `nmcli` subcommands: - `nmcli general` diff --git a/jc/parsers/ntpq.py b/jc/parsers/ntpq.py index f4eb7468..e8e474a6 100644 --- a/jc/parsers/ntpq.py +++ b/jc/parsers/ntpq.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `ntpq -p` command output parser +"""jc - JSON Convert `ntpq -p` command output parser Usage (cli): diff --git a/jc/parsers/passwd.py b/jc/parsers/passwd.py index 9be3b867..6281fc5d 100644 --- a/jc/parsers/passwd.py +++ b/jc/parsers/passwd.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `/etc/passwd` file Parser +"""jc - JSON Convert `/etc/passwd` file Parser Usage (cli): diff --git a/jc/parsers/ping.py b/jc/parsers/ping.py index 70e05465..0758045b 100644 --- a/jc/parsers/ping.py +++ b/jc/parsers/ping.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `ping` command output parser +"""jc - JSON Convert `ping` command output parser Supports `ping` and `ping6` output. diff --git a/jc/parsers/ping_s.py b/jc/parsers/ping_s.py index ab80d11b..34ce7369 100644 --- a/jc/parsers/ping_s.py +++ b/jc/parsers/ping_s.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `ping` command output streaming parser +"""jc - JSON Convert `ping` command output streaming parser > This streaming parser outputs JSON Lines diff --git a/jc/parsers/pip_list.py b/jc/parsers/pip_list.py index a429d468..00f5d310 100644 --- a/jc/parsers/pip_list.py +++ b/jc/parsers/pip_list.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `pip-list` command output parser +"""jc - JSON Convert `pip-list` command output parser Usage (cli): diff --git a/jc/parsers/pip_show.py b/jc/parsers/pip_show.py index 38142d6c..f465c26a 100644 --- a/jc/parsers/pip_show.py +++ b/jc/parsers/pip_show.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `pip-show` command output parser +"""jc - JSON Convert `pip-show` command output parser Usage (cli): diff --git a/jc/parsers/ps.py b/jc/parsers/ps.py index 99a68c6d..06e7c7fa 100644 --- a/jc/parsers/ps.py +++ b/jc/parsers/ps.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `ps` command output parser +"""jc - JSON Convert `ps` command output parser `ps` options supported: - `ef` diff --git a/jc/parsers/route.py b/jc/parsers/route.py index 3a5178bc..7eb07872 100644 --- a/jc/parsers/route.py +++ b/jc/parsers/route.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `route` command output parser +"""jc - JSON Convert `route` command output parser Usage (cli): diff --git a/jc/parsers/rpm_qi.py b/jc/parsers/rpm_qi.py index 2a6a81dd..52e42d74 100644 --- a/jc/parsers/rpm_qi.py +++ b/jc/parsers/rpm_qi.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `rpm -qi` command output parser +"""jc - JSON Convert `rpm -qi` command output parser Works with `rpm -qi [package]` or `rpm -qia`. diff --git a/jc/parsers/rsync.py b/jc/parsers/rsync.py index 8b56761a..eadfa495 100644 --- a/jc/parsers/rsync.py +++ b/jc/parsers/rsync.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `rsync` command output parser +"""jc - JSON Convert `rsync` command output parser Supports the `-i` or `--itemize-changes` options with all levels of verbosity. This parser will process the STDOUT output or a log file diff --git a/jc/parsers/rsync_s.py b/jc/parsers/rsync_s.py index 6a73c2ba..94b874e3 100644 --- a/jc/parsers/rsync_s.py +++ b/jc/parsers/rsync_s.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `rsync` command output streaming parser +"""jc - JSON Convert `rsync` command output streaming parser > This streaming parser outputs JSON Lines diff --git a/jc/parsers/sfdisk.py b/jc/parsers/sfdisk.py index d5f4ac88..9900b60b 100644 --- a/jc/parsers/sfdisk.py +++ b/jc/parsers/sfdisk.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `sfdisk` command output parser +"""jc - JSON Convert `sfdisk` command output parser Supports the following `sfdisk` options: - `-l` diff --git a/jc/parsers/shadow.py b/jc/parsers/shadow.py index 00427a37..ad1ae570 100644 --- a/jc/parsers/shadow.py +++ b/jc/parsers/shadow.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `/etc/shadow` file parser +"""jc - JSON Convert `/etc/shadow` file parser Usage (cli): diff --git a/jc/parsers/ss.py b/jc/parsers/ss.py index 0416f097..10bd69dc 100644 --- a/jc/parsers/ss.py +++ b/jc/parsers/ss.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `ss` command output parser +"""jc - JSON Convert `ss` command output parser Extended information options like -e and -p are not supported and may cause parsing irregularities. diff --git a/jc/parsers/stat.py b/jc/parsers/stat.py index af6bbd33..ca58789d 100644 --- a/jc/parsers/stat.py +++ b/jc/parsers/stat.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `stat` command output parser +"""jc - JSON Convert `stat` command output parser The `xxx_epoch` calculated timestamp fields are naive. (i.e. based on the local time of the system the parser is run on) diff --git a/jc/parsers/stat_s.py b/jc/parsers/stat_s.py index e58759b8..3b302e38 100644 --- a/jc/parsers/stat_s.py +++ b/jc/parsers/stat_s.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `stat` command output streaming parser +"""jc - JSON Convert `stat` command output streaming parser > This streaming parser outputs JSON Lines diff --git a/jc/parsers/sysctl.py b/jc/parsers/sysctl.py index 388c0fb9..022546b1 100644 --- a/jc/parsers/sysctl.py +++ b/jc/parsers/sysctl.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `sysctl -a` command output parser +"""jc - JSON Convert `sysctl -a` command output parser Note: Since `sysctl` output is not easily parsable only a very simple key/value object will be output. An attempt is made to convert obvious diff --git a/jc/parsers/systemctl.py b/jc/parsers/systemctl.py index 58cbe8d0..47136e15 100644 --- a/jc/parsers/systemctl.py +++ b/jc/parsers/systemctl.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `systemctl` command output parser +"""jc - JSON Convert `systemctl` command output parser Usage (cli): diff --git a/jc/parsers/systemctl_lj.py b/jc/parsers/systemctl_lj.py index f078b20b..a6ccd5fd 100644 --- a/jc/parsers/systemctl_lj.py +++ b/jc/parsers/systemctl_lj.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `systemctl list-jobs` command output parser +"""jc - JSON Convert `systemctl list-jobs` command output parser Usage (cli): diff --git a/jc/parsers/systemctl_ls.py b/jc/parsers/systemctl_ls.py index 0b7302c9..670986d5 100644 --- a/jc/parsers/systemctl_ls.py +++ b/jc/parsers/systemctl_ls.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `systemctl list-sockets` command output +"""jc - JSON Convert `systemctl list-sockets` command output parser Usage (cli): diff --git a/jc/parsers/systemctl_luf.py b/jc/parsers/systemctl_luf.py index 9eb91035..8fd540e8 100644 --- a/jc/parsers/systemctl_luf.py +++ b/jc/parsers/systemctl_luf.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `systemctl list-unit-files` command output +"""jc - JSON Convert `systemctl list-unit-files` command output parser Usage (cli): diff --git a/jc/parsers/systeminfo.py b/jc/parsers/systeminfo.py index dfcd1ba8..85222662 100644 --- a/jc/parsers/systeminfo.py +++ b/jc/parsers/systeminfo.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `systeminfo` command output parser +"""jc - JSON Convert `systeminfo` command output parser Blank or missing elements are set to `null`. diff --git a/jc/parsers/time.py b/jc/parsers/time.py index c09b5c45..74b9ce56 100644 --- a/jc/parsers/time.py +++ b/jc/parsers/time.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `/usr/bin/time` command output parser +"""jc - JSON Convert `/usr/bin/time` command output parser Output from `/usr/bin/time` is sent to `STDERR`, so the `-o` option can be used to redirect the output to a file that can be read by `jc`. diff --git a/jc/parsers/timedatectl.py b/jc/parsers/timedatectl.py index 5a5d670a..e4957c69 100644 --- a/jc/parsers/timedatectl.py +++ b/jc/parsers/timedatectl.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `timedatectl` command output parser +"""jc - JSON Convert `timedatectl` command output parser The `epoch_utc` calculated timestamp field is timezone-aware and is only available if the `universal_time` field is available. diff --git a/jc/parsers/tracepath.py b/jc/parsers/tracepath.py index 5a4458ed..2e0396a0 100644 --- a/jc/parsers/tracepath.py +++ b/jc/parsers/tracepath.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `tracepath` command output parser +"""jc - JSON Convert `tracepath` command output parser Supports `tracepath` and `tracepath6` output. diff --git a/jc/parsers/traceroute.py b/jc/parsers/traceroute.py index 5df5e70a..aa11b5a1 100644 --- a/jc/parsers/traceroute.py +++ b/jc/parsers/traceroute.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `traceroute` command output parser +"""jc - JSON Convert `traceroute` command output parser Supports `traceroute` and `traceroute6` output. diff --git a/jc/parsers/ufw.py b/jc/parsers/ufw.py index 58bedd57..cb0a8f39 100644 --- a/jc/parsers/ufw.py +++ b/jc/parsers/ufw.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `ufw status` command output parser +"""jc - JSON Convert `ufw status` command output parser Usage (cli): diff --git a/jc/parsers/ufw_appinfo.py b/jc/parsers/ufw_appinfo.py index ec3e78ef..04524653 100644 --- a/jc/parsers/ufw_appinfo.py +++ b/jc/parsers/ufw_appinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `ufw app info [application]` command +"""jc - JSON Convert `ufw app info [application]` command output parser Supports individual apps via `ufw app info [application]` and all apps list diff --git a/jc/parsers/uname.py b/jc/parsers/uname.py index 3f8538a6..7260803f 100644 --- a/jc/parsers/uname.py +++ b/jc/parsers/uname.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `uname -a` command output parser +"""jc - JSON Convert `uname -a` command output parser Note: Must use `uname -a` diff --git a/jc/parsers/universal.py b/jc/parsers/universal.py index b1de1ca4..289af3b9 100644 --- a/jc/parsers/universal.py +++ b/jc/parsers/universal.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility universal Parsers""" +"""jc - JSON Convert universal Parsers""" import string diff --git a/jc/parsers/upower.py b/jc/parsers/upower.py index b6508231..7dd511a3 100644 --- a/jc/parsers/upower.py +++ b/jc/parsers/upower.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `upower` command output parser +"""jc - JSON Convert `upower` command output parser The `updated_epoch` calculated timestamp field is naive. (i.e. based on the local time of the system the parser is run on) diff --git a/jc/parsers/uptime.py b/jc/parsers/uptime.py index 9b433dcc..486f8799 100644 --- a/jc/parsers/uptime.py +++ b/jc/parsers/uptime.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `uptime` command output parser +"""jc - JSON Convert `uptime` command output parser Usage (cli): diff --git a/jc/parsers/vmstat.py b/jc/parsers/vmstat.py index f39a5b71..8b31acdd 100644 --- a/jc/parsers/vmstat.py +++ b/jc/parsers/vmstat.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `vmstat` command output parser +"""jc - JSON Convert `vmstat` command output parser Options supported: `-a`, `-w`, `-d`, `-t` diff --git a/jc/parsers/vmstat_s.py b/jc/parsers/vmstat_s.py index 3a0d0921..5e2899ea 100644 --- a/jc/parsers/vmstat_s.py +++ b/jc/parsers/vmstat_s.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `vmstat` command output streaming parser +"""jc - JSON Convert `vmstat` command output streaming parser > This streaming parser outputs JSON Lines diff --git a/jc/parsers/w.py b/jc/parsers/w.py index 386bd066..7ce640c8 100644 --- a/jc/parsers/w.py +++ b/jc/parsers/w.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `w` command output parser +"""jc - JSON Convert `w` command output parser Usage (cli): diff --git a/jc/parsers/wc.py b/jc/parsers/wc.py index ce10b46e..eb1def49 100644 --- a/jc/parsers/wc.py +++ b/jc/parsers/wc.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `wc` command output parser +"""jc - JSON Convert `wc` command output parser Usage (cli): diff --git a/jc/parsers/who.py b/jc/parsers/who.py index c66d4003..c3655bfc 100644 --- a/jc/parsers/who.py +++ b/jc/parsers/who.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `who` command output parser +"""jc - JSON Convert `who` command output parser Accepts any of the following who options (or no options): `-aTH` diff --git a/jc/parsers/xml.py b/jc/parsers/xml.py index 3100f586..9eda8d53 100644 --- a/jc/parsers/xml.py +++ b/jc/parsers/xml.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `XML` file parser +"""jc - JSON Convert `XML` file parser Usage (cli): diff --git a/jc/parsers/xrandr.py b/jc/parsers/xrandr.py index 871f2fcc..c2f5ed66 100644 --- a/jc/parsers/xrandr.py +++ b/jc/parsers/xrandr.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `xrandr` command output parser +"""jc - JSON Convert `xrandr` command output parser Usage (cli): diff --git a/jc/parsers/yaml.py b/jc/parsers/yaml.py index f8c085cd..a8e815fd 100644 --- a/jc/parsers/yaml.py +++ b/jc/parsers/yaml.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `YAML` file parser +"""jc - JSON Convert `YAML` file parser Usage (cli): diff --git a/jc/parsers/zipinfo.py b/jc/parsers/zipinfo.py index 8d706dc3..d06ae365 100644 --- a/jc/parsers/zipinfo.py +++ b/jc/parsers/zipinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `zipinfo` command output parser +"""jc - JSON Convert `zipinfo` command output parser Options supported: - none diff --git a/jc/streaming.py b/jc/streaming.py index 0e6dbc80..208e0687 100644 --- a/jc/streaming.py +++ b/jc/streaming.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility streaming utils""" +"""jc - JSON Convert streaming utils""" from functools import wraps from typing import Dict, Iterable diff --git a/jc/utils.py b/jc/utils.py index e30fe519..678f824a 100644 --- a/jc/utils.py +++ b/jc/utils.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility utils""" +"""jc - JSON Convert utils""" import sys import re import locale diff --git a/man/jc.1 b/man/jc.1 index 2f99e9fb..e299572e 100644 --- a/man/jc.1 +++ b/man/jc.1 @@ -1,4 +1,4 @@ -.TH jc 1 2022-02-28 1.18.4 "JSON CLI output utility" +.TH jc 1 2022-03-04 1.18.4 "JSON Convert" .SH NAME jc \- JSONifies the output of many CLI tools and file-types .SH SYNOPSIS diff --git a/templates/manpage_template b/templates/manpage_template index 38fc17fb..fe1bc4fc 100644 --- a/templates/manpage_template +++ b/templates/manpage_template @@ -1,4 +1,4 @@ -.TH jc 1 {{ today }} {{ jc.version}} "JSON CLI output utility" +.TH jc 1 {{ today }} {{ jc.version}} "JSON Convert" .SH NAME jc \- JSONifies the output of many CLI tools and file-types .SH SYNOPSIS diff --git a/templates/readme_template b/templates/readme_template index d7873222..c71c3015 100644 --- a/templates/readme_template +++ b/templates/readme_template @@ -1,8 +1,6 @@ ![Tests](https://github.com/kellyjonbrazil/jc/workflows/Tests/badge.svg?branch=master) ![Pypi](https://img.shields.io/pypi/v/jc.svg) -> `jc` was recently featured in the [Console Open Source Newsletter](https://console.substack.com/p/console-89) - > Check out the `jc` Python [package documentation](https://github.com/kellyjonbrazil/jc/tree/master/docs) for developers > Try the `jc` [web demo](https://jc-web-demo.herokuapp.com/) @@ -13,7 +11,7 @@ Ansible filter plugin in the `community.general` collection. See this for an example. # JC -JSON CLI output utility +JSON Convert `jc` JSONifies the output of many CLI tools and file-types for easier parsing in scripts. See the [**Parsers**](#parsers) section for supported commands and From ac32c69c31e8eff22252d7aded08f6cb14622086 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Fri, 4 Mar 2022 13:35:16 -0800 Subject: [PATCH 31/38] formatting --- docs/parsers/universal.md | 2 +- jc/parsers/universal.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/parsers/universal.md b/docs/parsers/universal.md index ae227a9d..fbd7edee 100644 --- a/docs/parsers/universal.md +++ b/docs/parsers/universal.md @@ -8,7 +8,7 @@ # jc.parsers.universal -jc - JSON Convert universal Parsers +jc - JSON Convert universal parsers diff --git a/jc/parsers/universal.py b/jc/parsers/universal.py index 289af3b9..5fe253a4 100644 --- a/jc/parsers/universal.py +++ b/jc/parsers/universal.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert universal Parsers""" +"""jc - JSON Convert universal parsers""" import string From e4222b45f54e6179e22d7924c083e4642b9974ae Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Fri, 4 Mar 2022 16:24:13 -0800 Subject: [PATCH 32/38] fix names to mod names --- jc/lib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jc/lib.py b/jc/lib.py index f5d382d1..23fdaf31 100644 --- a/jc/lib.py +++ b/jc/lib.py @@ -247,7 +247,7 @@ def standard_parser_mod_list() -> List[str]: for p in parsers: parser = _get_parser(p) if not _parser_is_streaming(parser): - plist.append(p) + plist.append(_cliname_to_modname(p)) return plist def streaming_parser_mod_list() -> List[str]: @@ -259,7 +259,7 @@ def streaming_parser_mod_list() -> List[str]: for p in parsers: parser = _get_parser(p) if _parser_is_streaming(parser): - plist.append(p) + plist.append(_cliname_to_modname(p)) return plist def parser_info(parser_mod_name: str) -> Dict: From 0c1be7cc11ec75a5738483d68d053e702eb34fc1 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Fri, 4 Mar 2022 16:29:36 -0800 Subject: [PATCH 33/38] reduce dig example size --- README.md | 11 ++--------- templates/readme_template | 11 ++--------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 42b194d1..1d804634 100644 --- a/README.md +++ b/README.md @@ -53,16 +53,9 @@ will be a python dictionary, or list of dictionaries, instead of JSON: >>> cmd_output = subprocess.check_output(['dig', 'example.com'], text=True) >>> data = jc.parse('dig', cmd_output) >>> ->>> data -[{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', 'flags': ['qr', 'rd', -'ra'], 'query_num': 1, 'answer_num': 1, 'authority_num': 0, 'additional_num': -1, 'opt_pseudosection': {'edns': {'version': 0, 'flags': [], 'udp': 4096}}, -'question': {'name': 'example.com.', 'class': 'IN', 'type': 'A'}, 'answer': +>>> data[0]['answer'] [{'name': 'example.com.', 'class': 'IN', 'type': 'A', 'ttl': 29658, 'data': -'93.184.216.34'}], 'query_time': 52, 'server': -'2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)', 'when': -'Fri Apr 16 16:13:00 PDT 2021', 'rcvd': 56, 'when_epoch': 1618614780, -'when_epoch_utc': None}] +'93.184.216.34'}] ``` > For `jc` Python package documentation, use `help('jc')`, `help('jc.lib')`, or diff --git a/templates/readme_template b/templates/readme_template index c71c3015..286ca343 100644 --- a/templates/readme_template +++ b/templates/readme_template @@ -53,16 +53,9 @@ will be a python dictionary, or list of dictionaries, instead of JSON: >>> cmd_output = subprocess.check_output(['dig', 'example.com'], text=True) >>> data = jc.parse('dig', cmd_output) >>> ->>> data -[{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', 'flags': ['qr', 'rd', -'ra'], 'query_num': 1, 'answer_num': 1, 'authority_num': 0, 'additional_num': -1, 'opt_pseudosection': {'edns': {'version': 0, 'flags': [], 'udp': 4096}}, -'question': {'name': 'example.com.', 'class': 'IN', 'type': 'A'}, 'answer': +>>> data[0]['answer'] [{'name': 'example.com.', 'class': 'IN', 'type': 'A', 'ttl': 29658, 'data': -'93.184.216.34'}], 'query_time': 52, 'server': -'2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)', 'when': -'Fri Apr 16 16:13:00 PDT 2021', 'rcvd': 56, 'when_epoch': 1618614780, -'when_epoch_utc': None}] +'93.184.216.34'}] ``` > For `jc` Python package documentation, use `help('jc')`, `help('jc.lib')`, or From a531ab8864fca27b55d83b55055eaef1c36128cd Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Fri, 4 Mar 2022 16:35:06 -0800 Subject: [PATCH 34/38] formatting --- docs/readme.md | 4 ++-- jc/__init__.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/readme.md b/docs/readme.md index 0f1c71aa..d224b4d7 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -26,9 +26,9 @@ https://github.com/kellyjonbrazil/jc/tree/master/docs ### Specific Version -Replace `{{full_version_number}}` - e.g. `1.17.7`: +Replace `` - e.g. `1.17.7`: -`https://github.com/kellyjonbrazil/jc/tree/v{{full_version_number}}/docs` +`https://github.com/kellyjonbrazil/jc/tree/v/docs` Specific versions can also be selected by tag in the branch dropdown menu. diff --git a/jc/__init__.py b/jc/__init__.py index ea5ccc20..71053c42 100644 --- a/jc/__init__.py +++ b/jc/__init__.py @@ -22,9 +22,9 @@ https://github.com/kellyjonbrazil/jc/tree/master/docs ### Specific Version -Replace `{{full_version_number}}` - e.g. `1.17.7`: +Replace `` - e.g. `1.17.7`: -`https://github.com/kellyjonbrazil/jc/tree/v{{full_version_number}}/docs` +`https://github.com/kellyjonbrazil/jc/tree/v/docs` Specific versions can also be selected by tag in the branch dropdown menu. From 128c3c170abc6a702ae044b073fb9d992d4262b1 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Fri, 4 Mar 2022 16:38:49 -0800 Subject: [PATCH 35/38] doc update --- CHANGELOG | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index a3b291e9..7aa053f6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,9 +1,10 @@ jc changelog -20220303 v1.18.4 +20220304 v1.18.4 - Add nmcli command parser tested on linux - Enhance parse error messages at the cli - Add standard and streaming parser list functions to the public API +- Enhance python developer documentation formatting 20220214 v1.18.3 - Add rsync command and log file parser tested on linux and macOS From 29c263f87810f8566ebdad2358e99896391adfd8 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Sat, 5 Mar 2022 12:15:14 -0800 Subject: [PATCH 36/38] pydoc formatting fixes --- docs/lib.md | 16 ++++++++-------- docs/parsers/acpi.md | 2 +- docs/parsers/airport.md | 2 +- docs/parsers/airport_s.md | 2 +- docs/parsers/arp.md | 2 +- docs/parsers/blkid.md | 2 +- docs/parsers/cksum.md | 2 +- docs/parsers/crontab.md | 2 +- docs/parsers/crontab_u.md | 2 +- docs/parsers/csv.md | 2 +- docs/parsers/csv_s.md | 2 +- docs/parsers/date.md | 2 +- docs/parsers/df.md | 2 +- docs/parsers/dig.md | 2 +- docs/parsers/dir.md | 2 +- docs/parsers/dmidecode.md | 2 +- docs/parsers/dpkg_l.md | 2 +- docs/parsers/du.md | 2 +- docs/parsers/env.md | 2 +- docs/parsers/file.md | 2 +- docs/parsers/finger.md | 2 +- docs/parsers/free.md | 2 +- docs/parsers/fstab.md | 2 +- docs/parsers/group.md | 2 +- docs/parsers/gshadow.md | 2 +- docs/parsers/hash.md | 2 +- docs/parsers/hashsum.md | 2 +- docs/parsers/hciconfig.md | 2 +- docs/parsers/history.md | 2 +- docs/parsers/hosts.md | 2 +- docs/parsers/id.md | 2 +- docs/parsers/ifconfig.md | 2 +- docs/parsers/ini.md | 2 +- docs/parsers/iostat.md | 2 +- docs/parsers/iostat_s.md | 2 +- docs/parsers/iptables.md | 2 +- docs/parsers/iw_scan.md | 2 +- docs/parsers/jar_manifest.md | 2 +- docs/parsers/jobs.md | 2 +- docs/parsers/kv.md | 2 +- docs/parsers/last.md | 2 +- docs/parsers/ls.md | 2 +- docs/parsers/ls_s.md | 2 +- docs/parsers/lsblk.md | 2 +- docs/parsers/lsmod.md | 2 +- docs/parsers/lsof.md | 2 +- docs/parsers/lsusb.md | 2 +- docs/parsers/mount.md | 2 +- docs/parsers/netstat.md | 2 +- docs/parsers/nmcli.md | 2 +- docs/parsers/ntpq.md | 2 +- docs/parsers/passwd.md | 2 +- docs/parsers/ping.md | 2 +- docs/parsers/ping_s.md | 2 +- docs/parsers/pip_list.md | 2 +- docs/parsers/pip_show.md | 2 +- docs/parsers/ps.md | 2 +- docs/parsers/route.md | 2 +- docs/parsers/rpm_qi.md | 2 +- docs/parsers/rsync.md | 2 +- docs/parsers/rsync_s.md | 2 +- docs/parsers/sfdisk.md | 2 +- docs/parsers/shadow.md | 2 +- docs/parsers/ss.md | 2 +- docs/parsers/stat.md | 2 +- docs/parsers/stat_s.md | 2 +- docs/parsers/sysctl.md | 2 +- docs/parsers/systemctl.md | 2 +- docs/parsers/systemctl_lj.md | 2 +- docs/parsers/systemctl_ls.md | 2 +- docs/parsers/systemctl_luf.md | 2 +- docs/parsers/systeminfo.md | 2 +- docs/parsers/time.md | 2 +- docs/parsers/timedatectl.md | 2 +- docs/parsers/tracepath.md | 2 +- docs/parsers/traceroute.md | 2 +- docs/parsers/ufw.md | 2 +- docs/parsers/ufw_appinfo.md | 2 +- docs/parsers/uname.md | 2 +- docs/parsers/universal.md | 4 ++-- docs/parsers/upower.md | 2 +- docs/parsers/uptime.md | 2 +- docs/parsers/vmstat.md | 2 +- docs/parsers/vmstat_s.md | 2 +- docs/parsers/w.md | 2 +- docs/parsers/wc.md | 2 +- docs/parsers/who.md | 2 +- docs/parsers/xml.md | 2 +- docs/parsers/xrandr.md | 2 +- docs/parsers/yaml.md | 2 +- docs/parsers/zipinfo.md | 2 +- docs/streaming.md | 12 ++++++------ docs/utils.md | 20 ++++++++++---------- 93 files changed, 115 insertions(+), 115 deletions(-) diff --git a/docs/lib.md b/docs/lib.md index 67e5ea34..ae714f9e 100644 --- a/docs/lib.md +++ b/docs/lib.md @@ -19,7 +19,7 @@ JC lib module -#### parse +### parse ```python def parse(parser_mod_name: str, @@ -86,7 +86,7 @@ Returns: -#### parser\_mod\_list +### parser\_mod\_list ```python def parser_mod_list() -> List[str] @@ -96,7 +96,7 @@ Returns a list of all available parser module names. -#### plugin\_parser\_mod\_list +### plugin\_parser\_mod\_list ```python def plugin_parser_mod_list() -> List[str] @@ -107,7 +107,7 @@ subset of `parser_mod_list()`. -#### standard\_parser\_mod\_list +### standard\_parser\_mod\_list ```python def standard_parser_mod_list() -> List[str] @@ -119,7 +119,7 @@ parsers. -#### streaming\_parser\_mod\_list +### streaming\_parser\_mod\_list ```python def streaming_parser_mod_list() -> List[str] @@ -130,7 +130,7 @@ subset of `parser_mod_list()`. -#### parser\_info +### parser\_info ```python def parser_info(parser_mod_name: str) -> Dict @@ -143,7 +143,7 @@ This function will accept **module_name**, **cli-name**, and -#### all\_parser\_info +### all\_parser\_info ```python def all_parser_info() -> List[Dict] @@ -153,7 +153,7 @@ Returns a list of dictionaries that includes metadata for all modules. -#### get\_help +### get\_help ```python def get_help(parser_mod_name: str) -> None diff --git a/docs/parsers/acpi.md b/docs/parsers/acpi.md index e486954f..98202760 100644 --- a/docs/parsers/acpi.md +++ b/docs/parsers/acpi.md @@ -234,7 +234,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/airport.md b/docs/parsers/airport.md index e9fa5490..4ec9bad3 100644 --- a/docs/parsers/airport.md +++ b/docs/parsers/airport.md @@ -87,7 +87,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/airport_s.md b/docs/parsers/airport_s.md index 84b8e4a0..b4354c45 100644 --- a/docs/parsers/airport_s.md +++ b/docs/parsers/airport_s.md @@ -115,7 +115,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/arp.md b/docs/parsers/arp.md index 136476b6..ad76015f 100644 --- a/docs/parsers/arp.md +++ b/docs/parsers/arp.md @@ -124,7 +124,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/blkid.md b/docs/parsers/blkid.md index 11f81041..09fb8abe 100644 --- a/docs/parsers/blkid.md +++ b/docs/parsers/blkid.md @@ -127,7 +127,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/cksum.md b/docs/parsers/cksum.md index aee5efc4..2ab0ecf6 100644 --- a/docs/parsers/cksum.md +++ b/docs/parsers/cksum.md @@ -61,7 +61,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/crontab.md b/docs/parsers/crontab.md index ae9c4c31..dfd27bf6 100644 --- a/docs/parsers/crontab.md +++ b/docs/parsers/crontab.md @@ -180,7 +180,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/crontab_u.md b/docs/parsers/crontab_u.md index bfcd45a6..0ae1817d 100644 --- a/docs/parsers/crontab_u.md +++ b/docs/parsers/crontab_u.md @@ -177,7 +177,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/csv.md b/docs/parsers/csv.md index d98a4945..16c65905 100644 --- a/docs/parsers/csv.md +++ b/docs/parsers/csv.md @@ -84,7 +84,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/csv_s.md b/docs/parsers/csv_s.md index 902d117b..4515a77b 100644 --- a/docs/parsers/csv_s.md +++ b/docs/parsers/csv_s.md @@ -70,7 +70,7 @@ Examples: -#### parse +### parse ```python @add_jc_meta diff --git a/docs/parsers/date.md b/docs/parsers/date.md index d348d089..6da56dc5 100644 --- a/docs/parsers/date.md +++ b/docs/parsers/date.md @@ -84,7 +84,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/df.md b/docs/parsers/df.md index 25ee0773..717a9637 100644 --- a/docs/parsers/df.md +++ b/docs/parsers/df.md @@ -104,7 +104,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/dig.md b/docs/parsers/dig.md index 70bd67ea..4903fc82 100644 --- a/docs/parsers/dig.md +++ b/docs/parsers/dig.md @@ -329,7 +329,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/dir.md b/docs/parsers/dir.md index 84a76476..c04e4de6 100644 --- a/docs/parsers/dir.md +++ b/docs/parsers/dir.md @@ -127,7 +127,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/dmidecode.md b/docs/parsers/dmidecode.md index a7664b6d..8c7072ac 100644 --- a/docs/parsers/dmidecode.md +++ b/docs/parsers/dmidecode.md @@ -132,7 +132,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/dpkg_l.md b/docs/parsers/dpkg_l.md index 6b24634c..97ed8209 100644 --- a/docs/parsers/dpkg_l.md +++ b/docs/parsers/dpkg_l.md @@ -138,7 +138,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/du.md b/docs/parsers/du.md index 12ec1ca4..fe2f5511 100644 --- a/docs/parsers/du.md +++ b/docs/parsers/du.md @@ -94,7 +94,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/env.md b/docs/parsers/env.md index dd625602..1b951549 100644 --- a/docs/parsers/env.md +++ b/docs/parsers/env.md @@ -79,7 +79,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/file.md b/docs/parsers/file.md index b95f0d29..25895fe7 100644 --- a/docs/parsers/file.md +++ b/docs/parsers/file.md @@ -69,7 +69,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/finger.md b/docs/parsers/finger.md index 56daa2bc..b9445add 100644 --- a/docs/parsers/finger.md +++ b/docs/parsers/finger.md @@ -97,7 +97,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/free.md b/docs/parsers/free.md index 1b8fd722..5f540ace 100644 --- a/docs/parsers/free.md +++ b/docs/parsers/free.md @@ -79,7 +79,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/fstab.md b/docs/parsers/fstab.md index 5f4a2773..60c6555e 100644 --- a/docs/parsers/fstab.md +++ b/docs/parsers/fstab.md @@ -92,7 +92,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/group.md b/docs/parsers/group.md index 0e3fb442..33ca0cdf 100644 --- a/docs/parsers/group.md +++ b/docs/parsers/group.md @@ -116,7 +116,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/gshadow.md b/docs/parsers/gshadow.md index 1a1b7a70..e48012f9 100644 --- a/docs/parsers/gshadow.md +++ b/docs/parsers/gshadow.md @@ -84,7 +84,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/hash.md b/docs/parsers/hash.md index ca6109e0..74cde8f5 100644 --- a/docs/parsers/hash.md +++ b/docs/parsers/hash.md @@ -44,7 +44,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/hashsum.md b/docs/parsers/hashsum.md index 984babe3..b8b76634 100644 --- a/docs/parsers/hashsum.md +++ b/docs/parsers/hashsum.md @@ -75,7 +75,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/hciconfig.md b/docs/parsers/hciconfig.md index 9fe21dcb..240cc50c 100644 --- a/docs/parsers/hciconfig.md +++ b/docs/parsers/hciconfig.md @@ -324,7 +324,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/history.md b/docs/parsers/history.md index 19b5be41..5edd0ce6 100644 --- a/docs/parsers/history.md +++ b/docs/parsers/history.md @@ -70,7 +70,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/hosts.md b/docs/parsers/hosts.md index 2aecaac7..dd77a886 100644 --- a/docs/parsers/hosts.md +++ b/docs/parsers/hosts.md @@ -81,7 +81,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/id.md b/docs/parsers/id.md index ac8efbc0..b37a97d7 100644 --- a/docs/parsers/id.md +++ b/docs/parsers/id.md @@ -112,7 +112,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/ifconfig.md b/docs/parsers/ifconfig.md index 686426d7..de99c8db 100644 --- a/docs/parsers/ifconfig.md +++ b/docs/parsers/ifconfig.md @@ -193,7 +193,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/ini.md b/docs/parsers/ini.md index eac8190d..5e2dc174 100644 --- a/docs/parsers/ini.md +++ b/docs/parsers/ini.md @@ -73,7 +73,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/iostat.md b/docs/parsers/iostat.md index fdf63c60..b8e5fae5 100644 --- a/docs/parsers/iostat.md +++ b/docs/parsers/iostat.md @@ -166,7 +166,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/iostat_s.md b/docs/parsers/iostat_s.md index 162fd3a9..8e598bbc 100644 --- a/docs/parsers/iostat_s.md +++ b/docs/parsers/iostat_s.md @@ -107,7 +107,7 @@ Examples: -#### parse +### parse ```python @add_jc_meta diff --git a/docs/parsers/iptables.md b/docs/parsers/iptables.md index 9a98a899..c51d6d13 100644 --- a/docs/parsers/iptables.md +++ b/docs/parsers/iptables.md @@ -170,7 +170,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/iw_scan.md b/docs/parsers/iw_scan.md index 5dd0bd85..b39de09e 100644 --- a/docs/parsers/iw_scan.md +++ b/docs/parsers/iw_scan.md @@ -128,7 +128,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/jar_manifest.md b/docs/parsers/jar_manifest.md index 2b14cebc..91964220 100644 --- a/docs/parsers/jar_manifest.md +++ b/docs/parsers/jar_manifest.md @@ -84,7 +84,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/jobs.md b/docs/parsers/jobs.md index 69209734..ab7da0dd 100644 --- a/docs/parsers/jobs.md +++ b/docs/parsers/jobs.md @@ -100,7 +100,7 @@ Example: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/kv.md b/docs/parsers/kv.md index 4b71f64d..9959671a 100644 --- a/docs/parsers/kv.md +++ b/docs/parsers/kv.md @@ -60,7 +60,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/last.md b/docs/parsers/last.md index b2dfb32c..910e405f 100644 --- a/docs/parsers/last.md +++ b/docs/parsers/last.md @@ -111,7 +111,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/ls.md b/docs/parsers/ls.md index d3b0ea8b..578b3dfb 100644 --- a/docs/parsers/ls.md +++ b/docs/parsers/ls.md @@ -123,7 +123,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/ls_s.md b/docs/parsers/ls_s.md index 82ce4f6a..20bc6a90 100644 --- a/docs/parsers/ls_s.md +++ b/docs/parsers/ls_s.md @@ -84,7 +84,7 @@ Examples: -#### parse +### parse ```python @add_jc_meta diff --git a/docs/parsers/lsblk.md b/docs/parsers/lsblk.md index 24c8d6e8..0e8ba14e 100644 --- a/docs/parsers/lsblk.md +++ b/docs/parsers/lsblk.md @@ -281,7 +281,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/lsmod.md b/docs/parsers/lsmod.md index dda48fb4..705f45ff 100644 --- a/docs/parsers/lsmod.md +++ b/docs/parsers/lsmod.md @@ -132,7 +132,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/lsof.md b/docs/parsers/lsof.md index 90945628..bff7b40c 100644 --- a/docs/parsers/lsof.md +++ b/docs/parsers/lsof.md @@ -126,7 +126,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/lsusb.md b/docs/parsers/lsusb.md index 9be5c776..fa27c836 100644 --- a/docs/parsers/lsusb.md +++ b/docs/parsers/lsusb.md @@ -268,7 +268,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/mount.md b/docs/parsers/mount.md index cee2b027..e5bbea98 100644 --- a/docs/parsers/mount.md +++ b/docs/parsers/mount.md @@ -82,7 +82,7 @@ Example: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/netstat.md b/docs/parsers/netstat.md index 260237ef..01d0782b 100644 --- a/docs/parsers/netstat.md +++ b/docs/parsers/netstat.md @@ -362,7 +362,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/nmcli.md b/docs/parsers/nmcli.md index b0971100..3df6a3de 100644 --- a/docs/parsers/nmcli.md +++ b/docs/parsers/nmcli.md @@ -152,7 +152,7 @@ Examples: -#### parse +### parse ```python def parse(data: str, raw: bool = False, quiet: bool = False) -> List[Dict] diff --git a/docs/parsers/ntpq.md b/docs/parsers/ntpq.md index 73e30589..ff043328 100644 --- a/docs/parsers/ntpq.md +++ b/docs/parsers/ntpq.md @@ -213,7 +213,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/passwd.md b/docs/parsers/passwd.md index f30b1f39..498c1cfb 100644 --- a/docs/parsers/passwd.md +++ b/docs/parsers/passwd.md @@ -101,7 +101,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/ping.md b/docs/parsers/ping.md index eaea4e9c..a5e1f2cd 100644 --- a/docs/parsers/ping.md +++ b/docs/parsers/ping.md @@ -169,7 +169,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/ping_s.md b/docs/parsers/ping_s.md index 7fc3c204..f678bbca 100644 --- a/docs/parsers/ping_s.md +++ b/docs/parsers/ping_s.md @@ -90,7 +90,7 @@ Examples: -#### parse +### parse ```python @add_jc_meta diff --git a/docs/parsers/pip_list.md b/docs/parsers/pip_list.md index c05f99cb..33906cdf 100644 --- a/docs/parsers/pip_list.md +++ b/docs/parsers/pip_list.md @@ -54,7 +54,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/pip_show.md b/docs/parsers/pip_show.md index b378f604..661bc526 100644 --- a/docs/parsers/pip_show.md +++ b/docs/parsers/pip_show.md @@ -72,7 +72,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/ps.md b/docs/parsers/ps.md index 51aece3a..ef02011a 100644 --- a/docs/parsers/ps.md +++ b/docs/parsers/ps.md @@ -213,7 +213,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/route.md b/docs/parsers/route.md index 961f21d8..022676a7 100644 --- a/docs/parsers/route.md +++ b/docs/parsers/route.md @@ -115,7 +115,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/rpm_qi.md b/docs/parsers/rpm_qi.md index 7e1c5782..b0238a17 100644 --- a/docs/parsers/rpm_qi.md +++ b/docs/parsers/rpm_qi.md @@ -168,7 +168,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/rsync.md b/docs/parsers/rsync.md index 1271c1e7..dd799fdf 100644 --- a/docs/parsers/rsync.md +++ b/docs/parsers/rsync.md @@ -141,7 +141,7 @@ Examples: -#### parse +### parse ```python def parse(data: str, raw: bool = False, quiet: bool = False) -> List[Dict] diff --git a/docs/parsers/rsync_s.md b/docs/parsers/rsync_s.md index f42fc855..b3e41c30 100644 --- a/docs/parsers/rsync_s.md +++ b/docs/parsers/rsync_s.md @@ -95,7 +95,7 @@ Examples: -#### parse +### parse ```python @add_jc_meta diff --git a/docs/parsers/sfdisk.md b/docs/parsers/sfdisk.md index 91ee9862..4358b074 100644 --- a/docs/parsers/sfdisk.md +++ b/docs/parsers/sfdisk.md @@ -209,7 +209,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/shadow.md b/docs/parsers/shadow.md index fae577e2..ef615c26 100644 --- a/docs/parsers/shadow.md +++ b/docs/parsers/shadow.md @@ -108,7 +108,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/ss.md b/docs/parsers/ss.md index bbe984f8..bd0ed975 100644 --- a/docs/parsers/ss.md +++ b/docs/parsers/ss.md @@ -287,7 +287,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/stat.md b/docs/parsers/stat.md index c950a568..9240b290 100644 --- a/docs/parsers/stat.md +++ b/docs/parsers/stat.md @@ -177,7 +177,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/stat_s.md b/docs/parsers/stat_s.md index 1b438ab2..0813541f 100644 --- a/docs/parsers/stat_s.md +++ b/docs/parsers/stat_s.md @@ -88,7 +88,7 @@ Examples: -#### parse +### parse ```python @add_jc_meta diff --git a/docs/parsers/sysctl.md b/docs/parsers/sysctl.md index c19ca743..e0ac3892 100644 --- a/docs/parsers/sysctl.md +++ b/docs/parsers/sysctl.md @@ -64,7 +64,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/systemctl.md b/docs/parsers/systemctl.md index 085ad486..e6d03231 100644 --- a/docs/parsers/systemctl.md +++ b/docs/parsers/systemctl.md @@ -65,7 +65,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/systemctl_lj.md b/docs/parsers/systemctl_lj.md index 007e8261..68bfed5d 100644 --- a/docs/parsers/systemctl_lj.md +++ b/docs/parsers/systemctl_lj.md @@ -82,7 +82,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/systemctl_ls.md b/docs/parsers/systemctl_ls.md index f5783a95..cd13a9c0 100644 --- a/docs/parsers/systemctl_ls.md +++ b/docs/parsers/systemctl_ls.md @@ -58,7 +58,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/systemctl_luf.md b/docs/parsers/systemctl_luf.md index 79a858a2..ab3d2983 100644 --- a/docs/parsers/systemctl_luf.md +++ b/docs/parsers/systemctl_luf.md @@ -54,7 +54,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/systeminfo.md b/docs/parsers/systeminfo.md index 616e23dd..0b442e5f 100644 --- a/docs/parsers/systeminfo.md +++ b/docs/parsers/systeminfo.md @@ -218,7 +218,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/time.md b/docs/parsers/time.md index ed79b975..bdf3f1a4 100644 --- a/docs/parsers/time.md +++ b/docs/parsers/time.md @@ -139,7 +139,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/timedatectl.md b/docs/parsers/timedatectl.md index 94d50ed1..ddcd4c73 100644 --- a/docs/parsers/timedatectl.md +++ b/docs/parsers/timedatectl.md @@ -71,7 +71,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/tracepath.md b/docs/parsers/tracepath.md index 73d4f6ef..9a8256c5 100644 --- a/docs/parsers/tracepath.md +++ b/docs/parsers/tracepath.md @@ -138,7 +138,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/traceroute.md b/docs/parsers/traceroute.md index 2a0ff614..f98e5ba3 100644 --- a/docs/parsers/traceroute.md +++ b/docs/parsers/traceroute.md @@ -127,7 +127,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/ufw.md b/docs/parsers/ufw.md index fa26ae84..86e625ee 100644 --- a/docs/parsers/ufw.md +++ b/docs/parsers/ufw.md @@ -207,7 +207,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/ufw_appinfo.md b/docs/parsers/ufw_appinfo.md index 54711331..cb15ac4d 100644 --- a/docs/parsers/ufw_appinfo.md +++ b/docs/parsers/ufw_appinfo.md @@ -145,7 +145,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/uname.md b/docs/parsers/uname.md index b4a9329e..d583146c 100644 --- a/docs/parsers/uname.md +++ b/docs/parsers/uname.md @@ -54,7 +54,7 @@ Example: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/universal.md b/docs/parsers/universal.md index fbd7edee..5327ed83 100644 --- a/docs/parsers/universal.md +++ b/docs/parsers/universal.md @@ -12,7 +12,7 @@ jc - JSON Convert universal parsers -#### simple\_table\_parse +### simple\_table\_parse ```python def simple_table_parse(data: List[str]) -> List[Dict] @@ -37,7 +37,7 @@ Returns: -#### sparse\_table\_parse +### sparse\_table\_parse ```python def sparse_table_parse(data: List[str], delim: str = '\u2063') -> List[Dict] diff --git a/docs/parsers/upower.md b/docs/parsers/upower.md index 55a9a4c6..f8d513a4 100644 --- a/docs/parsers/upower.md +++ b/docs/parsers/upower.md @@ -205,7 +205,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/uptime.md b/docs/parsers/uptime.md index f63a3d42..d2c5ccea 100644 --- a/docs/parsers/uptime.md +++ b/docs/parsers/uptime.md @@ -72,7 +72,7 @@ Example: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/vmstat.md b/docs/parsers/vmstat.md index 1690b11e..fea78a6a 100644 --- a/docs/parsers/vmstat.md +++ b/docs/parsers/vmstat.md @@ -133,7 +133,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/vmstat_s.md b/docs/parsers/vmstat_s.md index 8d39e959..c2d35e39 100644 --- a/docs/parsers/vmstat_s.md +++ b/docs/parsers/vmstat_s.md @@ -107,7 +107,7 @@ Examples: -#### parse +### parse ```python @add_jc_meta diff --git a/docs/parsers/w.md b/docs/parsers/w.md index e754b7c8..6ff07141 100644 --- a/docs/parsers/w.md +++ b/docs/parsers/w.md @@ -110,7 +110,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/wc.md b/docs/parsers/wc.md index f58d1058..2969bf12 100644 --- a/docs/parsers/wc.md +++ b/docs/parsers/wc.md @@ -61,7 +61,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/who.md b/docs/parsers/who.md index 7dfdd25e..7d7eed62 100644 --- a/docs/parsers/who.md +++ b/docs/parsers/who.md @@ -142,7 +142,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/xml.md b/docs/parsers/xml.md index fa866d76..6e822260 100644 --- a/docs/parsers/xml.md +++ b/docs/parsers/xml.md @@ -77,7 +77,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/xrandr.md b/docs/parsers/xrandr.md index d5c05e8f..76d926b7 100644 --- a/docs/parsers/xrandr.md +++ b/docs/parsers/xrandr.md @@ -144,7 +144,7 @@ Examples: -#### parse +### parse ```python def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict diff --git a/docs/parsers/yaml.md b/docs/parsers/yaml.md index 18234a8c..6e774c7c 100644 --- a/docs/parsers/yaml.md +++ b/docs/parsers/yaml.md @@ -91,7 +91,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/parsers/zipinfo.md b/docs/parsers/zipinfo.md index e56ad2f0..e2ca96f7 100644 --- a/docs/parsers/zipinfo.md +++ b/docs/parsers/zipinfo.md @@ -86,7 +86,7 @@ Examples: -#### parse +### parse ```python def parse(data, raw=False, quiet=False) diff --git a/docs/streaming.md b/docs/streaming.md index f97f9d9f..71e61b8a 100644 --- a/docs/streaming.md +++ b/docs/streaming.md @@ -16,7 +16,7 @@ jc - JSON Convert streaming utils -#### streaming\_input\_type\_check +### streaming\_input\_type\_check ```python def streaming_input_type_check(data: Iterable) -> None @@ -27,7 +27,7 @@ Ensure input data is an iterable, but not a string or bytes. Raises -#### streaming\_line\_input\_type\_check +### streaming\_line\_input\_type\_check ```python def streaming_line_input_type_check(line: str) -> None @@ -37,7 +37,7 @@ Ensure each line is a string. Raises `TypeError` if not. -#### stream\_success +### stream\_success ```python def stream_success(output_line: Dict, ignore_exceptions: bool) -> Dict @@ -47,7 +47,7 @@ Add `_jc_meta` object to output line if `ignore_exceptions=True` -#### stream\_error +### stream\_error ```python def stream_error(e: BaseException, line: str) -> Dict @@ -57,7 +57,7 @@ Return an error `_jc_meta` field. -#### add\_jc\_meta +### add\_jc\_meta ```python def add_jc_meta(func) @@ -102,7 +102,7 @@ In all cases above: -#### raise\_or\_yield +### raise\_or\_yield ```python def raise_or_yield(ignore_exceptions: bool, e: BaseException, diff --git a/docs/utils.md b/docs/utils.md index de72f4f7..f35a53a4 100644 --- a/docs/utils.md +++ b/docs/utils.md @@ -20,7 +20,7 @@ jc - JSON Convert utils -#### warning\_message +### warning\_message ```python def warning_message(message_lines: List[str]) -> None @@ -40,7 +40,7 @@ Returns: -#### error\_message +### error\_message ```python def error_message(message_lines: List[str]) -> None @@ -60,7 +60,7 @@ Returns: -#### compatibility +### compatibility ```python def compatibility(mod_name: str, @@ -87,7 +87,7 @@ Returns: -#### has\_data +### has\_data ```python def has_data(data: str) -> bool @@ -107,7 +107,7 @@ Returns: -#### convert\_to\_int +### convert\_to\_int ```python def convert_to_int(value: Union[str, float]) -> Optional[int] @@ -126,7 +126,7 @@ Returns: -#### convert\_to\_float +### convert\_to\_float ```python def convert_to_float(value: Union[str, int]) -> Optional[float] @@ -145,7 +145,7 @@ Returns: -#### convert\_to\_bool +### convert\_to\_bool ```python def convert_to_bool(value: Union[str, int, float]) -> bool @@ -165,7 +165,7 @@ Returns: -#### input\_type\_check +### input\_type\_check ```python def input_type_check(data: str) -> None @@ -175,7 +175,7 @@ Ensure input data is a string. Raises `TypeError` if not. -## timestamp Objects +### timestamp Objects ```python class timestamp() @@ -183,7 +183,7 @@ class timestamp() -#### \_\_init\_\_ +### \_\_init\_\_ ```python def __init__(datetime_string: str, From ca79053db08542849136ae13fdb4d1d90b79a7e5 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Sat, 5 Mar 2022 12:15:47 -0800 Subject: [PATCH 37/38] document pydoc version --- docgen.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docgen.sh b/docgen.sh index 8b2b272d..812d8aed 100755 --- a/docgen.sh +++ b/docgen.sh @@ -1,6 +1,6 @@ #!/bin/bash # Generate docs.md -# requires pydoc-markdown 4.5.0 +# requires pydoc-markdown 4.6.1 readme_config=$(cat <<'EOF' { "processors": [ From 98619834818c181cb50a9605fe166b6153c46095 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Sat, 5 Mar 2022 13:45:28 -0800 Subject: [PATCH 38/38] doc update --- man/jc.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/jc.1 b/man/jc.1 index e299572e..cabf84e9 100644 --- a/man/jc.1 +++ b/man/jc.1 @@ -1,4 +1,4 @@ -.TH jc 1 2022-03-04 1.18.4 "JSON Convert" +.TH jc 1 2022-03-05 1.18.4 "JSON Convert" .SH NAME jc \- JSONifies the output of many CLI tools and file-types .SH SYNOPSIS