diff --git a/CHANGELOG b/CHANGELOG index 7706e9f4e..1799e51d9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,23 @@ jc changelog +20240323 v1.25.2 +- Add `apt-cache-show` command parser +- Add `apt-get-sqq` command parser +- Add `ethtool` command parser +- Add `needrestart` command parser +- Enhance `df` parser to add human readable output support. Note: the `size` + field has been changed to an integer and all size values have been normalized + to bytes. +- Enhance `free` parser to add human readable output support. All size values + have been normalizd to bytes. +- Enhance `iptables` parser to handle -x output +- Enhance `/proc/pid/stat` parser to support "Idle" state +- Enhance `rpm_qi` and `pkg_index_deb` parsers to split list fields into arrays +- Fix `iwconfig` parser to handle more special characters in the SSID name +- Fix `xrandr` parser to ignore extra horizontal and vertical stats lines +- Add aarch64 binaries to Releases for macOS and Linux +- Documentation and doc build updates + 20240212 v1.25.1 - Fix for crash when optional libraries are not installed (e.g. xmltodict) - Fix for `ini` parser crashing with some keys with no values diff --git a/README.md b/README.md index f61b6cb4e..b81ca7dc0 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ function parameter in `parse()` when using `jc` as a python library. Schemas for each parser can be found at the documentation link beside each [**Parser**](#parsers) below. -Release notes can be found [here](https://blog.kellybrazil.com/category/jc-news/). +Release notes can be found in the [Releases section](https://github.com/kellyjonbrazil/jc/releases) on Github. ## Why Would Anyone Do This!? For more information on the motivations for this project, please see my blog @@ -159,6 +159,8 @@ option. | `--acpi` | `acpi` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/acpi) | | `--airport` | `airport -I` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/airport) | | `--airport-s` | `airport -s` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/airport_s) | +| `--apt-cache-show` | `apt-cache show` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/apt_cache_show) | +| `--apt-get-sqq` | `apt-get -sqq` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/apt_get_sqq) | | `--arp` | `arp` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/arp) | | `--asciitable` | ASCII and Unicode table parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/asciitable) | | `--asciitable-m` | multi-line ASCII and Unicode table parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/asciitable_m) | @@ -189,6 +191,7 @@ option. | `--efibootmgr` | `efibootmgr` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/efibootmgr) | | `--email-address` | Email Address string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/email_address) | | `--env` | `env` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/env) | +| `--ethtool` | `ethtool` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ethtool) | | `--file` | `file` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/file) | | `--find` | `find` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/find) | | `--findmnt` | `findmnt` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/findmnt) | @@ -239,6 +242,7 @@ option. | `--mount` | `mount` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/mount) | | `--mpstat` | `mpstat` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/mpstat) | | `--mpstat-s` | `mpstat` command streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/mpstat_s) | +| `--needrestart` | `needrestart -b` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/needrestart) | | `--netstat` | `netstat` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/netstat) | | `--nmcli` | `nmcli` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/nmcli) | | `--nsd-control` | `nsd-control` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/nsd_control) | diff --git a/completions/jc_bash_completion.sh b/completions/jc_bash_completion.sh index 0c4880348..445cc14c9 100644 --- a/completions/jc_bash_completion.sh +++ b/completions/jc_bash_completion.sh @@ -3,8 +3,8 @@ _jc() local cur prev words cword jc_commands jc_parsers jc_options \ jc_about_options jc_about_mod_options jc_help_options jc_special_options - jc_commands=(acpi airport arp blkid bluetoothctl cbt certbot chage cksum crontab curl date debconf-show df dig dmidecode dpkg du efibootmgr env file findmnt finger free git gpg hciconfig host id ifconfig iostat ip iptables iw iwconfig jobs last lastb ls lsattr lsb_release lsblk lsmod lsof lspci lsusb md5 md5sum mdadm mount mpstat netstat nmcli nsd-control ntpq os-prober pidstat ping ping6 pip pip3 postconf printenv ps route rpm rsync sfdisk sha1sum sha224sum sha256sum sha384sum sha512sum shasum ss ssh sshd stat sum swapon sysctl systemctl systeminfo timedatectl top tracepath tracepath6 traceroute traceroute6 tune2fs udevadm ufw uname update-alternatives upower uptime vdir veracrypt vmstat w wc who xrandr zipinfo zpool) - jc_parsers=(--acpi --airport --airport-s --arp --asciitable --asciitable-m --blkid --bluetoothctl --cbt --cef --cef-s --certbot --chage --cksum --clf --clf-s --crontab --crontab-u --csv --csv-s --curl-head --date --datetime-iso --debconf-show --df --dig --dir --dmidecode --dpkg-l --du --efibootmgr --email-address --env --file --find --findmnt --finger --free --fstab --git-log --git-log-s --git-ls-remote --gpg --group --gshadow --hash --hashsum --hciconfig --history --host --hosts --http-headers --id --ifconfig --ini --ini-dup --iostat --iostat-s --ip-address --iptables --ip-route --iw-scan --iwconfig --jar-manifest --jobs --jwt --kv --kv-dup --last --ls --ls-s --lsattr --lsb-release --lsblk --lsmod --lsof --lspci --lsusb --m3u --mdadm --mount --mpstat --mpstat-s --netstat --nmcli --nsd-control --ntpq --openvpn --os-prober --os-release --passwd --path --path-list --pci-ids --pgpass --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --pkg-index-apk --pkg-index-deb --plist --postconf --proc --proc-buddyinfo --proc-cmdline --proc-consoles --proc-cpuinfo --proc-crypto --proc-devices --proc-diskstats --proc-filesystems --proc-interrupts --proc-iomem --proc-ioports --proc-loadavg --proc-locks --proc-meminfo --proc-modules --proc-mtrr --proc-pagetypeinfo --proc-partitions --proc-slabinfo --proc-softirqs --proc-stat --proc-swaps --proc-uptime --proc-version --proc-vmallocinfo --proc-vmstat --proc-zoneinfo --proc-driver-rtc --proc-net-arp --proc-net-dev --proc-net-dev-mcast --proc-net-if-inet6 --proc-net-igmp --proc-net-igmp6 --proc-net-ipv6-route --proc-net-netlink --proc-net-netstat --proc-net-packet --proc-net-protocols --proc-net-route --proc-net-tcp --proc-net-unix --proc-pid-fdinfo --proc-pid-io --proc-pid-maps --proc-pid-mountinfo --proc-pid-numa-maps --proc-pid-smaps --proc-pid-stat --proc-pid-statm --proc-pid-status --ps --resolve-conf --route --rpm-qi --rsync --rsync-s --semver --sfdisk --shadow --srt --ss --ssh-conf --sshd-conf --stat --stat-s --swapon --sysctl --syslog --syslog-s --syslog-bsd --syslog-bsd-s --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --toml --top --top-s --tracepath --traceroute --tune2fs --udevadm --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --ver --veracrypt --vmstat --vmstat-s --w --wc --who --x509-cert --x509-csr --xml --xrandr --yaml --zipinfo --zpool-iostat --zpool-status) + jc_commands=(acpi airport apt-cache apt-get arp blkid bluetoothctl cbt certbot chage cksum crontab curl date debconf-show df dig dmidecode dpkg du efibootmgr env ethtool file findmnt finger free git gpg hciconfig host id ifconfig iostat ip iptables iw iwconfig jobs last lastb ls lsattr lsb_release lsblk lsmod lsof lspci lsusb md5 md5sum mdadm mount mpstat needrestart netstat nmcli nsd-control ntpq os-prober pidstat ping ping6 pip pip3 postconf printenv ps route rpm rsync sfdisk sha1sum sha224sum sha256sum sha384sum sha512sum shasum ss ssh sshd stat sum swapon sysctl systemctl systeminfo timedatectl top tracepath tracepath6 traceroute traceroute6 tune2fs udevadm ufw uname update-alternatives upower uptime vdir veracrypt vmstat w wc who xrandr zipinfo zpool) + jc_parsers=(--acpi --airport --airport-s --apt-cache-show --apt-get-sqq --arp --asciitable --asciitable-m --blkid --bluetoothctl --cbt --cef --cef-s --certbot --chage --cksum --clf --clf-s --crontab --crontab-u --csv --csv-s --curl-head --date --datetime-iso --debconf-show --df --dig --dir --dmidecode --dpkg-l --du --efibootmgr --email-address --env --ethtool --file --find --findmnt --finger --free --fstab --git-log --git-log-s --git-ls-remote --gpg --group --gshadow --hash --hashsum --hciconfig --history --host --hosts --http-headers --id --ifconfig --ini --ini-dup --iostat --iostat-s --ip-address --iptables --ip-route --iw-scan --iwconfig --jar-manifest --jobs --jwt --kv --kv-dup --last --ls --ls-s --lsattr --lsb-release --lsblk --lsmod --lsof --lspci --lsusb --m3u --mdadm --mount --mpstat --mpstat-s --needrestart --netstat --nmcli --nsd-control --ntpq --openvpn --os-prober --os-release --passwd --path --path-list --pci-ids --pgpass --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --pkg-index-apk --pkg-index-deb --plist --postconf --proc --proc-buddyinfo --proc-cmdline --proc-consoles --proc-cpuinfo --proc-crypto --proc-devices --proc-diskstats --proc-filesystems --proc-interrupts --proc-iomem --proc-ioports --proc-loadavg --proc-locks --proc-meminfo --proc-modules --proc-mtrr --proc-pagetypeinfo --proc-partitions --proc-slabinfo --proc-softirqs --proc-stat --proc-swaps --proc-uptime --proc-version --proc-vmallocinfo --proc-vmstat --proc-zoneinfo --proc-driver-rtc --proc-net-arp --proc-net-dev --proc-net-dev-mcast --proc-net-if-inet6 --proc-net-igmp --proc-net-igmp6 --proc-net-ipv6-route --proc-net-netlink --proc-net-netstat --proc-net-packet --proc-net-protocols --proc-net-route --proc-net-tcp --proc-net-unix --proc-pid-fdinfo --proc-pid-io --proc-pid-maps --proc-pid-mountinfo --proc-pid-numa-maps --proc-pid-smaps --proc-pid-stat --proc-pid-statm --proc-pid-status --ps --resolve-conf --route --rpm-qi --rsync --rsync-s --semver --sfdisk --shadow --srt --ss --ssh-conf --sshd-conf --stat --stat-s --swapon --sysctl --syslog --syslog-s --syslog-bsd --syslog-bsd-s --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --toml --top --top-s --tracepath --traceroute --tune2fs --udevadm --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --ver --veracrypt --vmstat --vmstat-s --w --wc --who --x509-cert --x509-csr --xml --xrandr --yaml --zipinfo --zpool-iostat --zpool-status) jc_options=(--force-color -C --debug -d --monochrome -m --meta-out -M --pretty -p --quiet -q --raw -r --slurp -s --unbuffer -u --yaml-out -y) jc_about_options=(--about -a) jc_about_mod_options=(--pretty -p --yaml-out -y --monochrome -m --force-color -C) diff --git a/completions/jc_zsh_completion.sh b/completions/jc_zsh_completion.sh index 355da76fd..13ed727a8 100644 --- a/completions/jc_zsh_completion.sh +++ b/completions/jc_zsh_completion.sh @@ -9,10 +9,12 @@ _jc() { jc_help_options jc_help_options_describe \ jc_special_options jc_special_options_describe - jc_commands=(acpi airport arp blkid bluetoothctl cbt certbot chage cksum crontab curl date debconf-show df dig dmidecode dpkg du efibootmgr env file findmnt finger free git gpg hciconfig host id ifconfig iostat ip iptables iw iwconfig jobs last lastb ls lsattr lsb_release lsblk lsmod lsof lspci lsusb md5 md5sum mdadm mount mpstat netstat nmcli nsd-control ntpq os-prober pidstat ping ping6 pip pip3 postconf printenv ps route rpm rsync sfdisk sha1sum sha224sum sha256sum sha384sum sha512sum shasum ss ssh sshd stat sum swapon sysctl systemctl systeminfo timedatectl top tracepath tracepath6 traceroute traceroute6 tune2fs udevadm ufw uname update-alternatives upower uptime vdir veracrypt vmstat w wc who xrandr zipinfo zpool) + jc_commands=(acpi airport apt-cache apt-get arp blkid bluetoothctl cbt certbot chage cksum crontab curl date debconf-show df dig dmidecode dpkg du efibootmgr env ethtool file findmnt finger free git gpg hciconfig host id ifconfig iostat ip iptables iw iwconfig jobs last lastb ls lsattr lsb_release lsblk lsmod lsof lspci lsusb md5 md5sum mdadm mount mpstat needrestart netstat nmcli nsd-control ntpq os-prober pidstat ping ping6 pip pip3 postconf printenv ps route rpm rsync sfdisk sha1sum sha224sum sha256sum sha384sum sha512sum shasum ss ssh sshd stat sum swapon sysctl systemctl systeminfo timedatectl top tracepath tracepath6 traceroute traceroute6 tune2fs udevadm ufw uname update-alternatives upower uptime vdir veracrypt vmstat w wc who xrandr zipinfo zpool) jc_commands_describe=( 'acpi:run "acpi" command with magic syntax.' 'airport:run "airport" command with magic syntax.' + 'apt-cache:run "apt-cache" command with magic syntax.' + 'apt-get:run "apt-get" command with magic syntax.' 'arp:run "arp" command with magic syntax.' 'blkid:run "blkid" command with magic syntax.' 'bluetoothctl:run "bluetoothctl" command with magic syntax.' @@ -31,6 +33,7 @@ _jc() { 'du:run "du" command with magic syntax.' 'efibootmgr:run "efibootmgr" command with magic syntax.' 'env:run "env" command with magic syntax.' + 'ethtool:run "ethtool" command with magic syntax.' 'file:run "file" command with magic syntax.' 'findmnt:run "findmnt" command with magic syntax.' 'finger:run "finger" command with magic syntax.' @@ -62,6 +65,7 @@ _jc() { 'mdadm:run "mdadm" command with magic syntax.' 'mount:run "mount" command with magic syntax.' 'mpstat:run "mpstat" command with magic syntax.' + 'needrestart:run "needrestart" command with magic syntax.' 'netstat:run "netstat" command with magic syntax.' 'nmcli:run "nmcli" command with magic syntax.' 'nsd-control:run "nsd-control" command with magic syntax.' @@ -117,11 +121,13 @@ _jc() { 'zipinfo:run "zipinfo" command with magic syntax.' 'zpool:run "zpool" command with magic syntax.' ) - jc_parsers=(--acpi --airport --airport-s --arp --asciitable --asciitable-m --blkid --bluetoothctl --cbt --cef --cef-s --certbot --chage --cksum --clf --clf-s --crontab --crontab-u --csv --csv-s --curl-head --date --datetime-iso --debconf-show --df --dig --dir --dmidecode --dpkg-l --du --efibootmgr --email-address --env --file --find --findmnt --finger --free --fstab --git-log --git-log-s --git-ls-remote --gpg --group --gshadow --hash --hashsum --hciconfig --history --host --hosts --http-headers --id --ifconfig --ini --ini-dup --iostat --iostat-s --ip-address --iptables --ip-route --iw-scan --iwconfig --jar-manifest --jobs --jwt --kv --kv-dup --last --ls --ls-s --lsattr --lsb-release --lsblk --lsmod --lsof --lspci --lsusb --m3u --mdadm --mount --mpstat --mpstat-s --netstat --nmcli --nsd-control --ntpq --openvpn --os-prober --os-release --passwd --path --path-list --pci-ids --pgpass --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --pkg-index-apk --pkg-index-deb --plist --postconf --proc --proc-buddyinfo --proc-cmdline --proc-consoles --proc-cpuinfo --proc-crypto --proc-devices --proc-diskstats --proc-filesystems --proc-interrupts --proc-iomem --proc-ioports --proc-loadavg --proc-locks --proc-meminfo --proc-modules --proc-mtrr --proc-pagetypeinfo --proc-partitions --proc-slabinfo --proc-softirqs --proc-stat --proc-swaps --proc-uptime --proc-version --proc-vmallocinfo --proc-vmstat --proc-zoneinfo --proc-driver-rtc --proc-net-arp --proc-net-dev --proc-net-dev-mcast --proc-net-if-inet6 --proc-net-igmp --proc-net-igmp6 --proc-net-ipv6-route --proc-net-netlink --proc-net-netstat --proc-net-packet --proc-net-protocols --proc-net-route --proc-net-tcp --proc-net-unix --proc-pid-fdinfo --proc-pid-io --proc-pid-maps --proc-pid-mountinfo --proc-pid-numa-maps --proc-pid-smaps --proc-pid-stat --proc-pid-statm --proc-pid-status --ps --resolve-conf --route --rpm-qi --rsync --rsync-s --semver --sfdisk --shadow --srt --ss --ssh-conf --sshd-conf --stat --stat-s --swapon --sysctl --syslog --syslog-s --syslog-bsd --syslog-bsd-s --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --toml --top --top-s --tracepath --traceroute --tune2fs --udevadm --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --ver --veracrypt --vmstat --vmstat-s --w --wc --who --x509-cert --x509-csr --xml --xrandr --yaml --zipinfo --zpool-iostat --zpool-status) + jc_parsers=(--acpi --airport --airport-s --apt-cache-show --apt-get-sqq --arp --asciitable --asciitable-m --blkid --bluetoothctl --cbt --cef --cef-s --certbot --chage --cksum --clf --clf-s --crontab --crontab-u --csv --csv-s --curl-head --date --datetime-iso --debconf-show --df --dig --dir --dmidecode --dpkg-l --du --efibootmgr --email-address --env --ethtool --file --find --findmnt --finger --free --fstab --git-log --git-log-s --git-ls-remote --gpg --group --gshadow --hash --hashsum --hciconfig --history --host --hosts --http-headers --id --ifconfig --ini --ini-dup --iostat --iostat-s --ip-address --iptables --ip-route --iw-scan --iwconfig --jar-manifest --jobs --jwt --kv --kv-dup --last --ls --ls-s --lsattr --lsb-release --lsblk --lsmod --lsof --lspci --lsusb --m3u --mdadm --mount --mpstat --mpstat-s --needrestart --netstat --nmcli --nsd-control --ntpq --openvpn --os-prober --os-release --passwd --path --path-list --pci-ids --pgpass --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --pkg-index-apk --pkg-index-deb --plist --postconf --proc --proc-buddyinfo --proc-cmdline --proc-consoles --proc-cpuinfo --proc-crypto --proc-devices --proc-diskstats --proc-filesystems --proc-interrupts --proc-iomem --proc-ioports --proc-loadavg --proc-locks --proc-meminfo --proc-modules --proc-mtrr --proc-pagetypeinfo --proc-partitions --proc-slabinfo --proc-softirqs --proc-stat --proc-swaps --proc-uptime --proc-version --proc-vmallocinfo --proc-vmstat --proc-zoneinfo --proc-driver-rtc --proc-net-arp --proc-net-dev --proc-net-dev-mcast --proc-net-if-inet6 --proc-net-igmp --proc-net-igmp6 --proc-net-ipv6-route --proc-net-netlink --proc-net-netstat --proc-net-packet --proc-net-protocols --proc-net-route --proc-net-tcp --proc-net-unix --proc-pid-fdinfo --proc-pid-io --proc-pid-maps --proc-pid-mountinfo --proc-pid-numa-maps --proc-pid-smaps --proc-pid-stat --proc-pid-statm --proc-pid-status --ps --resolve-conf --route --rpm-qi --rsync --rsync-s --semver --sfdisk --shadow --srt --ss --ssh-conf --sshd-conf --stat --stat-s --swapon --sysctl --syslog --syslog-s --syslog-bsd --syslog-bsd-s --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --toml --top --top-s --tracepath --traceroute --tune2fs --udevadm --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --ver --veracrypt --vmstat --vmstat-s --w --wc --who --x509-cert --x509-csr --xml --xrandr --yaml --zipinfo --zpool-iostat --zpool-status) jc_parsers_describe=( '--acpi:`acpi` command parser' '--airport:`airport -I` command parser' '--airport-s:`airport -s` command parser' + '--apt-cache-show:`apt-cache show` command parser' + '--apt-get-sqq:`apt-get -sqq` command parser' '--arp:`arp` command parser' '--asciitable:ASCII and Unicode table parser' '--asciitable-m:multi-line ASCII and Unicode table parser' @@ -152,6 +158,7 @@ _jc() { '--efibootmgr:`efibootmgr` command parser' '--email-address:Email Address string parser' '--env:`env` command parser' + '--ethtool:`ethtool` command parser' '--file:`file` command parser' '--find:`find` command parser' '--findmnt:`findmnt` command parser' @@ -202,6 +209,7 @@ _jc() { '--mount:`mount` command parser' '--mpstat:`mpstat` command parser' '--mpstat-s:`mpstat` command streaming parser' + '--needrestart:`needrestart -b` command parser' '--netstat:`netstat` command parser' '--nmcli:`nmcli` command parser' '--nsd-control:`nsd-control` command parser' diff --git a/doc2md.py b/doc2md.py new file mode 100755 index 000000000..c81a1623c --- /dev/null +++ b/doc2md.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python3 + +""" +Convert parser doc string to markdown +""" +import sys +import importlib +from inspect import isfunction, signature, cleandoc +import yapf # type: ignore + +ignore_lib_functions = [ + 'cast', + 'wraps', + 'lru_cache', + 'namedtuple' +] + +mod_path = sys.argv[1] +mod_name = mod_path.split('.')[-1] +module = importlib.import_module(f'{mod_path}') + +######## HEADER ######## +header = f'''[Home](https://kellyjonbrazil.github.io/jc/) + + +# {mod_path} +''' + +summary = module.__doc__ or '' + +functions = [] +for attribute in dir(module): + if isfunction(getattr(module, attribute)) \ + and not getattr(module, attribute).__name__.startswith('_'): + + if 'jc.parsers.' in mod_path and not 'universal' in mod_path: + if attribute == 'parse': + functions.append(attribute) + + else: + if not attribute in ignore_lib_functions: + functions.append(attribute) + +######## TABLE OF CONTENTS ######## +toc = f'## Table of Contents\n\n* [{mod_path}](#{mod_path})\n' +for api in functions: + toc = f'{toc} * [{api}](#{mod_path}.{api})\n' + +######## API DOCS ######## +api_docs = '' +for api in functions: + api_function = getattr(module, api) + + this_header = f'\n\n### {api}\n' + this_sig = str(signature(api_function)) + formatted_sig = yapf.yapf_api.FormatCode(f'def {api_function.__name__}{this_sig}:\n pass' ) + formatted_sig = formatted_sig[0].split(':\n pass')[0] + this_name_and_sig = f'{this_header}\n```python\n{formatted_sig}\n```' + + this_doc = cleandoc(api_function.__doc__) + api_docs = api_docs + this_name_and_sig + '\n\n' + this_doc + '\n\n' + +######## FOOTER ######## +footer = '' +if 'jc.parsers.' in mod_path and not 'universal' in mod_path: + footer = '### Parser Information\n' + comp = ', '.join(module.info.compatible) + ver = module.info.version + author = module.info.author + author_email = module.info.author_email + slurpable = 'slurpable' in module.info.tags + footer = footer + f'Compatibility: {comp}\n\n' + footer = footer + f'Source: [`jc/parsers/{mod_name}.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/{mod_name}.py)\n\n' + if slurpable: + footer = footer + 'This parser can be used with the `--slurp` command-line option.\n\n' + footer = footer + f'Version {ver} by {author} ({author_email})' + +final_doc = '' +if 'jc.parsers.' in mod_path and not 'universal' in mod_path: + final_doc = header + '\n' + summary + '\n' + api_docs + footer +elif mod_path == 'jc': + final_doc = header + '\n' + summary +else: + final_doc = header + '\n' + toc + '\n' + summary + '\n\n' + api_docs + +print(final_doc) diff --git a/docgen.sh b/docgen.sh index a403c627f..d5d876e19 100755 --- a/docgen.sh +++ b/docgen.sh @@ -1,107 +1,32 @@ #!/bin/bash -# Generate docs.md -# requires pydoc-markdown 4.6.1 - +# Generate markdown document files (*.md) +# Requires the yapf python library # use ./docgen all to generate all docs -readme_config=$(cat <<'EOF' -{ - "processors": [ - { - "type": "filter" - }, - { - "type": "pydocmd" - } - ], - "renderer": { - "type": "markdown", - "header_level_by_type": { - "Module": 1, - "Class": 3, - "Method": 3, - "Function": 3, - "Variable": 3 - } - } -} -EOF -) - -toc_config=$(cat <<'EOF' -{ - "processors": [ - { - "type": "filter" - }, - { - "type": "pydocmd" - } - ], - "renderer": { - "type": "markdown", - "render_toc": true, - "header_level_by_type": { - "Module": 1, - "Class": 3, - "Method": 3, - "Function": 3, - "Variable": 3 - } - } -} -EOF -) - -parser_config=$(cat <<'EOF' -{ - "processors": [ - { - "type": "filter", - "expression": "not name == \"info\" and not name.startswith(\"_\") and default()" - }, - { - "type": "pydocmd" - } - ], - "renderer": { - "type": "markdown", - "header_level_by_type": { - "Module": 1, - "Class": 3, - "Method": 3, - "Function": 3, - "Variable": 3 - } - } -} -EOF -) - cd jc ( echo Building docs for: package - pydoc-markdown -m jc "${readme_config}" > ../docs/readme.md; echo "+++ package docs complete" + ../doc2md.py jc > ../docs/readme.md && echo "+++ package docs complete" || echo "*** PACKAGE DOCS FAILED ***" ) & ( echo Building docs for: lib - pydoc-markdown -m jc.lib "${toc_config}" > ../docs/lib.md; echo "+++ lib docs complete" + ../doc2md.py jc.lib > ../docs/lib.md && echo "+++ lib docs complete" || echo "*** LIB DOCS FAILED ***" ) & ( echo Building docs for: utils - pydoc-markdown -m jc.utils "${toc_config}" > ../docs/utils.md; echo "+++ utils docs complete" + ../doc2md.py jc.utils > ../docs/utils.md && echo "+++ utils docs complete" || echo "*** UTILS DOCS FAILED ***" ) & ( echo Building docs for: streaming - pydoc-markdown -m jc.streaming "${toc_config}" > ../docs/streaming.md; echo "+++ streaming docs complete" + ../doc2md.py jc.streaming > ../docs/streaming.md && echo "+++ streaming docs complete" || echo "*** STREAMING DOCS FAILED ***" ) & ( echo Building docs for: universal parser - pydoc-markdown -m jc.parsers.universal "${toc_config}" > ../docs/parsers/universal.md; echo "+++ universal parser docs complete" + ../doc2md.py jc.parsers.universal > ../docs/parsers/universal.md && echo "+++ universal parser docs complete" || echo "*** UNIVERSAL PARSER DOCS FAILED ***" ) & # a bit of inception here... jc is being used to help @@ -119,27 +44,8 @@ for parser in "${parsers[@]}"; do parser_name=$(jq -r '.name' <<< "$parser") { if [[ $1 == "all" ]] || ! git diff --quiet --exit-code HEAD~5 -- "parsers/${parser_name}.py"; then - compatible=$(jq -r '.compatible | join(", ")' <<< "$parser") - version=$(jq -r '.version' <<< "$parser") - author=$(jq -r '.author' <<< "$parser") - author_email=$(jq -r '.author_email' <<< "$parser") - echo "Building docs for: ${parser_name}" - echo "[Home](https://kellyjonbrazil.github.io/jc/)" > ../docs/parsers/"${parser_name}".md - pydoc-markdown -m jc.parsers."${parser_name}" "${parser_config}" >> ../docs/parsers/"${parser_name}".md - echo "### Parser Information" >> ../docs/parsers/"${parser_name}".md - echo "Compatibility: ${compatible}" >> ../docs/parsers/"${parser_name}".md - echo >> ../docs/parsers/"${parser_name}".md - echo "Source: [\`jc/parsers/${parser_name}.py\`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/${parser_name}.py)" >> ../docs/parsers/"${parser_name}".md - echo >> ../docs/parsers/"${parser_name}".md - - if $(jq -e '.tags | contains(["slurpable"])' <<< "$parser"); then - echo "This parser can be used with the \`--slurp\` command-line option." >> ../docs/parsers/"${parser_name}".md - echo >> ../docs/parsers/"${parser_name}".md - fi - - echo "Version ${version} by ${author} (${author_email})" >> ../docs/parsers/"${parser_name}".md - echo "+++ ${parser_name} docs complete" + ../doc2md.py jc.parsers."${parser_name}" > ../docs/parsers/"${parser_name}".md && echo "+++ ${parser_name} docs complete" || echo "*** ${parser_name} DOCS FAILED ***" fi } & done diff --git a/docs/lib.md b/docs/lib.md index 060a5c8ba..309444df6 100644 --- a/docs/lib.md +++ b/docs/lib.md @@ -1,29 +1,67 @@ -# Table of Contents +[Home](https://kellyjonbrazil.github.io/jc/) + + +# jc.lib + +## Table of Contents * [jc.lib](#jc.lib) - * [get\_parser](#jc.lib.get_parser) + * [all_parser_info](#jc.lib.all_parser_info) + * [get_help](#jc.lib.get_help) + * [get_parser](#jc.lib.get_parser) * [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) - * [slurpable\_parser\_mod\_list](#jc.lib.slurpable_parser_mod_list) - * [parser\_info](#jc.lib.parser_info) - * [all\_parser\_info](#jc.lib.all_parser_info) - * [get\_help](#jc.lib.get_help) + * [parser_info](#jc.lib.parser_info) + * [parser_mod_list](#jc.lib.parser_mod_list) + * [plugin_parser_mod_list](#jc.lib.plugin_parser_mod_list) + * [slurpable_parser_mod_list](#jc.lib.slurpable_parser_mod_list) + * [standard_parser_mod_list](#jc.lib.standard_parser_mod_list) + * [streaming_parser_mod_list](#jc.lib.streaming_parser_mod_list) - +jc - JSON Convert lib module -# jc.lib + -jc - JSON Convert lib module +### all_parser_info + +```python +def all_parser_info( + documentation: bool = False, + show_hidden: bool = False, + show_deprecated: bool = False) -> List[jc.jc_types.ParserInfoType] +``` + +Returns a list of dictionaries that includes metadata for all parser +modules. By default only non-hidden, non-deprecated parsers are +returned. + +Parameters: + + documentation: (boolean) include parser docstrings if True + show_hidden: (boolean) also show parsers marked as hidden + in their info metadata. + show_deprecated: (boolean) also show parsers marked as + deprecated in their info metadata. + + + +### get_help + +```python +def get_help(parser_mod_name: Union[str, module]) -> None +``` + +Show help screen for the selected parser. + +This function will accept **module_name**, **cli-name**, and +**--argument-name** variants of the module name string as well as a +parser module object. -### get\_parser +### get_parser ```python -def get_parser(parser_mod_name: Union[str, ModuleType]) -> ModuleType +def get_parser(parser_mod_name: Union[str, module]) -> module ``` Return the parser module object and check that the module is a valid @@ -56,13 +94,13 @@ Raises: ```python def parse( - parser_mod_name: Union[str, ModuleType], + parser_mod_name: Union[str, module], data: Union[str, bytes, Iterable[str]], quiet: bool = False, raw: bool = False, ignore_exceptions: Optional[bool] = None, **kwargs -) -> Union[JSONDictType, List[JSONDictType], Iterator[JSONDictType]] +) -> Union[Dict[str, Any], List[Dict[str, Any]], Iterator[Dict[str, Any]]] ``` Parse the data (string or bytes) using the supplied parser (string or @@ -152,57 +190,53 @@ Returns: Standard Parsers: Dictionary or List of Dictionaries Streaming Parsers: Generator Object containing Dictionaries - + -### parser\_mod\_list +### parser_info ```python -def parser_mod_list(show_hidden: bool = False, - show_deprecated: bool = False) -> List[str] +def parser_info(parser_mod_name: Union[str, module], + documentation: bool = False) -> jc.jc_types.ParserInfoType ``` -Returns a list of all available parser module names. - - +Returns a dictionary that includes the parser module metadata. -### plugin\_parser\_mod\_list +Parameters: -```python -def plugin_parser_mod_list(show_hidden: bool = False, - show_deprecated: bool = False) -> List[str] -``` + parser_mod_name: (string or name of the parser module. This + Module) function will accept module_name, + cli-name, and --argument-name + variants of the module name as well + as a parser module object. -Returns a list of plugin parser module names. This function is a -subset of `parser_mod_list()`. + documentation: (boolean) include parser docstring if True - + -### standard\_parser\_mod\_list +### parser_mod_list ```python -def standard_parser_mod_list(show_hidden: bool = False, - show_deprecated: bool = False) -> List[str] +def parser_mod_list(show_hidden: bool = False, + show_deprecated: bool = False) -> 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. +Returns a list of all available parser module names. - + -### streaming\_parser\_mod\_list +### plugin_parser_mod_list ```python -def streaming_parser_mod_list(show_hidden: bool = False, - show_deprecated: bool = False) -> List[str] +def plugin_parser_mod_list(show_hidden: bool = False, + show_deprecated: bool = False) -> List[str] ``` -Returns a list of streaming parser module names. This function is a +Returns a list of plugin parser module names. This function is a subset of `parser_mod_list()`. -### slurpable\_parser\_mod\_list +### slurpable_parser_mod_list ```python def slurpable_parser_mod_list(show_hidden: bool = False, @@ -212,60 +246,29 @@ def slurpable_parser_mod_list(show_hidden: bool = False, Returns a list of slurpable parser module names. This function is a subset of `parser_mod_list()`. - - -### parser\_info - -```python -def parser_info(parser_mod_name: Union[str, ModuleType], - documentation: bool = False) -> ParserInfoType -``` - -Returns a dictionary that includes the parser module metadata. - -Parameters: - - parser_mod_name: (string or name of the parser module. This - Module) function will accept module_name, - cli-name, and --argument-name - variants of the module name as well - as a parser module object. - - documentation: (boolean) include parser docstring if True - - + -### all\_parser\_info +### standard_parser_mod_list ```python -def all_parser_info(documentation: bool = False, - show_hidden: bool = False, - show_deprecated: bool = False) -> List[ParserInfoType] +def standard_parser_mod_list(show_hidden: bool = False, + show_deprecated: bool = False) -> List[str] ``` -Returns a list of dictionaries that includes metadata for all parser -modules. By default only non-hidden, non-deprecated parsers are -returned. - -Parameters: - - documentation: (boolean) include parser docstrings if True - show_hidden: (boolean) also show parsers marked as hidden - in their info metadata. - show_deprecated: (boolean) also show parsers marked as - deprecated in their info metadata. +Returns a list of standard parser module names. This function is a +subset of `parser_mod_list()` and does not contain any streaming +parsers. - + -### get\_help +### streaming_parser_mod_list ```python -def get_help(parser_mod_name: Union[str, ModuleType]) -> None +def streaming_parser_mod_list(show_hidden: bool = False, + show_deprecated: bool = False) -> List[str] ``` -Show help screen for the selected parser. +Returns a list of streaming parser module names. This function is a +subset of `parser_mod_list()`. -This function will accept **module_name**, **cli-name**, and -**--argument-name** variants of the module name string as well as a -parser module object. diff --git a/docs/parsers/airport_s.md b/docs/parsers/airport_s.md index 3874ff82f..80b239ce4 100644 --- a/docs/parsers/airport_s.md +++ b/docs/parsers/airport_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.airport\_s +# jc.parsers.airport_s jc - JSON Convert `airport -s` command output parser diff --git a/docs/parsers/apt_cache_show.md b/docs/parsers/apt_cache_show.md new file mode 100644 index 000000000..8cd4db3c0 --- /dev/null +++ b/docs/parsers/apt_cache_show.md @@ -0,0 +1,180 @@ +[Home](https://kellyjonbrazil.github.io/jc/) + + +# jc.parsers.apt_cache_show + +jc - JSON Convert `apt-cache show` command parser + +Usage (cli): + + $ apt-cache show | jc --apt-cache-show + +Usage (module): + + import jc + result = jc.parse('apt_cache_show', apt_cache_show_output) + +Schema: + + [ + { + "package": string, + "version": string, + "installed_size": integer, + "maintainer": string, + "architecture": string, + "depends": [ + string + ], + "pre_depends": [ + string + ], + "recommends": [ + string + ], + "suggests": [ + string + ], + "conflicts": [ + string + ], + "breaks": [ + string + ], + "description_md5": string, + "multi_arch": string, + "homepage": string, + "section": string, + "priority": string, + "filename": string, + "size": integer, + "sha256": string, + "description": string + } + ] + +Examples: + + $ apt-cache show | jc --apt-cache-show -p + [ + { + "package": "systemd", + "version": "247.3-6~bpo10+1", + "installed_size": 16121, + "maintainer": "Debian systemd Maintainers = 2.2.23)", + "libapparmor1 (>= 2.13)", + "libaudit1 (>= 1:2.2.1)", + "libcap2 (>= 1:2.10)", + "libcryptsetup12 (>= 2:2.0.1)", + "libgnutls30 (>= 3.6.6)", + "libgpg-error0 (>= 1.14)", + "libip4tc0 (>= 1.6.0+snapshot20161117)", + "libkmod2 (>= 5~)", + "liblz4-1 (>= 0.0~r130)", + "libmount1 (>= 2.30)", + "libpam0g (>= 0.99.7.1)", + "libseccomp2 (>= 2.3.1)", + "libsystemd0 (= 247.3-6~bpo10+1)", + "systemd-timesyncd | time-daemon", + "util-linux (>= 2.27.1)", + "mount (>= 2.26)", + "adduser" + ], + "pre_depends": [ + "libblkid1 (>= 2.24)", + "libc6 (>= 2.28)", + "libgcrypt20 (>= 1.8.0)", + "liblz4-1 (>= 0.0~r122)", + "liblzma5 (>= 5.1.1alpha+20120614)", + "libselinux1 (>= 2.1.9)", + "libzstd1 (>= 1.4.0)" + ], + "recommends": [ + "dbus" + ], + "suggests": [ + "systemd-container", + "policykit-1" + ], + "conflicts": [ + "consolekit", + "libpam-ck-connector" + ], + "breaks": [ + "python-dbusmock (<< 0.18)", + "python3-dbusmock (<< 0.18)", + "resolvconf (<< 1.83~)", + "systemd-shim (<< 10-4~)", + "udev (<< 247~)" + ], + "description_md5": "19399579cbc0c47a303288bf15eadcd4", + "multi_arch": "foreign", + "homepage": "https://www.freedesktop.org/wiki/Software/systemd", + "section": "admin", + "priority": "important", + "filename": "pool/main/s/systemd/systemd_247.3-6~bpo10+1_amd64.deb", + "size": 4382056, + "sha256": "2035450655ad02faa0f75dc952128b503e51df5795c67273c0f6...", + "description": "system and service manager systemd is a system..." + }, + ... + ] + + $ apt-cache show | jc --apt-cache-show -p -r + [ + { + "package": "systemd", + "version": "247.3-6~bpo10+1", + "installed_size": "16121", + "maintainer": "Debian systemd Maintainers = 2.2.23), libapparmor1 (>= 2.13), libaud...", + "pre_depends": "libblkid1 (>= 2.24), libc6 (>= 2.28), libgcrypt...", + "recommends": "dbus", + "suggests": "systemd-container, policykit-1", + "conflicts": "consolekit, libpam-ck-connector", + "breaks": "python-dbusmock (<< 0.18), python3-dbusmock (<< 0.18...", + "description_md5": "19399579cbc0c47a303288bf15eadcd4", + "multi_arch": "foreign", + "homepage": "https://www.freedesktop.org/wiki/Software/systemd", + "section": "admin", + "priority": "important", + "filename": "pool/main/s/systemd/systemd_247.3-6~bpo10+1_amd64.deb", + "size": "4382056", + "sha256": "2035450655ad02faa0f75dc952128b503e51df5795c67273c0f6...", + "description": "system and service manager systemd is a system..." + }, + ... + ] + + + +### parse + +```python +def parse(data: str, + raw: bool = False, + quiet: bool = False) -> List[Dict[str, Any]] +``` + +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 + +Source: [`jc/parsers/apt_cache_show.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/apt_cache_show.py) + +Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/apt_get_sqq.md b/docs/parsers/apt_get_sqq.md new file mode 100644 index 000000000..3d9939f2b --- /dev/null +++ b/docs/parsers/apt_get_sqq.md @@ -0,0 +1,201 @@ +[Home](https://kellyjonbrazil.github.io/jc/) + + +# jc.parsers.apt_get_sqq + +jc - JSON Convert `apt-get -sqq` command output parser + +Requires the `-sqq` options in `apt-get`. + +Usage (cli): + + $ apt-get -sqq | jc --apt-get-sqq + +or + + $ jc apt-get -sqq + +Usage (module): + + import jc + result = jc.parse('apt_get_sqq', apt_get_sqq_command_output) + +Schema: + + [ + { + "operation": string, # configure, remove, or unpack + "package": string, + "broken": string/null, + "proposed_pkg_ver": string, + "existing_pkg_ver": string/null, + "architecture": string + } + ] + +Examples: + + $ apt-get -sqq | jc --apt-get-sqq -p + [ + { + "operation": "unpack", + "package": "dpkg", + "broken": "1.19.7", + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + }, + { + "operation": "unpack", + "package": "dpkg", + "broken": null, + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + }, + { + "operation": "configure", + "package": "dpkg", + "broken": "1.19.7", + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + }, + { + "operation": "remove", + "package": "dpkg", + "broken": "1.19.7", + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + }, + { + "operation": "unpack", + "package": "base-files", + "broken": "10.3+deb10u4", + "proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable", + "existing_pkg_ver": null, + "architecture": "amd64" + }, + { + "operation": "configure", + "package": "base-files", + "broken": null, + "proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable", + "existing_pkg_ver": null, + "architecture": "amd64" + }, + { + "operation": "unpack", + "package": "dpkg", + "broken": "1.19.7", + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + }, + { + "operation": "configure", + "package": "dpkg", + "broken": null, + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + } + ] + + $ apt-get -sqq | jc --apt-get-sqq -p -r + [ + { + "operation": "Inst", + "package": "dpkg", + "broken": "1.19.7", + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + }, + { + "operation": "Inst", + "package": "dpkg", + "broken": null, + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + }, + { + "operation": "Conf", + "package": "dpkg", + "broken": "1.19.7", + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + }, + { + "operation": "Remv", + "package": "dpkg", + "broken": "1.19.7", + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + }, + { + "operation": "Inst", + "package": "base-files", + "broken": "10.3+deb10u4", + "proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable", + "existing_pkg_ver": null, + "architecture": "amd64" + }, + { + "operation": "Conf", + "package": "base-files", + "broken": null, + "proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable", + "existing_pkg_ver": null, + "architecture": "amd64" + }, + { + "operation": "Inst", + "package": "dpkg", + "broken": "1.19.7", + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + }, + { + "operation": "Conf", + "package": "dpkg", + "broken": null, + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + } + ] + + + +### parse + +```python +def parse(data: str, + raw: bool = False, + quiet: bool = False) -> List[Dict[str, Any]] +``` + +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 + +Source: [`jc/parsers/apt_get_sqq.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/apt_get_sqq.py) + +Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/asciitable_m.md b/docs/parsers/asciitable_m.md index 977778906..8e6a4acc1 100644 --- a/docs/parsers/asciitable_m.md +++ b/docs/parsers/asciitable_m.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.asciitable\_m +# jc.parsers.asciitable_m jc - JSON Convert `asciitable-m` parser diff --git a/docs/parsers/bluetoothctl.md b/docs/parsers/bluetoothctl.md index eccc50d3b..1474b0bdf 100644 --- a/docs/parsers/bluetoothctl.md +++ b/docs/parsers/bluetoothctl.md @@ -112,7 +112,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/cbt.md b/docs/parsers/cbt.md index 37563b016..a8f753e13 100644 --- a/docs/parsers/cbt.md +++ b/docs/parsers/cbt.md @@ -104,7 +104,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/cef_s.md b/docs/parsers/cef_s.md index 17a085b34..4e5c5dcd4 100644 --- a/docs/parsers/cef_s.md +++ b/docs/parsers/cef_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.cef\_s +# jc.parsers.cef_s jc - JSON Convert CEF string output streaming parser @@ -95,7 +95,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data: Iterable[str], raw: bool = False, quiet: bool = False, diff --git a/docs/parsers/certbot.md b/docs/parsers/certbot.md index 6e5591f29..5ccf68255 100644 --- a/docs/parsers/certbot.md +++ b/docs/parsers/certbot.md @@ -140,7 +140,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/clf.md b/docs/parsers/clf.md index a0ce543de..4f65bd1b4 100644 --- a/docs/parsers/clf.md +++ b/docs/parsers/clf.md @@ -178,7 +178,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/clf_s.md b/docs/parsers/clf_s.md index 4e6727280..f7c9f2e21 100644 --- a/docs/parsers/clf_s.md +++ b/docs/parsers/clf_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.clf\_s +# jc.parsers.clf_s jc - JSON Convert Common Log Format file streaming parser @@ -88,11 +88,12 @@ Examples: ### parse ```python -@add_jc_meta -def parse(data: Iterable[str], - raw: bool = False, - quiet: bool = False, - ignore_exceptions: bool = False) -> StreamingOutputType +def parse( + data: Iterable[str], + raw: bool = False, + quiet: bool = False, + ignore_exceptions: bool = False +) -> Iterator[Union[Dict[str, Any], Tuple[BaseException, str]]] ``` Main text parsing generator function. Returns an iterable object. diff --git a/docs/parsers/crontab_u.md b/docs/parsers/crontab_u.md index a4a0bb7d1..ec69331ad 100644 --- a/docs/parsers/crontab_u.md +++ b/docs/parsers/crontab_u.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.crontab\_u +# jc.parsers.crontab_u jc - JSON Convert `crontab -l` command output and crontab file parser diff --git a/docs/parsers/csv.md b/docs/parsers/csv.md index 6833ecefc..00b16bdc1 100644 --- a/docs/parsers/csv.md +++ b/docs/parsers/csv.md @@ -84,7 +84,7 @@ Examples: ```python def parse(data: Union[str, bytes], raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/csv_s.md b/docs/parsers/csv_s.md index fca783dad..269fcd45f 100644 --- a/docs/parsers/csv_s.md +++ b/docs/parsers/csv_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.csv\_s +# jc.parsers.csv_s jc - JSON Convert `csv` file streaming parser @@ -64,7 +64,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data, raw=False, quiet=False, ignore_exceptions=False) ``` diff --git a/docs/parsers/curl_head.md b/docs/parsers/curl_head.md index a9c707587..cb6642702 100644 --- a/docs/parsers/curl_head.md +++ b/docs/parsers/curl_head.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.curl\_head +# jc.parsers.curl_head jc - JSON Convert `curl --head` command output parser @@ -286,7 +286,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/datetime_iso.md b/docs/parsers/datetime_iso.md index c8a8651a0..164bbf478 100644 --- a/docs/parsers/datetime_iso.md +++ b/docs/parsers/datetime_iso.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.datetime\_iso +# jc.parsers.datetime_iso jc - JSON Convert ISO 8601 Datetime string parser diff --git a/docs/parsers/debconf_show.md b/docs/parsers/debconf_show.md index 0b24154eb..834151b16 100644 --- a/docs/parsers/debconf_show.md +++ b/docs/parsers/debconf_show.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.debconf\_show +# jc.parsers.debconf_show jc - JSON Convert `debconf-show` command output parser @@ -84,7 +84,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/df.md b/docs/parsers/df.md index 30fb0e4af..06f17325d 100644 --- a/docs/parsers/df.md +++ b/docs/parsers/df.md @@ -5,6 +5,8 @@ jc - JSON Convert `df` command output parser +Values are normalized to bytes when using `df -h`. + Usage (cli): $ df | jc --df @@ -23,7 +25,7 @@ Schema: [ { "filesystem": string, - "size": string, + "size": integer, "1k_blocks": integer, "512_blocks": integer, "used": integer, @@ -122,4 +124,4 @@ Compatibility: linux, darwin, freebsd Source: [`jc/parsers/df.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/df.py) -Version 1.11 by Kelly Brazil (kellyjonbrazil@gmail.com) +Version 2.0 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/dpkg_l.md b/docs/parsers/dpkg_l.md index 43bb89ad0..f71ed268e 100644 --- a/docs/parsers/dpkg_l.md +++ b/docs/parsers/dpkg_l.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.dpkg\_l +# jc.parsers.dpkg_l jc - JSON Convert `dpkg -l` command output parser diff --git a/docs/parsers/efibootmgr.md b/docs/parsers/efibootmgr.md index e118efc2a..90a8f157c 100644 --- a/docs/parsers/efibootmgr.md +++ b/docs/parsers/efibootmgr.md @@ -81,7 +81,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/email_address.md b/docs/parsers/email_address.md index ecb8765d8..038504120 100644 --- a/docs/parsers/email_address.md +++ b/docs/parsers/email_address.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.email\_address +# jc.parsers.email_address jc - JSON Convert Email Address string parser diff --git a/docs/parsers/ethtool.md b/docs/parsers/ethtool.md new file mode 100644 index 000000000..bd0946b02 --- /dev/null +++ b/docs/parsers/ethtool.md @@ -0,0 +1,197 @@ +[Home](https://kellyjonbrazil.github.io/jc/) + + +# jc.parsers.ethtool + +jc - JSON Convert `ethtool` command output parser + +Supports standard `ethtool` output and the `--module-info` option. + +Usage (cli): + + $ ethtool | jc --ethtool + $ ethtool --module-info | jc --ethtool + +or + + $ jc ethtool + $ jc ethtool --module-info + +Usage (module): + + import jc + result = jc.parse('ethtool', ethtool_command_output) + +Schema: + +Note: many units fields are converted to integers and floats +when detected. Use raw output for the original string values. + + { + "name": string, + "supported_ports": [ + string + ], + "supported_link_modes": [ + string + ], + "supported_pause_frame_use": string, + "supports_auto_negotiation": boolean, + "supported_fec_modes": [ + string + ], + "advertised_link_modes": [ + string + ], + "advertised_pause_frame_use": boolean, + "advertised_auto_negotiation": boolean, + "advertised_fec_modes": [ + string + ], + "speed": string, + "speed_bps": integer, + "duplex": string, + "auto_negotiation": boolean, + "port": string, + "phyad": string, + "mdi_x": string, + "transceiver": string, + "supports_wake_on": string, + "wake_on": string, + "current_message_level": [ + string + ], + "link_detected": boolean, + "identifier": string, + "extended_identifier": string, + "connector": string, + "transceiver_codes": string, + "transceiver_type": [ + string + ], + "encoding": string, + "br_nominal": string, + "rate_identifier": string, + "length_smf_km": string, + "length_smf": string, + "length_50um": string, + "length_62_5um": string, + "length_copper": string, + "length_om3": string, + "passive_cu_cmplnce": string, + "vendor_name": string, + "vendor_oui": string, + "vendor_pn": string, + "vendor_rev": string, + "option_values": string, + "br_margin_max": string, + "br_margin_min": string + } + +Examples: + + $ ethtool enp0s3 | jc --ethtool -p + { + "name": "enp0s3", + "supported_pause_frame_use": "No", + "supports_auto_negotiation": true, + "supported_fec_modes": "Not reported", + "advertised_pause_frame_use": false, + "advertised_auto_negotiation": true, + "advertised_fec_modes": "Not reported", + "speed": "1000Mb/s", + "duplex": "Full", + "port": "Twisted Pair", + "phyad": "0", + "transceiver": "internal", + "auto_negotiation": false, + "mdi_x": "off (auto)", + "supports_wake_on": "umbg", + "wake_on": "d", + "link_detected": true, + "supported_ports": [ + "TP" + ], + "supported_link_modes": [ + "10baseT/Half", + "10baseT/Full", + "100baseT/Half", + "100baseT/Full", + "1000baseT/Full" + ], + "advertised_link_modes": [ + "10baseT/Half", + "10baseT/Full", + "100baseT/Half", + "100baseT/Full", + "1000baseT/Full" + ], + "current_message_level": [ + "0x00000007 (7)", + "drv probe link" + ], + "speed_bps": 1000000000 + } + + $ ethtool --module-info enp0s3 | jc --ethtool -p + { + "identifier": "0x03 (SFP)", + "extended_identifier": "0x04 (GBIC/SFP defined by 2-wire interface ID)", + "connector": "0x21 (Copper pigtail)", + "transceiver_codes": "0x01 0x00 0x00 0x04 0x00 0x04 0x80 0xd5 0x00", + "transceiver_type": [ + "Infiniband: 1X Copper Passive", + "Ethernet: 1000BASE-CX", + "Passive Cable", + "FC: Twin Axial Pair (TW)", + "FC: 1200 MBytes/sec", + "FC: 800 MBytes/sec", + "FC: 400 MBytes/sec", + "FC: 200 MBytes/sec", + "FC: 100 MBytes/sec" + ], + "encoding": "0x00 (unspecified)", + "br_nominal": "10300MBd", + "rate_identifier": "0x00 (unspecified)", + "length_smf_km": "0km", + "length_smf": "0m", + "length_50um": "0m", + "length_62_5um": "0m", + "length_copper": "2m", + "length_om3": "0m", + "passive_cu_cmplnce": "0x01 (SFF-8431 appendix E) [SFF-8472 rev10.4 only]", + "vendor_name": "UbiquitiNetworks", + "vendor_oui": "00:40:20", + "vendor_pn": "UDC-2", + "vendor_rev": "", + "option_values": "0x00 0x00", + "br_margin_max": "0%", + "br_margin_min": "0%" + } + + + +### parse + +```python +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] +``` + +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 + +Source: [`jc/parsers/ethtool.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/ethtool.py) + +Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/findmnt.md b/docs/parsers/findmnt.md index 449babf0c..9bc413aec 100644 --- a/docs/parsers/findmnt.md +++ b/docs/parsers/findmnt.md @@ -96,7 +96,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/free.md b/docs/parsers/free.md index e67330dd9..1e0200097 100644 --- a/docs/parsers/free.md +++ b/docs/parsers/free.md @@ -5,6 +5,8 @@ jc - JSON Convert `free` command output parser +Values are normalized to bytes when using `free -h`. + Usage (cli): $ free | jc --free @@ -22,13 +24,13 @@ Schema: [ { - "type": string, - "total": integer, - "used": integer, - "free": integer, - "shared": integer, - "buff_cache": integer, - "available": integer + "type": string, + "total": integer, + "used": integer, + "free": integer, + "shared": integer, + "buff_cache": integer, + "available": integer } ] @@ -97,4 +99,4 @@ Compatibility: linux Source: [`jc/parsers/free.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/free.py) -Version 1.7 by Kelly Brazil (kellyjonbrazil@gmail.com) +Version 1.8 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/git_log.md b/docs/parsers/git_log.md index 69444e32f..d93a6f11e 100644 --- a/docs/parsers/git_log.md +++ b/docs/parsers/git_log.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.git\_log +# jc.parsers.git_log jc - JSON Convert `git log` command output parser diff --git a/docs/parsers/git_log_s.md b/docs/parsers/git_log_s.md index 4d501881e..3dfb08e9b 100644 --- a/docs/parsers/git_log_s.md +++ b/docs/parsers/git_log_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.git\_log\_s +# jc.parsers.git_log_s jc - JSON Convert `git log` command output streaming parser @@ -82,7 +82,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data: Iterable[str], raw: bool = False, quiet: bool = False, diff --git a/docs/parsers/git_ls_remote.md b/docs/parsers/git_ls_remote.md index ef09b41fd..ae5015a9f 100644 --- a/docs/parsers/git_ls_remote.md +++ b/docs/parsers/git_ls_remote.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.git\_ls\_remote +# jc.parsers.git_ls_remote jc - JSON Convert `git ls-remote` command output parser @@ -71,7 +71,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> Union[JSONDictType, List[JSONDictType]] + quiet: bool = False) -> Union[Dict[str, Any], List[Dict[str, Any]]] ``` Main text parsing function diff --git a/docs/parsers/http_headers.md b/docs/parsers/http_headers.md index f3d74a7c8..b7330ef75 100644 --- a/docs/parsers/http_headers.md +++ b/docs/parsers/http_headers.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.http\_headers +# jc.parsers.http_headers jc - JSON Convert HTTP headers parser @@ -313,7 +313,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/ifconfig.md b/docs/parsers/ifconfig.md index 274d4c28f..e9b0ddc9a 100644 --- a/docs/parsers/ifconfig.md +++ b/docs/parsers/ifconfig.md @@ -222,7 +222,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/ini_dup.md b/docs/parsers/ini_dup.md index a4a74d83d..078c7a361 100644 --- a/docs/parsers/ini_dup.md +++ b/docs/parsers/ini_dup.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.ini\_dup +# jc.parsers.ini_dup jc - JSON Convert INI with duplicate key file parser diff --git a/docs/parsers/iostat_s.md b/docs/parsers/iostat_s.md index 4bb699288..e2e980811 100644 --- a/docs/parsers/iostat_s.md +++ b/docs/parsers/iostat_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.iostat\_s +# jc.parsers.iostat_s jc - JSON Convert `iostat` command output streaming parser @@ -108,7 +108,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data, raw=False, quiet=False, ignore_exceptions=False) ``` diff --git a/docs/parsers/ip_address.md b/docs/parsers/ip_address.md index 7b1fa4162..efdcc21f8 100644 --- a/docs/parsers/ip_address.md +++ b/docs/parsers/ip_address.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.ip\_address +# jc.parsers.ip_address jc - JSON Convert IP Address string parser diff --git a/docs/parsers/ip_route.md b/docs/parsers/ip_route.md index e5efb990e..24975d915 100644 --- a/docs/parsers/ip_route.md +++ b/docs/parsers/ip_route.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.ip\_route +# jc.parsers.ip_route jc - JSON Convert `ip route` command output parser diff --git a/docs/parsers/iptables.md b/docs/parsers/iptables.md index 9639f2e3a..8c41a3304 100644 --- a/docs/parsers/iptables.md +++ b/docs/parsers/iptables.md @@ -5,7 +5,7 @@ jc - JSON Convert `iptables` command output parser -Supports `-vLn` and `--line-numbers` for all tables. +Supports `-vLnx` and `--line-numbers` for all tables. Usage (cli): @@ -188,4 +188,4 @@ Compatibility: linux Source: [`jc/parsers/iptables.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/iptables.py) -Version 1.10 by Kelly Brazil (kellyjonbrazil@gmail.com) +Version 1.11 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/iw_scan.md b/docs/parsers/iw_scan.md index de2470b9d..9fc82cd9d 100644 --- a/docs/parsers/iw_scan.md +++ b/docs/parsers/iw_scan.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.iw\_scan +# jc.parsers.iw_scan jc - JSON Convert `iw dev scan` command output parser diff --git a/docs/parsers/iwconfig.md b/docs/parsers/iwconfig.md index fcbbdc010..e02e20bfa 100644 --- a/docs/parsers/iwconfig.md +++ b/docs/parsers/iwconfig.md @@ -90,7 +90,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function @@ -110,4 +110,4 @@ Compatibility: linux Source: [`jc/parsers/iwconfig.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/iwconfig.py) -Version 1.1 by Thomas Vincent (vrince@gmail.com) +Version 1.2 by Thomas Vincent (vrince@gmail.com) diff --git a/docs/parsers/jar_manifest.md b/docs/parsers/jar_manifest.md index 080ff6742..eeb8275bb 100644 --- a/docs/parsers/jar_manifest.md +++ b/docs/parsers/jar_manifest.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.jar\_manifest +# jc.parsers.jar_manifest jc - JSON Convert Java `MANIFEST.MF` file parser diff --git a/docs/parsers/kv.md b/docs/parsers/kv.md index 4bad8da23..d1bb4ef24 100644 --- a/docs/parsers/kv.md +++ b/docs/parsers/kv.md @@ -81,4 +81,4 @@ Compatibility: linux, darwin, cygwin, win32, aix, freebsd Source: [`jc/parsers/kv.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/kv.py) -Version 2.1 by Kelly Brazil (kellyjonbrazil@gmail.com) +Version 2.2 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/kv_dup.md b/docs/parsers/kv_dup.md index 3d2121790..f62f0ed9e 100644 --- a/docs/parsers/kv_dup.md +++ b/docs/parsers/kv_dup.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.kv\_dup +# jc.parsers.kv_dup jc - JSON Convert `Key/Value` with duplicate key file and string parser @@ -88,4 +88,4 @@ Compatibility: linux, darwin, cygwin, win32, aix, freebsd Source: [`jc/parsers/kv_dup.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/kv_dup.py) -Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com) +Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/ls_s.md b/docs/parsers/ls_s.md index c49d5a134..a6e73af32 100644 --- a/docs/parsers/ls_s.md +++ b/docs/parsers/ls_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.ls\_s +# jc.parsers.ls_s jc - JSON Convert `ls` and `vdir` command output streaming parser @@ -77,7 +77,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data, raw=False, quiet=False, ignore_exceptions=False) ``` diff --git a/docs/parsers/lsattr.md b/docs/parsers/lsattr.md index 1c5cf141a..768f6bbac 100644 --- a/docs/parsers/lsattr.md +++ b/docs/parsers/lsattr.md @@ -69,7 +69,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/lsb_release.md b/docs/parsers/lsb_release.md index 948233092..1dda22ce1 100644 --- a/docs/parsers/lsb_release.md +++ b/docs/parsers/lsb_release.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.lsb\_release +# jc.parsers.lsb_release jc - JSON Convert `lsb_release` command parser @@ -40,7 +40,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function @@ -60,4 +60,4 @@ Compatibility: linux, darwin, cygwin, win32, aix, freebsd Source: [`jc/parsers/lsb_release.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/lsb_release.py) -Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com) +Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/lspci.md b/docs/parsers/lspci.md index 95a058062..28b3dbcc6 100644 --- a/docs/parsers/lspci.md +++ b/docs/parsers/lspci.md @@ -127,7 +127,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/mpstat_s.md b/docs/parsers/mpstat_s.md index 310f52367..d92e61aa0 100644 --- a/docs/parsers/mpstat_s.md +++ b/docs/parsers/mpstat_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.mpstat\_s +# jc.parsers.mpstat_s jc - JSON Convert `mpstat` command output streaming parser @@ -100,7 +100,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data: Iterable[str], raw: bool = False, quiet: bool = False, diff --git a/docs/parsers/needrestart.md b/docs/parsers/needrestart.md new file mode 100644 index 000000000..e38596f0d --- /dev/null +++ b/docs/parsers/needrestart.md @@ -0,0 +1,101 @@ +[Home](https://kellyjonbrazil.github.io/jc/) + + +# jc.parsers.needrestart + +jc - JSON Convert `needrestart -b` command output parser + +Usage (cli): + + $ needrestart -b | jc --needrestart + +or + + $ jc needrestart -b + +Usage (module): + + import jc + result = jc.parse('needrestart', needrestart_command_output) + +Schema: + + { + "version": string, + "running_kernel_version": string, + "expected_kernel_version": string, + "kernel_status": integer, + "container": string, + "session": [ + string + ], + "service": [ + string + ], + "pid": [ + string + ] + } + +Examples: + + $ needrestart -b | jc --needrestart -p + { + "version": "2.1", + "running_kernel_version": "3.19.3-tl1+", + "expected_kernel_version": "3.19.3-tl1+", + "kernel_status": 1, + "container": "LXC web1", + "session": [ + "metabase @ user manager service", + "root @ session #28017" + ], + "service": [ + "systemd-journald.service", + "systemd-machined.service" + ] + } + + $ needrestart -b | jc --needrestart -p -r + { + "needrestart_ver": "2.1", + "needrestart_kcur": "3.19.3-tl1+", + "needrestart_kexp": "3.19.3-tl1+", + "needrestart_ksta": "1", + "needrestart_cont": "LXC web1", + "needrestart_sess": [ + "metabase @ user manager service", + "root @ session #28017" + ], + "needrestart_svc": [ + "systemd-journald.service", + "systemd-machined.service" + ] + } + + + +### parse + +```python +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] +``` + +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: + + Dictionary. Raw or processed structured data. + +### Parser Information +Compatibility: linux + +Source: [`jc/parsers/needrestart.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/needrestart.py) + +Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/nsd_control.md b/docs/parsers/nsd_control.md index 7231413f0..f236f8ae7 100644 --- a/docs/parsers/nsd_control.md +++ b/docs/parsers/nsd_control.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.nsd\_control +# jc.parsers.nsd_control jc - JSON Convert `nsd-control` command output parser diff --git a/docs/parsers/openvpn.md b/docs/parsers/openvpn.md index 9e362d871..6395ff8ba 100644 --- a/docs/parsers/openvpn.md +++ b/docs/parsers/openvpn.md @@ -157,7 +157,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/os_prober.md b/docs/parsers/os_prober.md index 5bbe08c06..94fb00d66 100644 --- a/docs/parsers/os_prober.md +++ b/docs/parsers/os_prober.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.os\_prober +# jc.parsers.os_prober jc - JSON Convert `os-prober` command output parser @@ -45,7 +45,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/os_release.md b/docs/parsers/os_release.md index ac057d073..cbf9a4be4 100644 --- a/docs/parsers/os_release.md +++ b/docs/parsers/os_release.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.os\_release +# jc.parsers.os_release jc - JSON Convert `/etc/os-release` file parser @@ -65,7 +65,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function @@ -85,4 +85,4 @@ Compatibility: linux, darwin, cygwin, win32, aix, freebsd Source: [`jc/parsers/os_release.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/os_release.py) -Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com) +Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/path_list.md b/docs/parsers/path_list.md index bf927d3dd..76b2bbaae 100644 --- a/docs/parsers/path_list.md +++ b/docs/parsers/path_list.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.path\_list +# jc.parsers.path_list jc - JSON Convert POSIX path list string parser diff --git a/docs/parsers/pci_ids.md b/docs/parsers/pci_ids.md index 8027887ac..ad728d4ed 100644 --- a/docs/parsers/pci_ids.md +++ b/docs/parsers/pci_ids.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.pci\_ids +# jc.parsers.pci_ids jc - JSON Convert `pci.ids` file parser @@ -78,7 +78,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/pgpass.md b/docs/parsers/pgpass.md index 62c96a244..d7576328c 100644 --- a/docs/parsers/pgpass.md +++ b/docs/parsers/pgpass.md @@ -54,7 +54,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/pidstat_s.md b/docs/parsers/pidstat_s.md index c834e3f4b..10a46efb5 100644 --- a/docs/parsers/pidstat_s.md +++ b/docs/parsers/pidstat_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.pidstat\_s +# jc.parsers.pidstat_s jc - JSON Convert `pidstat -H` command output streaming parser @@ -86,7 +86,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data: Iterable[str], raw: bool = False, quiet: bool = False, diff --git a/docs/parsers/ping_s.md b/docs/parsers/ping_s.md index 3b371a6f5..813dee9c3 100644 --- a/docs/parsers/ping_s.md +++ b/docs/parsers/ping_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.ping\_s +# jc.parsers.ping_s jc - JSON Convert `ping` command output streaming parser @@ -86,7 +86,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data, raw=False, quiet=False, ignore_exceptions=False) ``` diff --git a/docs/parsers/pip_list.md b/docs/parsers/pip_list.md index 75f30abc6..000dbfd3a 100644 --- a/docs/parsers/pip_list.md +++ b/docs/parsers/pip_list.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.pip\_list +# jc.parsers.pip_list jc - JSON Convert `pip-list` command output parser diff --git a/docs/parsers/pip_show.md b/docs/parsers/pip_show.md index a0dd6da2f..4900f9a0b 100644 --- a/docs/parsers/pip_show.md +++ b/docs/parsers/pip_show.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.pip\_show +# jc.parsers.pip_show jc - JSON Convert `pip-show` command output parser diff --git a/docs/parsers/pkg_index_apk.md b/docs/parsers/pkg_index_apk.md index 0dcd935e4..eed1ebc32 100644 --- a/docs/parsers/pkg_index_apk.md +++ b/docs/parsers/pkg_index_apk.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.pkg\_index\_apk +# jc.parsers.pkg_index_apk jc - JSON Convert Alpine Linux Package Index files diff --git a/docs/parsers/pkg_index_deb.md b/docs/parsers/pkg_index_deb.md index 9bf3ef784..fc623a567 100644 --- a/docs/parsers/pkg_index_deb.md +++ b/docs/parsers/pkg_index_deb.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.pkg\_index\_deb +# jc.parsers.pkg_index_deb jc - JSON Convert Debian Package Index file parser @@ -27,9 +27,15 @@ Schema: "maintainer": string, "description": string, "homepage": string, - "depends": string, - "conflicts": string, - "replaces": string, + "depends": [ + string + ], + "conflicts": [ + string + ], + "replaces": [ + string + ], "vcs_git": string, "sha256": string, "size": integer, @@ -43,35 +49,44 @@ Examples: $ cat Packages | jc --pkg-index-deb [ { - "package": "aspnetcore-runtime-2.1", - "version": "2.1.22-1", + "package": "dotnet-host", + "version": "3.1.16-1", "architecture": "amd64", - "section": "devel", + "section": "libs", "priority": "standard", - "installed_size": 71081, - "maintainer": "Microsoft ", - "description": "Microsoft ASP.NET Core 2.1.22 Shared Framework", - "homepage": "https://www.asp.net/", - "depends": "libc6 (>= 2.14), dotnet-runtime-2.1 (>= 2.1.22)", - "sha256": "48d4e78a7ceff34105411172f4c3e91a0359b3929d84d26a493...", - "size": 21937036, - "filename": "pool/main/a/aspnetcore-runtime-2.1/aspnetcore-run..." + "installed_size": 146, + "maintainer": ".NET Core Team ", + "description": "Microsoft .NET Core Host - 3.1.16", + "homepage": "https://dot.net/core", + "conflicts": [ + "dotnet", + "dotnet-nightly" + ], + "depends": [ + "libgcc1", + "libstdc++6", + "libc6" + ], + "sha256": "2557da13447d61382f255eb751ba29cc1a8220899c1e3e640a7bb3d2a0c1d297", + "size": 32594, + "filename": "pool/main/d/dotnet-host/dotnet-host-3.1.16-x64.deb" }, { - "package": "azure-functions-core-tools-4", - "version": "4.0.4590-1", + "package": "aspnetcore-runtime-5.0", + "version": "5.0.10-1", "architecture": "amd64", "section": "devel", - "priority": "optional", - "maintainer": "Ahmed ElSayed ", - "description": "Azure Function Core Tools v4", - "homepage": "https://docs.microsoft.com/en-us/azure/azure-func...", - "conflicts": "azure-functions-core-tools-2, azure-functions-co...", - "replaces": "azure-functions-core-tools-2, azure-functions-cor...", - "vcs_git": "https://github.com/Azure/azure-functions-core-tool...", - "sha256": "a2a4f99d6d98ba0a46832570285552f2a93bab06cebbda2afc7...", - "size": 124417844, - "filename": "pool/main/a/azure-functions-core-tools-4/azure-fu..." + "priority": "standard", + "installed_size": 18551, + "maintainer": "Microsoft ", + "description": "Shared Framework for hosting of Microsoft ASP.NET Core applications. It is open source, cross-platform and is supported by Microsoft. We hope you enjoy using it! If you do, please consider joining the active community of developers that are contributing to the project on GitHub (https://github.com/dotnet/aspnetcore). We happily accept issues and PRs.", + "homepage": "https://asp.net", + "depends": [ + "dotnet-runtime-5.0 (>= 5.0.10)" + ], + "sha256": "1d9869f862cb4e9c46b245a343d8e39fbbc84d9f8ab9ef357c4643da20805ad3", + "size": 6084188, + "filename": "pool/main/a/aspnetcore-runtime-5.0/aspnetcore-runtime-5.0.10-x64.deb" } ] @@ -117,7 +132,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function @@ -137,4 +152,4 @@ Compatibility: linux, darwin, cygwin, win32, aix, freebsd Source: [`jc/parsers/pkg_index_deb.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/pkg_index_deb.py) -Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com) +Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/proc.md b/docs/parsers/proc.md index 24dcdacbe..8b725fff5 100644 --- a/docs/parsers/proc.md +++ b/docs/parsers/proc.md @@ -52,7 +52,7 @@ Specific Proc file parser names can be found with `jc -hh` or `jc -a`. Schemas can also be found online at: -https://kellyjonbrazil.github.io/jc/docs/parsers/proc_ + https://kellyjonbrazil.github.io/jc/docs/parsers/proc_ For example: @@ -151,4 +151,4 @@ Source: [`jc/parsers/proc.py`](https://github.com/kellyjonbrazil/jc/blob/master/ This parser can be used with the `--slurp` command-line option. -Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com) +Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/proc_buddyinfo.md b/docs/parsers/proc_buddyinfo.md index b3e11944c..6a0ac4b94 100644 --- a/docs/parsers/proc_buddyinfo.md +++ b/docs/parsers/proc_buddyinfo.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_buddyinfo +# jc.parsers.proc_buddyinfo jc - JSON Convert `/proc/buddyinfo` file parser diff --git a/docs/parsers/proc_cmdline.md b/docs/parsers/proc_cmdline.md index d7c4c45cb..6c60f2714 100644 --- a/docs/parsers/proc_cmdline.md +++ b/docs/parsers/proc_cmdline.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_cmdline +# jc.parsers.proc_cmdline jc - JSON Convert `/proc/cmdline` file parser @@ -71,7 +71,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/proc_consoles.md b/docs/parsers/proc_consoles.md index 7f9cd7e53..7ed0bde19 100644 --- a/docs/parsers/proc_consoles.md +++ b/docs/parsers/proc_consoles.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_consoles +# jc.parsers.proc_consoles jc - JSON Convert `/proc/consoles` file parser diff --git a/docs/parsers/proc_cpuinfo.md b/docs/parsers/proc_cpuinfo.md index 1f72a8148..fae7ea589 100644 --- a/docs/parsers/proc_cpuinfo.md +++ b/docs/parsers/proc_cpuinfo.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_cpuinfo +# jc.parsers.proc_cpuinfo jc - JSON Convert `/proc/cpuinfo` file parser diff --git a/docs/parsers/proc_crypto.md b/docs/parsers/proc_crypto.md index b510720f2..eb1e279a0 100644 --- a/docs/parsers/proc_crypto.md +++ b/docs/parsers/proc_crypto.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_crypto +# jc.parsers.proc_crypto jc - JSON Convert `/proc/crypto` file parser diff --git a/docs/parsers/proc_devices.md b/docs/parsers/proc_devices.md index f8d3d483e..fe29248c8 100644 --- a/docs/parsers/proc_devices.md +++ b/docs/parsers/proc_devices.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_devices +# jc.parsers.proc_devices jc - JSON Convert `/proc/devices` file parser diff --git a/docs/parsers/proc_diskstats.md b/docs/parsers/proc_diskstats.md index c118922a3..7681c2461 100644 --- a/docs/parsers/proc_diskstats.md +++ b/docs/parsers/proc_diskstats.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_diskstats +# jc.parsers.proc_diskstats jc - JSON Convert `/proc/diskstats` file parser diff --git a/docs/parsers/proc_driver_rtc.md b/docs/parsers/proc_driver_rtc.md index 40591627f..bfe71885d 100644 --- a/docs/parsers/proc_driver_rtc.md +++ b/docs/parsers/proc_driver_rtc.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_driver\_rtc +# jc.parsers.proc_driver_rtc jc - JSON Convert `/proc/driver/rtc` file parser diff --git a/docs/parsers/proc_filesystems.md b/docs/parsers/proc_filesystems.md index 7947efde2..7eec09dbb 100644 --- a/docs/parsers/proc_filesystems.md +++ b/docs/parsers/proc_filesystems.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_filesystems +# jc.parsers.proc_filesystems jc - JSON Convert `/proc/filesystems` file parser diff --git a/docs/parsers/proc_interrupts.md b/docs/parsers/proc_interrupts.md index dc6fbf353..ff4b4c3f2 100644 --- a/docs/parsers/proc_interrupts.md +++ b/docs/parsers/proc_interrupts.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_interrupts +# jc.parsers.proc_interrupts jc - JSON Convert `/proc/interrupts` file parser diff --git a/docs/parsers/proc_iomem.md b/docs/parsers/proc_iomem.md index 848c7f477..7aeae5fc5 100644 --- a/docs/parsers/proc_iomem.md +++ b/docs/parsers/proc_iomem.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_iomem +# jc.parsers.proc_iomem jc - JSON Convert `/proc/iomem` file parser diff --git a/docs/parsers/proc_ioports.md b/docs/parsers/proc_ioports.md index a3c040cab..1077ac413 100644 --- a/docs/parsers/proc_ioports.md +++ b/docs/parsers/proc_ioports.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_ioports +# jc.parsers.proc_ioports jc - JSON Convert `/proc/ioports` file parser diff --git a/docs/parsers/proc_loadavg.md b/docs/parsers/proc_loadavg.md index 5562daf9f..324683030 100644 --- a/docs/parsers/proc_loadavg.md +++ b/docs/parsers/proc_loadavg.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_loadavg +# jc.parsers.proc_loadavg jc - JSON Convert `/proc/loadavg` file parser diff --git a/docs/parsers/proc_locks.md b/docs/parsers/proc_locks.md index 436203386..c1826dc0e 100644 --- a/docs/parsers/proc_locks.md +++ b/docs/parsers/proc_locks.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_locks +# jc.parsers.proc_locks jc - JSON Convert `/proc/locks` file parser diff --git a/docs/parsers/proc_meminfo.md b/docs/parsers/proc_meminfo.md index e70e6af25..a4383c841 100644 --- a/docs/parsers/proc_meminfo.md +++ b/docs/parsers/proc_meminfo.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_meminfo +# jc.parsers.proc_meminfo jc - JSON Convert `/proc/meminfo` file parser diff --git a/docs/parsers/proc_modules.md b/docs/parsers/proc_modules.md index 2e7c3fc00..119535c1a 100644 --- a/docs/parsers/proc_modules.md +++ b/docs/parsers/proc_modules.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_modules +# jc.parsers.proc_modules jc - JSON Convert `/proc/modules` file parser diff --git a/docs/parsers/proc_mtrr.md b/docs/parsers/proc_mtrr.md index 85575c624..ec286ca4d 100644 --- a/docs/parsers/proc_mtrr.md +++ b/docs/parsers/proc_mtrr.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_mtrr +# jc.parsers.proc_mtrr jc - JSON Convert `/proc/mtrr` file parser diff --git a/docs/parsers/proc_net_arp.md b/docs/parsers/proc_net_arp.md index e772b26e0..f773db239 100644 --- a/docs/parsers/proc_net_arp.md +++ b/docs/parsers/proc_net_arp.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_arp +# jc.parsers.proc_net_arp jc - JSON Convert `/proc/net/arp` file parser diff --git a/docs/parsers/proc_net_dev.md b/docs/parsers/proc_net_dev.md index 03fdabeb5..021c1dfe7 100644 --- a/docs/parsers/proc_net_dev.md +++ b/docs/parsers/proc_net_dev.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_dev +# jc.parsers.proc_net_dev jc - JSON Convert `/proc/net/dev` file parser diff --git a/docs/parsers/proc_net_dev_mcast.md b/docs/parsers/proc_net_dev_mcast.md index 32c64984f..66b9ef57a 100644 --- a/docs/parsers/proc_net_dev_mcast.md +++ b/docs/parsers/proc_net_dev_mcast.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_dev\_mcast +# jc.parsers.proc_net_dev_mcast jc - JSON Convert `/proc/net/dev_mcast` file parser diff --git a/docs/parsers/proc_net_if_inet6.md b/docs/parsers/proc_net_if_inet6.md index 75abcfcef..894ecd7ad 100644 --- a/docs/parsers/proc_net_if_inet6.md +++ b/docs/parsers/proc_net_if_inet6.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_if\_inet6 +# jc.parsers.proc_net_if_inet6 jc - JSON Convert `/proc/net/if_inet6` file parser diff --git a/docs/parsers/proc_net_igmp.md b/docs/parsers/proc_net_igmp.md index 26af814ae..c7a1b989a 100644 --- a/docs/parsers/proc_net_igmp.md +++ b/docs/parsers/proc_net_igmp.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_igmp +# jc.parsers.proc_net_igmp jc - JSON Convert `/proc/net/igmp` file parser diff --git a/docs/parsers/proc_net_igmp6.md b/docs/parsers/proc_net_igmp6.md index 21ff8be25..dfcf20fff 100644 --- a/docs/parsers/proc_net_igmp6.md +++ b/docs/parsers/proc_net_igmp6.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_igmp6 +# jc.parsers.proc_net_igmp6 jc - JSON Convert `/proc/net/igmp6` file parser diff --git a/docs/parsers/proc_net_ipv6_route.md b/docs/parsers/proc_net_ipv6_route.md index 8b3f6e993..4549c5ea7 100644 --- a/docs/parsers/proc_net_ipv6_route.md +++ b/docs/parsers/proc_net_ipv6_route.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_ipv6\_route +# jc.parsers.proc_net_ipv6_route jc - JSON Convert `/proc/net/ipv6_route` file parser diff --git a/docs/parsers/proc_net_netlink.md b/docs/parsers/proc_net_netlink.md index dcf432ffd..fda000bfe 100644 --- a/docs/parsers/proc_net_netlink.md +++ b/docs/parsers/proc_net_netlink.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_netlink +# jc.parsers.proc_net_netlink jc - JSON Convert `/proc/net/netlink` file parser diff --git a/docs/parsers/proc_net_netstat.md b/docs/parsers/proc_net_netstat.md index 6d3f6d0ab..51be58ac6 100644 --- a/docs/parsers/proc_net_netstat.md +++ b/docs/parsers/proc_net_netstat.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_netstat +# jc.parsers.proc_net_netstat jc - JSON Convert `/proc/net/netstat` file parser diff --git a/docs/parsers/proc_net_packet.md b/docs/parsers/proc_net_packet.md index 01a716c90..e6ff1fe18 100644 --- a/docs/parsers/proc_net_packet.md +++ b/docs/parsers/proc_net_packet.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_packet +# jc.parsers.proc_net_packet jc - JSON Convert `/proc/net/packet` file parser diff --git a/docs/parsers/proc_net_protocols.md b/docs/parsers/proc_net_protocols.md index def15550e..ab980b423 100644 --- a/docs/parsers/proc_net_protocols.md +++ b/docs/parsers/proc_net_protocols.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_protocols +# jc.parsers.proc_net_protocols jc - JSON Convert `/proc/net/protocols` file parser diff --git a/docs/parsers/proc_net_route.md b/docs/parsers/proc_net_route.md index ec37c1bc0..5c0865744 100644 --- a/docs/parsers/proc_net_route.md +++ b/docs/parsers/proc_net_route.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_route +# jc.parsers.proc_net_route jc - JSON Convert `/proc/net/route` file parser diff --git a/docs/parsers/proc_net_tcp.md b/docs/parsers/proc_net_tcp.md index ec34df35e..57656f5ba 100644 --- a/docs/parsers/proc_net_tcp.md +++ b/docs/parsers/proc_net_tcp.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_tcp +# jc.parsers.proc_net_tcp jc - JSON Convert `/proc/net/tcp` and `proc/net/tcp6` file parser diff --git a/docs/parsers/proc_net_unix.md b/docs/parsers/proc_net_unix.md index 89932f985..372712e83 100644 --- a/docs/parsers/proc_net_unix.md +++ b/docs/parsers/proc_net_unix.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_unix +# jc.parsers.proc_net_unix jc - JSON Convert `/proc/net/unix` file parser diff --git a/docs/parsers/proc_pagetypeinfo.md b/docs/parsers/proc_pagetypeinfo.md index 2320e688c..1451ae027 100644 --- a/docs/parsers/proc_pagetypeinfo.md +++ b/docs/parsers/proc_pagetypeinfo.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_pagetypeinfo +# jc.parsers.proc_pagetypeinfo jc - JSON Convert `/proc/pagetypeinfo` file parser diff --git a/docs/parsers/proc_partitions.md b/docs/parsers/proc_partitions.md index b4a9cb8e1..e00e1f77e 100644 --- a/docs/parsers/proc_partitions.md +++ b/docs/parsers/proc_partitions.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_partitions +# jc.parsers.proc_partitions jc - JSON Convert `/proc/partitions` file parser diff --git a/docs/parsers/proc_pid_fdinfo.md b/docs/parsers/proc_pid_fdinfo.md index 891b9cbc1..e725b0e94 100644 --- a/docs/parsers/proc_pid_fdinfo.md +++ b/docs/parsers/proc_pid_fdinfo.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_pid\_fdinfo +# jc.parsers.proc_pid_fdinfo jc - JSON Convert `/proc//fdinfo/` file parser diff --git a/docs/parsers/proc_pid_io.md b/docs/parsers/proc_pid_io.md index c4ebed773..f2761302c 100644 --- a/docs/parsers/proc_pid_io.md +++ b/docs/parsers/proc_pid_io.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_pid\_io +# jc.parsers.proc_pid_io jc - JSON Convert `/proc//io` file parser diff --git a/docs/parsers/proc_pid_maps.md b/docs/parsers/proc_pid_maps.md index e3e72c063..0705d16de 100644 --- a/docs/parsers/proc_pid_maps.md +++ b/docs/parsers/proc_pid_maps.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_pid\_maps +# jc.parsers.proc_pid_maps jc - JSON Convert `/proc//maps` file parser diff --git a/docs/parsers/proc_pid_mountinfo.md b/docs/parsers/proc_pid_mountinfo.md index ac839702c..bfd60129c 100644 --- a/docs/parsers/proc_pid_mountinfo.md +++ b/docs/parsers/proc_pid_mountinfo.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_pid\_mountinfo +# jc.parsers.proc_pid_mountinfo jc - JSON Convert `/proc//mountinfo` file parser diff --git a/docs/parsers/proc_pid_numa_maps.md b/docs/parsers/proc_pid_numa_maps.md index 63304c173..d46b9d0dd 100644 --- a/docs/parsers/proc_pid_numa_maps.md +++ b/docs/parsers/proc_pid_numa_maps.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_pid\_numa\_maps +# jc.parsers.proc_pid_numa_maps jc - JSON Convert `/proc//numa_maps` file parser diff --git a/docs/parsers/proc_pid_smaps.md b/docs/parsers/proc_pid_smaps.md index a33aaae15..c3a778cce 100644 --- a/docs/parsers/proc_pid_smaps.md +++ b/docs/parsers/proc_pid_smaps.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_pid\_smaps +# jc.parsers.proc_pid_smaps jc - JSON Convert `/proc//smaps` file parser diff --git a/docs/parsers/proc_pid_stat.md b/docs/parsers/proc_pid_stat.md index 50c6e4401..fa0901ebd 100644 --- a/docs/parsers/proc_pid_stat.md +++ b/docs/parsers/proc_pid_stat.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_pid\_stat +# jc.parsers.proc_pid_stat jc - JSON Convert `/proc//stat` file parser @@ -225,4 +225,4 @@ Compatibility: linux Source: [`jc/parsers/proc_pid_stat.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/proc_pid_stat.py) -Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com) +Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/proc_pid_statm.md b/docs/parsers/proc_pid_statm.md index 64536f8e7..1bdfc1cd5 100644 --- a/docs/parsers/proc_pid_statm.md +++ b/docs/parsers/proc_pid_statm.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_pid\_statm +# jc.parsers.proc_pid_statm jc - JSON Convert `/proc//statm` file parser diff --git a/docs/parsers/proc_pid_status.md b/docs/parsers/proc_pid_status.md index 2a9b95b37..1332989eb 100644 --- a/docs/parsers/proc_pid_status.md +++ b/docs/parsers/proc_pid_status.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_pid\_status +# jc.parsers.proc_pid_status jc - JSON Convert `/proc//status` file parser diff --git a/docs/parsers/proc_slabinfo.md b/docs/parsers/proc_slabinfo.md index 938dafc58..6758d6b8e 100644 --- a/docs/parsers/proc_slabinfo.md +++ b/docs/parsers/proc_slabinfo.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_slabinfo +# jc.parsers.proc_slabinfo jc - JSON Convert `/proc/slabinfo` file parser diff --git a/docs/parsers/proc_softirqs.md b/docs/parsers/proc_softirqs.md index 518223fa7..d1d01194f 100644 --- a/docs/parsers/proc_softirqs.md +++ b/docs/parsers/proc_softirqs.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_softirqs +# jc.parsers.proc_softirqs jc - JSON Convert `/proc/softirqs` file parser diff --git a/docs/parsers/proc_stat.md b/docs/parsers/proc_stat.md index ee6710852..ae42916af 100644 --- a/docs/parsers/proc_stat.md +++ b/docs/parsers/proc_stat.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_stat +# jc.parsers.proc_stat jc - JSON Convert `/proc/stat` file parser diff --git a/docs/parsers/proc_swaps.md b/docs/parsers/proc_swaps.md index 59b47872a..a9317df48 100644 --- a/docs/parsers/proc_swaps.md +++ b/docs/parsers/proc_swaps.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_swaps +# jc.parsers.proc_swaps jc - JSON Convert `/proc/swaps` file parser diff --git a/docs/parsers/proc_uptime.md b/docs/parsers/proc_uptime.md index 6b807abee..48a8f52a4 100644 --- a/docs/parsers/proc_uptime.md +++ b/docs/parsers/proc_uptime.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_uptime +# jc.parsers.proc_uptime jc - JSON Convert `/proc/uptime` file parser diff --git a/docs/parsers/proc_version.md b/docs/parsers/proc_version.md index 1c05fb4f5..fe060d7e9 100644 --- a/docs/parsers/proc_version.md +++ b/docs/parsers/proc_version.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_version +# jc.parsers.proc_version jc - JSON Convert `/proc/version` file parser diff --git a/docs/parsers/proc_vmallocinfo.md b/docs/parsers/proc_vmallocinfo.md index 81ededbbf..f1f18b019 100644 --- a/docs/parsers/proc_vmallocinfo.md +++ b/docs/parsers/proc_vmallocinfo.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_vmallocinfo +# jc.parsers.proc_vmallocinfo jc - JSON Convert `/proc/vmallocinfo` file parser diff --git a/docs/parsers/proc_vmstat.md b/docs/parsers/proc_vmstat.md index b176dc2cf..388924211 100644 --- a/docs/parsers/proc_vmstat.md +++ b/docs/parsers/proc_vmstat.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_vmstat +# jc.parsers.proc_vmstat jc - JSON Convert `/proc/vmstat` file parser diff --git a/docs/parsers/proc_zoneinfo.md b/docs/parsers/proc_zoneinfo.md index 16cfa908d..b337260fc 100644 --- a/docs/parsers/proc_zoneinfo.md +++ b/docs/parsers/proc_zoneinfo.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_zoneinfo +# jc.parsers.proc_zoneinfo jc - JSON Convert `/proc/zoneinfo` file parser diff --git a/docs/parsers/resolve_conf.md b/docs/parsers/resolve_conf.md index 9a21a1d03..29eed2930 100644 --- a/docs/parsers/resolve_conf.md +++ b/docs/parsers/resolve_conf.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.resolve\_conf +# jc.parsers.resolve_conf jc - JSON Convert `/etc/resolve.conf` file parser @@ -62,7 +62,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/rpm_qi.md b/docs/parsers/rpm_qi.md index b85336ddc..8df44a462 100644 --- a/docs/parsers/rpm_qi.md +++ b/docs/parsers/rpm_qi.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.rpm\_qi +# jc.parsers.rpm_qi jc - JSON Convert `rpm -qi` command output parser @@ -48,6 +48,30 @@ Schema: "build_epoch_utc": integer, # [1] "build_host": string, "relocations": string, + "depends": [ + string + ], + "pre_depends": [ + string + ], + "recommends": [ + string + ], + "suggests": [ + string + ], + "conflicts": [ + string + ], + "breaks": [ + string + ], + "tag": [ + string + ], + "replaces": [ + string + ], "packager": string, "vendor": string, "url": string, @@ -186,4 +210,4 @@ Compatibility: linux Source: [`jc/parsers/rpm_qi.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/rpm_qi.py) -Version 1.7 by Kelly Brazil (kellyjonbrazil@gmail.com) +Version 1.8 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/rsync.md b/docs/parsers/rsync.md index 177d9a5dd..dc9cbe7c5 100644 --- a/docs/parsers/rsync.md +++ b/docs/parsers/rsync.md @@ -159,4 +159,4 @@ Compatibility: linux, darwin, freebsd Source: [`jc/parsers/rsync.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/rsync.py) -Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com) +Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/rsync_s.md b/docs/parsers/rsync_s.md index 9945321b0..ccb9770d2 100644 --- a/docs/parsers/rsync_s.md +++ b/docs/parsers/rsync_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.rsync\_s +# jc.parsers.rsync_s jc - JSON Convert `rsync` command output streaming parser @@ -89,7 +89,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data: Iterable[str], raw: bool = False, quiet: bool = False, @@ -116,4 +115,4 @@ Compatibility: linux, darwin, freebsd Source: [`jc/parsers/rsync_s.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/rsync_s.py) -Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com) +Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/semver.md b/docs/parsers/semver.md index 57615dc33..9b7a8e37a 100644 --- a/docs/parsers/semver.md +++ b/docs/parsers/semver.md @@ -56,7 +56,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/srt.md b/docs/parsers/srt.md index 3c5a23d91..6d6a1a26e 100644 --- a/docs/parsers/srt.md +++ b/docs/parsers/srt.md @@ -91,23 +91,6 @@ Examples: ... ] - - -### parse\_timestamp - -```python -def parse_timestamp(timestamp: str) -> Dict -``` - -timestamp: "hours:minutes:seconds,milliseconds" ---> -{ - "hours": "hours", - "minutes": "minutes", - "seconds": "seconds", - "milliseconds": "milliseconds", - "timestamp": "hours:minutes:seconds,milliseconds" -} - ### parse @@ -115,7 +98,7 @@ timestamp: "hours:minutes:seconds,milliseconds" ---> ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/ssh_conf.md b/docs/parsers/ssh_conf.md index c0b6d8742..3996db3e3 100644 --- a/docs/parsers/ssh_conf.md +++ b/docs/parsers/ssh_conf.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.ssh\_conf +# jc.parsers.ssh_conf jc - JSON Convert `ssh` configuration file and `ssh -G` command output parser @@ -527,7 +527,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/sshd_conf.md b/docs/parsers/sshd_conf.md index 698a4e7d2..212659674 100644 --- a/docs/parsers/sshd_conf.md +++ b/docs/parsers/sshd_conf.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.sshd\_conf +# jc.parsers.sshd_conf jc - JSON Convert `sshd` configuration file and `sshd -T` command output parser @@ -486,7 +486,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/stat_s.md b/docs/parsers/stat_s.md index 8e459e3d6..67c9439db 100644 --- a/docs/parsers/stat_s.md +++ b/docs/parsers/stat_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.stat\_s +# jc.parsers.stat_s jc - JSON Convert `stat` command output streaming parser @@ -82,11 +82,12 @@ Examples: ### parse ```python -@add_jc_meta -def parse(data: Iterable[str], - raw: bool = False, - quiet: bool = False, - ignore_exceptions: bool = False) -> StreamingOutputType +def parse( + data: Iterable[str], + raw: bool = False, + quiet: bool = False, + ignore_exceptions: bool = False +) -> Iterator[Union[Dict[str, Any], Tuple[BaseException, str]]] ``` Main text parsing generator function. Returns an iterable object. diff --git a/docs/parsers/swapon.md b/docs/parsers/swapon.md index c79d624a9..40094f09d 100644 --- a/docs/parsers/swapon.md +++ b/docs/parsers/swapon.md @@ -48,7 +48,9 @@ Example: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> List[_Entry] +def parse(data: str, + raw: bool = False, + quiet: bool = False) -> List[Dict[str, Union[str, int]]] ``` Main text parsing function diff --git a/docs/parsers/syslog_bsd.md b/docs/parsers/syslog_bsd.md index 3366b8eb5..5bd62711e 100644 --- a/docs/parsers/syslog_bsd.md +++ b/docs/parsers/syslog_bsd.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.syslog\_bsd +# jc.parsers.syslog_bsd jc - JSON Convert Syslog RFC 3164 string parser diff --git a/docs/parsers/syslog_bsd_s.md b/docs/parsers/syslog_bsd_s.md index c2e0294f9..6a46a4247 100644 --- a/docs/parsers/syslog_bsd_s.md +++ b/docs/parsers/syslog_bsd_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.syslog\_bsd\_s +# jc.parsers.syslog_bsd_s jc - JSON Convert Syslog RFC 3164 string streaming parser @@ -62,7 +62,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data: Iterable[str], raw: bool = False, quiet: bool = False, diff --git a/docs/parsers/syslog_s.md b/docs/parsers/syslog_s.md index 87e7b44fd..d3f7a66fc 100644 --- a/docs/parsers/syslog_s.md +++ b/docs/parsers/syslog_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.syslog\_s +# jc.parsers.syslog_s jc - JSON Convert Syslog RFC 5424 string streaming parser @@ -85,7 +85,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data: Iterable[str], raw: bool = False, quiet: bool = False, diff --git a/docs/parsers/systemctl_lj.md b/docs/parsers/systemctl_lj.md index 3b34918cc..2f3086809 100644 --- a/docs/parsers/systemctl_lj.md +++ b/docs/parsers/systemctl_lj.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.systemctl\_lj +# jc.parsers.systemctl_lj jc - JSON Convert `systemctl list-jobs` command output parser diff --git a/docs/parsers/systemctl_ls.md b/docs/parsers/systemctl_ls.md index 7bf0ba0f9..9b7d2b4a8 100644 --- a/docs/parsers/systemctl_ls.md +++ b/docs/parsers/systemctl_ls.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.systemctl\_ls +# jc.parsers.systemctl_ls jc - JSON Convert `systemctl list-sockets` command output parser diff --git a/docs/parsers/systemctl_luf.md b/docs/parsers/systemctl_luf.md index 5780bc334..7cffd6f0b 100644 --- a/docs/parsers/systemctl_luf.md +++ b/docs/parsers/systemctl_luf.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.systemctl\_luf +# jc.parsers.systemctl_luf jc - JSON Convert `systemctl list-unit-files` command output parser diff --git a/docs/parsers/toml.md b/docs/parsers/toml.md index 6763e97b9..ee716316c 100644 --- a/docs/parsers/toml.md +++ b/docs/parsers/toml.md @@ -60,7 +60,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/top_s.md b/docs/parsers/top_s.md index 88a3bbd5b..87897094f 100644 --- a/docs/parsers/top_s.md +++ b/docs/parsers/top_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.top\_s +# jc.parsers.top_s jc - JSON Convert `top -b` command output streaming parser @@ -151,7 +151,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data: Iterable[str], raw: bool = False, quiet: bool = False, diff --git a/docs/parsers/tune2fs.md b/docs/parsers/tune2fs.md index 27ec64f8e..91b237ee4 100644 --- a/docs/parsers/tune2fs.md +++ b/docs/parsers/tune2fs.md @@ -214,7 +214,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/udevadm.md b/docs/parsers/udevadm.md index 2c7cdf601..27e643d1c 100644 --- a/docs/parsers/udevadm.md +++ b/docs/parsers/udevadm.md @@ -122,7 +122,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/ufw_appinfo.md b/docs/parsers/ufw_appinfo.md index af74b6b2d..00c68a4c3 100644 --- a/docs/parsers/ufw_appinfo.md +++ b/docs/parsers/ufw_appinfo.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.ufw\_appinfo +# jc.parsers.ufw_appinfo jc - JSON Convert `ufw app info [application]` command output parser diff --git a/docs/parsers/universal.md b/docs/parsers/universal.md index ab8b1266b..5f5b0967a 100644 --- a/docs/parsers/universal.md +++ b/docs/parsers/universal.md @@ -1,18 +1,19 @@ -# Table of Contents - -* [jc.parsers.universal](#jc.parsers.universal) - * [simple\_table\_parse](#jc.parsers.universal.simple_table_parse) - * [sparse\_table\_parse](#jc.parsers.universal.sparse_table_parse) - +[Home](https://kellyjonbrazil.github.io/jc/) # jc.parsers.universal +## Table of Contents + +* [jc.parsers.universal](#jc.parsers.universal) + * [simple_table_parse](#jc.parsers.universal.simple_table_parse) + * [sparse_table_parse](#jc.parsers.universal.sparse_table_parse) + jc - JSON Convert universal parsers -### simple\_table\_parse +### simple_table_parse ```python def simple_table_parse(data: Iterable[str]) -> List[Dict] @@ -50,7 +51,7 @@ Returns: -### sparse\_table\_parse +### sparse_table_parse ```python def sparse_table_parse(data: Iterable[str], @@ -86,7 +87,7 @@ Parameters: Also, ensure there are no blank line items. - delim: (string) Delimiter to use. By default `u\\2063` + delim: (string) Delimiter to use. By default `u\2063` (invisible separator) is used since it is unlikely to ever be seen in terminal output. You can change this for troubleshooting purposes or if there is a @@ -96,3 +97,4 @@ Returns: List of Dictionaries + diff --git a/docs/parsers/update_alt_gs.md b/docs/parsers/update_alt_gs.md index 86bdfd6e8..e4a1b2c2b 100644 --- a/docs/parsers/update_alt_gs.md +++ b/docs/parsers/update_alt_gs.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.update\_alt\_gs +# jc.parsers.update_alt_gs jc - JSON Convert `update-alternatives --get-selections` command output parser diff --git a/docs/parsers/update_alt_q.md b/docs/parsers/update_alt_q.md index 02c1165f6..c6ddf5efc 100644 --- a/docs/parsers/update_alt_q.md +++ b/docs/parsers/update_alt_q.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.update\_alt\_q +# jc.parsers.update_alt_q jc - JSON Convert `update-alternatives --query` command output parser diff --git a/docs/parsers/ver.md b/docs/parsers/ver.md index b1948934e..8fcbcfa36 100644 --- a/docs/parsers/ver.md +++ b/docs/parsers/ver.md @@ -91,7 +91,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function @@ -113,4 +113,4 @@ Source: [`jc/parsers/ver.py`](https://github.com/kellyjonbrazil/jc/blob/master/j This parser can be used with the `--slurp` command-line option. -Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com) +Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/veracrypt.md b/docs/parsers/veracrypt.md index 08d3f6d83..8f5c4ab00 100644 --- a/docs/parsers/veracrypt.md +++ b/docs/parsers/veracrypt.md @@ -87,7 +87,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/vmstat_s.md b/docs/parsers/vmstat_s.md index 5c4bf7ec7..1d5c6c6f4 100644 --- a/docs/parsers/vmstat_s.md +++ b/docs/parsers/vmstat_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.vmstat\_s +# jc.parsers.vmstat_s jc - JSON Convert `vmstat` command output streaming parser @@ -101,7 +101,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data, raw=False, quiet=False, ignore_exceptions=False) ``` diff --git a/docs/parsers/x509_cert.md b/docs/parsers/x509_cert.md index 0c5f2854f..a9d237250 100644 --- a/docs/parsers/x509_cert.md +++ b/docs/parsers/x509_cert.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.x509\_cert +# jc.parsers.x509_cert jc - JSON Convert X.509 Certificate format file parser diff --git a/docs/parsers/x509_csr.md b/docs/parsers/x509_csr.md index bd13c9eb9..ec9638dfe 100644 --- a/docs/parsers/x509_csr.md +++ b/docs/parsers/x509_csr.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.x509\_csr +# jc.parsers.x509_csr jc - JSON Convert X.509 Certificate Request format file parser diff --git a/docs/parsers/xrandr.md b/docs/parsers/xrandr.md index bd85056f6..bb525c3fa 100644 --- a/docs/parsers/xrandr.md +++ b/docs/parsers/xrandr.md @@ -33,6 +33,16 @@ Schema: "maximum_height": integer, "devices": [ { + "props": { + + # either an EdidModel object or key value pairs + : { + "name": string, + "product_id": string, + "serial_number": string, + } + + }, "resolution_modes": [ { "resolution_width": integer, @@ -92,26 +102,9 @@ Examples: "frequency": 60.03, "is_current": true, "is_preferred": true - }, - { - "frequency": 59.93, - "is_current": false, - "is_preferred": false } ] }, - { - "resolution_width": 1680, - "resolution_height": 1050, - "is_high_resolution": false, - "frequencies": [ - { - "frequency": 59.88, - "is_current": false, - "is_preferred": false - } - ] - } ], "is_connected": true, "is_primary": true, @@ -134,40 +127,41 @@ Examples: { "screens": [ { - "screen_number": 0, - "minimum_width": 8, - "minimum_height": 8, - "current_width": 1920, - "current_height": 1080, - "maximum_width": 32767, - "maximum_height": 32767, "devices": [ { + "props": { + "EDID": [ + "00ffff5700000000", + "001c01a5544d9a27", + "0e50540101010101", + "010101383e401010", + "3500350f00000000", + "0000000000fe0041", + "554f0a20000000fe", + "00423137200a0070" + ], + "scaling mode": [ + "Full aspect ", + "supported: Full, Center, Full aspect" + ], + "Colorspace": [ + "Default ", + "supported: Default, RGB_Wide_Gamut_Fixed_Point, RGB_Wide_Gamut_Floating_Point, opRGB, DCI-P3_RGB_D65, BT2020_RGB, BT601_YCC, BT709_YCC, XVYCC_601, XVYCC_709, SYCC_601, opYCC_601, BT2020_CYCC, BT2020_YCC" + ], + "EdidModel": { + "name": "Generic", + "product_id": "22333", + "serial_number": "0" + } + }, "resolution_modes": [ { - "resolution_width": 1920, - "resolution_height": 1080, + "resolution_width": 320, + "resolution_height": 180, "is_high_resolution": false, "frequencies": [ { - "frequency": 60.03, - "is_current": true, - "is_preferred": true - }, - { - "frequency": 59.93, - "is_current": false, - "is_preferred": false - } - ] - }, - { - "resolution_width": 1680, - "resolution_height": 1050, - "is_high_resolution": false, - "frequencies": [ - { - "frequency": 59.88, + "frequency": 59.84, "is_current": false, "is_preferred": false } @@ -176,20 +170,24 @@ Examples: ], "is_connected": true, "is_primary": true, - "device_name": "eDP1", - "model_name": "ASUS VW193S", - "product_id": "54297", - "serial_number": "78L8021107", + "device_name": "eDP-1", + "rotation": "normal", + "reflection": "normal", "resolution_width": 1920, "resolution_height": 1080, "offset_width": 0, "offset_height": 0, - "dimension_width": 310, - "dimension_height": 170, - "rotation": "normal", - "reflection": "normal" + "dimension_width": 309, + "dimension_height": 174 } - ] + ], + "screen_number": 0, + "minimum_width": 320, + "minimum_height": 200, + "current_width": 1920, + "current_height": 1080, + "maximum_width": 16384, + "maximum_height": 16384 } ] } @@ -199,7 +197,9 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> Response +def parse(data: str, + raw: bool = False, + quiet: bool = False) -> jc.parsers.xrandr.Response ``` Main text parsing function @@ -219,4 +219,4 @@ Compatibility: linux, darwin, cygwin, aix, freebsd Source: [`jc/parsers/xrandr.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/xrandr.py) -Version 2.0 by Kevin Lyter (code (at) lyterk.com) +Version 2.1 by Kevin Lyter (code (at) lyterk.com) diff --git a/docs/parsers/zpool_iostat.md b/docs/parsers/zpool_iostat.md index 828bd804f..fd260ecf2 100644 --- a/docs/parsers/zpool_iostat.md +++ b/docs/parsers/zpool_iostat.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.zpool\_iostat +# jc.parsers.zpool_iostat jc - JSON Convert `zpool iostat` command output parser @@ -104,7 +104,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/zpool_status.md b/docs/parsers/zpool_status.md index a43d7aa1c..a9b6c8d5e 100644 --- a/docs/parsers/zpool_status.md +++ b/docs/parsers/zpool_status.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.zpool\_status +# jc.parsers.zpool_status jc - JSON Convert `zpool status` command output parser @@ -142,7 +142,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/readme.md b/docs/readme.md index 488c3d004..8ae724369 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -1,3 +1,4 @@ +[Home](https://kellyjonbrazil.github.io/jc/) # jc diff --git a/docs/streaming.md b/docs/streaming.md index 3b593a96e..09ddb82c4 100644 --- a/docs/streaming.md +++ b/docs/streaming.md @@ -1,67 +1,26 @@ -# Table of Contents - -* [jc.streaming](#jc.streaming) - * [streaming\_input\_type\_check](#jc.streaming.streaming_input_type_check) - * [streaming\_line\_input\_type\_check](#jc.streaming.streaming_line_input_type_check) - * [stream\_success](#jc.streaming.stream_success) - * [stream\_error](#jc.streaming.stream_error) - * [add\_jc\_meta](#jc.streaming.add_jc_meta) - * [raise\_or\_yield](#jc.streaming.raise_or_yield) - +[Home](https://kellyjonbrazil.github.io/jc/) # jc.streaming -jc - JSON Convert streaming utils - - - -### streaming\_input\_type\_check - -```python -def streaming_input_type_check(data: Iterable[Union[str, bytes]]) -> None -``` - -Ensure input data is an iterable, but not a string or bytes. Raises -`TypeError` if not. - - - -### streaming\_line\_input\_type\_check - -```python -def streaming_line_input_type_check(line: str) -> None -``` - -Ensure each line is a string. Raises `TypeError` if not. - - - -### stream\_success - -```python -def stream_success(output_line: JSONDictType, - ignore_exceptions: bool) -> JSONDictType -``` +## Table of Contents -Add `_jc_meta` object to output line if `ignore_exceptions=True` - - - -### stream\_error - -```python -def stream_error(e: BaseException, line: str) -> JSONDictType -``` +* [jc.streaming](#jc.streaming) + * [add_jc_meta](#jc.streaming.add_jc_meta) + * [raise_or_yield](#jc.streaming.raise_or_yield) + * [stream_error](#jc.streaming.stream_error) + * [stream_success](#jc.streaming.stream_success) + * [streaming_input_type_check](#jc.streaming.streaming_input_type_check) + * [streaming_line_input_type_check](#jc.streaming.streaming_line_input_type_check) -Return an error `_jc_meta` field. +jc - JSON Convert streaming utils -### add\_jc\_meta +### add_jc_meta ```python -def add_jc_meta(func: F) -> F +def add_jc_meta(func: ~F) -> ~F ``` Decorator for streaming parsers to add stream_success and stream_error @@ -103,7 +62,7 @@ In all cases above: -### raise\_or\_yield +### raise_or_yield ```python def raise_or_yield(ignore_exceptions: bool, e: BaseException, @@ -114,3 +73,46 @@ Return the exception object and line string if ignore_exceptions is True. Otherwise, re-raise the exception from the exception object with an annotation. + + +### stream_error + +```python +def stream_error(e: BaseException, line: str) -> Dict[str, Any] +``` + +Return an error `_jc_meta` field. + + + +### stream_success + +```python +def stream_success(output_line: Dict[str, Any], + ignore_exceptions: bool) -> Dict[str, Any] +``` + +Add `_jc_meta` object to output line if `ignore_exceptions=True` + + + +### streaming_input_type_check + +```python +def streaming_input_type_check(data: Iterable[Union[str, bytes]]) -> None +``` + +Ensure input data is an iterable, but not a string or bytes. Raises +`TypeError` if not. + + + +### streaming_line_input_type_check + +```python +def streaming_line_input_type_check(line: str) -> None +``` + +Ensure each line is a string. Raises `TypeError` if not. + + diff --git a/docs/utils.md b/docs/utils.md index 30899517c..de07a4e4f 100644 --- a/docs/utils.md +++ b/docs/utils.md @@ -1,77 +1,26 @@ -# Table of Contents - -* [jc.utils](#jc.utils) - * [warning\_message](#jc.utils.warning_message) - * [error\_message](#jc.utils.error_message) - * [is\_compatible](#jc.utils.is_compatible) - * [compatibility](#jc.utils.compatibility) - * [has\_data](#jc.utils.has_data) - * [remove\_quotes](#jc.utils.remove_quotes) - * [normalize\_key](#jc.utils.normalize_key) - * [convert\_to\_int](#jc.utils.convert_to_int) - * [convert\_to\_float](#jc.utils.convert_to_float) - * [convert\_to\_bool](#jc.utils.convert_to_bool) - * [convert\_size\_to\_int](#jc.utils.convert_size_to_int) - * [input\_type\_check](#jc.utils.input_type_check) - * [line\_slice](#jc.utils.line_slice) - * [timestamp](#jc.utils.timestamp) - * [\_\_init\_\_](#jc.utils.timestamp.__init__) - +[Home](https://kellyjonbrazil.github.io/jc/) # jc.utils -jc - JSON Convert utils - - - -### warning\_message - -```python -def warning_message(message_lines: List[str]) -> None -``` - -Prints warning message to `STDERR` for non-fatal issues. The first line -is prepended with 'jc: Warning - ' and subsequent lines are indented. -Wraps text as needed based on the terminal width. - -Parameters: - - message: (list) list of string lines - -Returns: - - None - just prints output to STDERR - - - -### error\_message - -```python -def error_message(message_lines: List[str]) -> None -``` +## Table of Contents -Prints an error message to `STDERR` for fatal issues. The first line is -prepended with 'jc: Error - ' and subsequent lines are indented. -Wraps text as needed based on the terminal width. - -Parameters: - - message: (list) list of string lines - -Returns: - - None - just prints output to STDERR - - - -### is\_compatible - -```python -def is_compatible(compatible: List[str]) -> bool -``` +* [jc.utils](#jc.utils) + * [compatibility](#jc.utils.compatibility) + * [convert_size_to_int](#jc.utils.convert_size_to_int) + * [convert_to_bool](#jc.utils.convert_to_bool) + * [convert_to_float](#jc.utils.convert_to_float) + * [convert_to_int](#jc.utils.convert_to_int) + * [error_message](#jc.utils.error_message) + * [has_data](#jc.utils.has_data) + * [input_type_check](#jc.utils.input_type_check) + * [is_compatible](#jc.utils.is_compatible) + * [line_slice](#jc.utils.line_slice) + * [normalize_key](#jc.utils.normalize_key) + * [remove_quotes](#jc.utils.remove_quotes) + * [warning_message](#jc.utils.warning_message) -Returns True if the parser is compatible with the running OS platform. +jc - JSON Convert utils @@ -101,77 +50,90 @@ Returns: None - just prints output to STDERR - + -### has\_data +### convert_size_to_int ```python -def has_data(data: Union[str, bytes]) -> bool +def convert_size_to_int(size: str, binary: bool = False) -> Optional[int] ``` -Checks if the string input contains data. If there are any -non-whitespace characters then return `True`, else return `False`. - -For bytes, returns True if there is any data. +Parse a human readable data size and return the number of bytes. Parameters: - data: (string, bytes) input to check whether it contains data - + size: (string) The human readable file size to parse. + binary: (boolean) `True` to use binary multiples of bytes + (base-2) for ambiguous unit symbols and names, + `False` to use decimal multiples of bytes (base-10). Returns: - Boolean True if input string (data) contains non-whitespace - characters, otherwise False. For bytes data, returns - True if there is any data, otherwise False. + integer/None Integer if successful conversion, otherwise None - +This function knows how to parse sizes in bytes, kilobytes, megabytes, +gigabytes, terabytes and petabytes. Some examples: + + >>> convert_size_to_int('42') + 42 + >>> convert_size_to_int('13b') + 13 + >>> convert_size_to_int('5 bytes') + 5 + >>> convert_size_to_int('1 KB') + 1000 + >>> convert_size_to_int('1 kilobyte') + 1000 + >>> convert_size_to_int('1 KiB') + 1024 + >>> convert_size_to_int('1 KB', binary=True) + 1024 + >>> convert_size_to_int('1.5 GB') + 1500000000 + >>> convert_size_to_int('1.5 GB', binary=True) + 1610612736 + + -### remove\_quotes +### convert_to_bool ```python -def remove_quotes(data: str) -> str +def convert_to_bool(value: object) -> bool ``` -Remove single or double quotes surrounding a string. If no quotes are -found then the string is returned unmodified. +Converts string, integer, or float input to boolean by checking +for 'truthy' values. Parameters: - data: (string) Input value + value: (string/integer/float) Input value Returns: - string + True/False False unless a 'truthy' number or string is found + ('y', 'yes', 'true', '1', 1, -1, etc.) - + -### normalize\_key +### convert_to_float ```python -def normalize_key(data: str) -> str +def convert_to_float(value: object) -> Optional[float] ``` -Normalize a key name by shifting to lower-case and converting special -characters to underscores. - -Special characters are defined as `space` and the following: - - !"#$%&'()*+,-./:;<=>?@[\]^`{|}~ - -This is a lossy algorithm. Repeating and trailing underscores are -removed. +Converts string and int input to float. Strips all non-numeric +characters from strings. Parameters: - data: (string) Input value + value: (string/integer) Input value Returns: - string + float/None Float if successful conversion, otherwise None -### convert\_to\_int +### convert_to_int ```python def convert_to_int(value: object) -> Optional[int] @@ -188,107 +150,79 @@ Returns: integer/None Integer if successful conversion, otherwise None - + -### convert\_to\_float +### error_message ```python -def convert_to_float(value: object) -> Optional[float] +def error_message(message_lines: List[str]) -> None ``` -Converts string and int input to float. Strips all non-numeric -characters from strings. +Prints an error message to `STDERR` for fatal issues. The first line is +prepended with 'jc: Error - ' and subsequent lines are indented. +Wraps text as needed based on the terminal width. Parameters: - value: (string/integer) Input value + message: (list) list of string lines Returns: - float/None Float if successful conversion, otherwise None + None - just prints output to STDERR - + -### convert\_to\_bool +### has_data ```python -def convert_to_bool(value: object) -> bool +def has_data(data: Union[str, bytes]) -> bool ``` -Converts string, integer, or float input to boolean by checking -for 'truthy' values. +Checks if the string input contains data. If there are any +non-whitespace characters then return `True`, else return `False`. + +For bytes, returns True if there is any data. Parameters: - value: (string/integer/float) Input value + data: (string, bytes) input to check whether it contains data Returns: - True/False False unless a 'truthy' number or string is found - ('y', 'yes', 'true', '1', 1, -1, etc.) + Boolean True if input string (data) contains non-whitespace + characters, otherwise False. For bytes data, returns + True if there is any data, otherwise False. - + -### convert\_size\_to\_int +### input_type_check ```python -def convert_size_to_int(size: str, binary: bool = False) -> Optional[int] +def input_type_check(data: object) -> None ``` -Parse a human readable data size and return the number of bytes. - -Parameters: - - size: (string) The human readable file size to parse. - binary: (boolean) `True` to use binary multiples of bytes - (base-2) for ambiguous unit symbols and names, - `False` to use decimal multiples of bytes (base-10). -Returns: - - integer/None Integer if successful conversion, otherwise None - -This function knows how to parse sizes in bytes, kilobytes, megabytes, -gigabytes, terabytes and petabytes. Some examples: - - >>> convert_size_to_int('42') - 42 - >>> convert_size_to_int('13b') - 13 - >>> convert_size_to_int('5 bytes') - 5 - >>> convert_size_to_int('1 KB') - 1000 - >>> convert_size_to_int('1 kilobyte') - 1000 - >>> convert_size_to_int('1 KiB') - 1024 - >>> convert_size_to_int('1 KB', binary=True) - 1024 - >>> convert_size_to_int('1.5 GB') - 1500000000 - >>> convert_size_to_int('1.5 GB', binary=True) - 1610612736 +Ensure input data is a string. Raises `TypeError` if not. - + -### input\_type\_check +### is_compatible ```python -def input_type_check(data: object) -> None +def is_compatible(compatible: List[str]) -> bool ``` -Ensure input data is a string. Raises `TypeError` if not. +Returns True if the parser is compatible with the running OS platform. -### line\_slice +### line_slice ```python def line_slice( - data: Union[str, Iterable[str], TextIO, bytes, None], + data: Union[str, Iterable[str], TextIO, bytes, NoneType], slice_start: Optional[int] = None, slice_end: Optional[int] = None -) -> Union[str, Iterable[str], TextIO, bytes, None] +) -> Union[str, Iterable[str], TextIO, bytes, NoneType] ``` Slice input data by lines - lazily, if possible. @@ -310,51 +244,69 @@ Returns: string if input is a string. iterable of strings if input is an iterable (for streaming parsers) - + -### timestamp Objects +### normalize_key ```python -class timestamp() +def normalize_key(data: str) -> str ``` - +Normalize a key name by shifting to lower-case and converting special +characters to underscores. + +Special characters are defined as `space` and the following: + + !"#$%&'()*+,-./:;<=>?@[\]^`{|}~ + +This is a lossy algorithm. Repeating and trailing underscores are +removed. + +Parameters: + + data: (string) Input value + +Returns: + + string -### \_\_init\_\_ + + +### remove_quotes ```python -def __init__(datetime_string: Optional[str], - format_hint: Optional[Iterable[int]] = None) -> None +def remove_quotes(data: str) -> str ``` -Input a datetime text string of several formats and convert to a -naive or timezone-aware epoch timestamp in UTC. +Remove single or double quotes surrounding a string. If no quotes are +found then the string is returned unmodified. Parameters: - datetime_string (str): a string representation of a - datetime in several supported formats + data: (string) Input value + +Returns: + + string - format_hint (iterable): an optional iterable of format ID - integers to instruct the timestamp object to try those - formats first in the order given. Other formats will be - tried after the format hint list is exhausted. This can - speed up timestamp conversion so several different formats - don't have to be tried in brute-force fashion. + -Returns a timestamp object with the following attributes: +### warning_message - string (str): the input datetime string +```python +def warning_message(message_lines: List[str]) -> None +``` - format (int | None): the format rule that was used to decode - the datetime string. None if conversion fails. +Prints warning message to `STDERR` for non-fatal issues. The first line +is prepended with 'jc: Warning - ' and subsequent lines are indented. +Wraps text as needed based on the terminal width. + +Parameters: - naive (int | None): timestamp based on locally configured - timezone. None if conversion fails. + message: (list) list of string lines - utc (int | None): aware timestamp only if UTC timezone - detected in datetime string. None if conversion fails. +Returns: + + None - just prints output to STDERR - iso (str | None): ISO string - timezone information is output - only if UTC timezone is detected in the datetime string. diff --git a/jc/lib.py b/jc/lib.py index cf2429dbe..96b35ec56 100644 --- a/jc/lib.py +++ b/jc/lib.py @@ -10,12 +10,14 @@ from jc import utils -__version__ = '1.25.1' +__version__ = '1.25.2' parsers: List[str] = [ 'acpi', 'airport', 'airport-s', + 'apt-cache-show', + 'apt-get-sqq', 'arp', 'asciitable', 'asciitable-m', @@ -46,6 +48,7 @@ 'efibootmgr', 'email-address', 'env', + 'ethtool', 'file', 'find', 'findmnt', @@ -96,6 +99,7 @@ 'mount', 'mpstat', 'mpstat-s', + 'needrestart', 'netstat', 'nmcli', 'nsd-control', diff --git a/jc/parsers/acpi.py b/jc/parsers/acpi.py index 8b3a080df..e8a96336f 100644 --- a/jc/parsers/acpi.py +++ b/jc/parsers/acpi.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `acpi` command output parser +r"""jc - JSON Convert `acpi` command output parser Usage (cli): diff --git a/jc/parsers/airport.py b/jc/parsers/airport.py index 696100f83..3c3d7e699 100644 --- a/jc/parsers/airport.py +++ b/jc/parsers/airport.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `airport -I` command output parser +r"""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 802c726ec..d804226ba 100644 --- a/jc/parsers/airport_s.py +++ b/jc/parsers/airport_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `airport -s` command output parser +r"""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/apt_cache_show.py b/jc/parsers/apt_cache_show.py new file mode 100644 index 000000000..62ede53ae --- /dev/null +++ b/jc/parsers/apt_cache_show.py @@ -0,0 +1,189 @@ +r"""jc - JSON Convert `apt-cache show` command parser + +Usage (cli): + + $ apt-cache show | jc --apt-cache-show + +Usage (module): + + import jc + result = jc.parse('apt_cache_show', apt_cache_show_output) + +Schema: + + [ + { + "package": string, + "version": string, + "installed_size": integer, + "maintainer": string, + "architecture": string, + "depends": [ + string + ], + "pre_depends": [ + string + ], + "recommends": [ + string + ], + "suggests": [ + string + ], + "conflicts": [ + string + ], + "breaks": [ + string + ], + "description_md5": string, + "multi_arch": string, + "homepage": string, + "section": string, + "priority": string, + "filename": string, + "size": integer, + "sha256": string, + "description": string + } + ] + +Examples: + + $ apt-cache show | jc --apt-cache-show -p + [ + { + "package": "systemd", + "version": "247.3-6~bpo10+1", + "installed_size": 16121, + "maintainer": "Debian systemd Maintainers = 2.2.23)", + "libapparmor1 (>= 2.13)", + "libaudit1 (>= 1:2.2.1)", + "libcap2 (>= 1:2.10)", + "libcryptsetup12 (>= 2:2.0.1)", + "libgnutls30 (>= 3.6.6)", + "libgpg-error0 (>= 1.14)", + "libip4tc0 (>= 1.6.0+snapshot20161117)", + "libkmod2 (>= 5~)", + "liblz4-1 (>= 0.0~r130)", + "libmount1 (>= 2.30)", + "libpam0g (>= 0.99.7.1)", + "libseccomp2 (>= 2.3.1)", + "libsystemd0 (= 247.3-6~bpo10+1)", + "systemd-timesyncd | time-daemon", + "util-linux (>= 2.27.1)", + "mount (>= 2.26)", + "adduser" + ], + "pre_depends": [ + "libblkid1 (>= 2.24)", + "libc6 (>= 2.28)", + "libgcrypt20 (>= 1.8.0)", + "liblz4-1 (>= 0.0~r122)", + "liblzma5 (>= 5.1.1alpha+20120614)", + "libselinux1 (>= 2.1.9)", + "libzstd1 (>= 1.4.0)" + ], + "recommends": [ + "dbus" + ], + "suggests": [ + "systemd-container", + "policykit-1" + ], + "conflicts": [ + "consolekit", + "libpam-ck-connector" + ], + "breaks": [ + "python-dbusmock (<< 0.18)", + "python3-dbusmock (<< 0.18)", + "resolvconf (<< 1.83~)", + "systemd-shim (<< 10-4~)", + "udev (<< 247~)" + ], + "description_md5": "19399579cbc0c47a303288bf15eadcd4", + "multi_arch": "foreign", + "homepage": "https://www.freedesktop.org/wiki/Software/systemd", + "section": "admin", + "priority": "important", + "filename": "pool/main/s/systemd/systemd_247.3-6~bpo10+1_amd64.deb", + "size": 4382056, + "sha256": "2035450655ad02faa0f75dc952128b503e51df5795c67273c0f6...", + "description": "system and service manager systemd is a system..." + }, + ... + ] + + $ apt-cache show | jc --apt-cache-show -p -r + [ + { + "package": "systemd", + "version": "247.3-6~bpo10+1", + "installed_size": "16121", + "maintainer": "Debian systemd Maintainers = 2.2.23), libapparmor1 (>= 2.13), libaud...", + "pre_depends": "libblkid1 (>= 2.24), libc6 (>= 2.28), libgcrypt...", + "recommends": "dbus", + "suggests": "systemd-container, policykit-1", + "conflicts": "consolekit, libpam-ck-connector", + "breaks": "python-dbusmock (<< 0.18), python3-dbusmock (<< 0.18...", + "description_md5": "19399579cbc0c47a303288bf15eadcd4", + "multi_arch": "foreign", + "homepage": "https://www.freedesktop.org/wiki/Software/systemd", + "section": "admin", + "priority": "important", + "filename": "pool/main/s/systemd/systemd_247.3-6~bpo10+1_amd64.deb", + "size": "4382056", + "sha256": "2035450655ad02faa0f75dc952128b503e51df5795c67273c0f6...", + "description": "system and service manager systemd is a system..." + }, + ... + ] +""" +from typing import List +from jc.jc_types import JSONDictType +import jc.parsers.rpm_qi as rpm_qi + + +class info(): + """Provides parser metadata (version, author, etc.)""" + version = '1.0' + description = '`apt-cache show` command parser' + author = 'Kelly Brazil' + author_email = 'kellyjonbrazil@gmail.com' + details = 'Using the rpm-qi parser' + compatible = ['linux'] + tags = ['command'] + magic_commands = ['apt-cache show'] + + +__version__ = info.version + + +def parse( + data: str, + raw: bool = False, + quiet: bool = False +) -> List[JSONDictType]: + """ + 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. + """ + # This parser is an alias of rpm_qi.py + rpm_qi.info = info # type: ignore + rpm_qi.__name__ = __name__ + return rpm_qi.parse(data, raw, quiet) diff --git a/jc/parsers/apt_get_sqq.py b/jc/parsers/apt_get_sqq.py new file mode 100644 index 000000000..77001cb99 --- /dev/null +++ b/jc/parsers/apt_get_sqq.py @@ -0,0 +1,279 @@ +r"""jc - JSON Convert `apt-get -sqq` command output parser + +Requires the `-sqq` options in `apt-get`. + +Usage (cli): + + $ apt-get -sqq | jc --apt-get-sqq + +or + + $ jc apt-get -sqq + +Usage (module): + + import jc + result = jc.parse('apt_get_sqq', apt_get_sqq_command_output) + +Schema: + + [ + { + "operation": string, # configure, remove, or unpack + "package": string, + "broken": string/null, + "proposed_pkg_ver": string, + "existing_pkg_ver": string/null, + "architecture": string + } + ] + +Examples: + + $ apt-get -sqq | jc --apt-get-sqq -p + [ + { + "operation": "unpack", + "package": "dpkg", + "broken": "1.19.7", + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + }, + { + "operation": "unpack", + "package": "dpkg", + "broken": null, + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + }, + { + "operation": "configure", + "package": "dpkg", + "broken": "1.19.7", + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + }, + { + "operation": "remove", + "package": "dpkg", + "broken": "1.19.7", + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + }, + { + "operation": "unpack", + "package": "base-files", + "broken": "10.3+deb10u4", + "proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable", + "existing_pkg_ver": null, + "architecture": "amd64" + }, + { + "operation": "configure", + "package": "base-files", + "broken": null, + "proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable", + "existing_pkg_ver": null, + "architecture": "amd64" + }, + { + "operation": "unpack", + "package": "dpkg", + "broken": "1.19.7", + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + }, + { + "operation": "configure", + "package": "dpkg", + "broken": null, + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + } + ] + + $ apt-get -sqq | jc --apt-get-sqq -p -r + [ + { + "operation": "Inst", + "package": "dpkg", + "broken": "1.19.7", + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + }, + { + "operation": "Inst", + "package": "dpkg", + "broken": null, + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + }, + { + "operation": "Conf", + "package": "dpkg", + "broken": "1.19.7", + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + }, + { + "operation": "Remv", + "package": "dpkg", + "broken": "1.19.7", + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + }, + { + "operation": "Inst", + "package": "base-files", + "broken": "10.3+deb10u4", + "proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable", + "existing_pkg_ver": null, + "architecture": "amd64" + }, + { + "operation": "Conf", + "package": "base-files", + "broken": null, + "proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable", + "existing_pkg_ver": null, + "architecture": "amd64" + }, + { + "operation": "Inst", + "package": "dpkg", + "broken": "1.19.7", + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + }, + { + "operation": "Conf", + "package": "dpkg", + "broken": null, + "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", + "architecture": "amd64" + } + ] +""" +import re +from typing import List, Dict +from jc.jc_types import JSONDictType +import jc.utils + + +class info(): + """Provides parser metadata (version, author, etc.)""" + version = '1.0' + description = '`apt-get -sqq` command parser' + author = 'Kelly Brazil' + author_email = 'kellyjonbrazil@gmail.com' + compatible = ['linux'] + tags = ['command'] + magic_commands = ['apt-get -sqq'] + + +__version__ = info.version + + +def _process(proc_data: List[JSONDictType]) -> List[JSONDictType]: + """ + 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. + """ + op_map = { + 'Conf': 'configure', + 'Remv': 'remove', + 'Inst': 'unpack' + } + + for item in proc_data: + if 'operation' in item and item['operation']: + item['operation'] = op_map[item['operation']] + + return proc_data + + +def parse( + data: str, + raw: bool = False, + quiet: bool = False +) -> List[JSONDictType]: + """ + 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[Dict] = [] + + if jc.utils.has_data(data): + + # Inst dpkg [1.19.7] (1.19.8 Debian:10.13/oldstable, Debian-Security:10/oldstable [amd64]) + # | | | | | \architecture + # | | | | \existing_pkg_ver (optional) + # | | | \proposed_pkg_ver + # | | \broken (optional) + # | \package + # \operation (configure, remove, or unpack) + + line_re = re.compile(r'(?PInst|Conf|Remv)\s(?P\S+)(?P\s+\[\S*?\])?\s\((?P.*?)\[(?P\w*)\]\)') + + for line in filter(None, data.splitlines()): + broken_val = None + packages_pe = None + proposed_pkg_ver = None + existing_pkg_ver = None + parsed_line = line_re.match(line) + + if parsed_line: + parsed_dict = parsed_line.groupdict() + + if parsed_dict['broken']: + broken_val = parsed_dict['broken'].strip()[1:-1] + + if parsed_dict['packages_pe']: + packages_pe = parsed_dict['packages_pe'].split(',') + proposed_pkg_ver = packages_pe[0].strip() + if len(packages_pe) == 2: + existing_pkg_ver = packages_pe[1].strip() + + output_line = { + 'operation': parsed_dict['operation'], + 'package': parsed_dict['package'], + 'broken': broken_val, + 'proposed_pkg_ver': proposed_pkg_ver, + 'existing_pkg_ver': existing_pkg_ver, + 'architecture': parsed_dict['architecture'] + } + + raw_output.append(output_line) + + return raw_output if raw else _process(raw_output) diff --git a/jc/parsers/arp.py b/jc/parsers/arp.py index db00708dd..be0b6edca 100644 --- a/jc/parsers/arp.py +++ b/jc/parsers/arp.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `arp` command output parser +r"""jc - JSON Convert `arp` command output parser Supports `arp` and `arp -a` output. diff --git a/jc/parsers/asciitable.py b/jc/parsers/asciitable.py index b7da4b949..4e2768c7f 100644 --- a/jc/parsers/asciitable.py +++ b/jc/parsers/asciitable.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `asciitable` parser +r"""jc - JSON Convert `asciitable` parser This parser converts ASCII and Unicode text tables with single-line rows. diff --git a/jc/parsers/asciitable_m.py b/jc/parsers/asciitable_m.py index 24b55487e..bc6cb9795 100644 --- a/jc/parsers/asciitable_m.py +++ b/jc/parsers/asciitable_m.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `asciitable-m` parser +r"""jc - JSON Convert `asciitable-m` parser This parser converts various styles of ASCII and Unicode text tables with multi-line rows. Tables must have a header row and separator line between diff --git a/jc/parsers/blkid.py b/jc/parsers/blkid.py index 6d28664c4..d799af915 100644 --- a/jc/parsers/blkid.py +++ b/jc/parsers/blkid.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `blkid` command output parser +r"""jc - JSON Convert `blkid` command output parser Usage (cli): diff --git a/jc/parsers/bluetoothctl.py b/jc/parsers/bluetoothctl.py index da3209e0f..24fc553e0 100644 --- a/jc/parsers/bluetoothctl.py +++ b/jc/parsers/bluetoothctl.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `bluetoothctl` command output parser +r"""jc - JSON Convert `bluetoothctl` command output parser Supports the following `bluetoothctl` subcommands: - `bluetoothctl list` diff --git a/jc/parsers/broken_parser.py b/jc/parsers/broken_parser.py index ded316ed6..475b460da 100644 --- a/jc/parsers/broken_parser.py +++ b/jc/parsers/broken_parser.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert broken parser - for testing purposes only""" +r"""jc - JSON Convert broken parser - for testing purposes only""" import non_existent_library class info(): diff --git a/jc/parsers/cbt.py b/jc/parsers/cbt.py index 184993fa7..7296b41aa 100644 --- a/jc/parsers/cbt.py +++ b/jc/parsers/cbt.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `cbt` command output parser (Google Bigtable) +r"""jc - JSON Convert `cbt` command output parser (Google Bigtable) Parses the human-, but not machine-, friendly output of the cbt command (for Google's Bigtable). diff --git a/jc/parsers/cef.py b/jc/parsers/cef.py index dae7bc54c..af9d1a412 100644 --- a/jc/parsers/cef.py +++ b/jc/parsers/cef.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert CEF string parser +r"""jc - JSON Convert CEF string parser This parser conforms to the Microfocus Arcsight CEF specification. diff --git a/jc/parsers/cef_s.py b/jc/parsers/cef_s.py index 00215aca8..442479121 100644 --- a/jc/parsers/cef_s.py +++ b/jc/parsers/cef_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert CEF string output streaming parser +r"""jc - JSON Convert CEF string output streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/certbot.py b/jc/parsers/certbot.py index 1bf442c03..99ae223c2 100644 --- a/jc/parsers/certbot.py +++ b/jc/parsers/certbot.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `certbot` command output parser +r"""jc - JSON Convert `certbot` command output parser Supports the following `certbot` commands: diff --git a/jc/parsers/chage.py b/jc/parsers/chage.py index ad24cffa3..35a43fe69 100644 --- a/jc/parsers/chage.py +++ b/jc/parsers/chage.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `chage --list` command output parser +r"""jc - JSON Convert `chage --list` command output parser Supports `chage -l ` or `chage --list ` diff --git a/jc/parsers/cksum.py b/jc/parsers/cksum.py index 4e798474c..463380f1c 100644 --- a/jc/parsers/cksum.py +++ b/jc/parsers/cksum.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `cksum` command output parser +r"""jc - JSON Convert `cksum` command output parser This parser works with the following checksum calculation utilities: - `sum` diff --git a/jc/parsers/clf.py b/jc/parsers/clf.py index 374553cee..fed1d94c8 100644 --- a/jc/parsers/clf.py +++ b/jc/parsers/clf.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Common Log Format file parser +r"""jc - JSON Convert Common Log Format file parser This parser will handle the Common Log Format standard as specified at https://www.w3.org/Daemon/User/Config/Logging.html#common-logfile-format. diff --git a/jc/parsers/clf_s.py b/jc/parsers/clf_s.py index fc43ed1e4..2debae02b 100644 --- a/jc/parsers/clf_s.py +++ b/jc/parsers/clf_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Common Log Format file streaming parser +r"""jc - JSON Convert Common Log Format file streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/crontab.py b/jc/parsers/crontab.py index 78ff53360..0df442d14 100644 --- a/jc/parsers/crontab.py +++ b/jc/parsers/crontab.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `crontab -l` command output and crontab +r"""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 0379d6c39..5d20ec9de 100644 --- a/jc/parsers/crontab_u.py +++ b/jc/parsers/crontab_u.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `crontab -l` command output and crontab +r"""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 e97e96696..7d56fe3a4 100644 --- a/jc/parsers/csv.py +++ b/jc/parsers/csv.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `csv` file parser +r"""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 9eaf1a1b7..5fa0be355 100644 --- a/jc/parsers/csv_s.py +++ b/jc/parsers/csv_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `csv` file streaming parser +r"""jc - JSON Convert `csv` file streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/curl_head.py b/jc/parsers/curl_head.py index 2c917a297..187939495 100644 --- a/jc/parsers/curl_head.py +++ b/jc/parsers/curl_head.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `curl --head` command output parser +r"""jc - JSON Convert `curl --head` command output parser This parser converts standard and verbose `curl --head` output. diff --git a/jc/parsers/date.py b/jc/parsers/date.py index abcc3e7a3..931cf5df3 100644 --- a/jc/parsers/date.py +++ b/jc/parsers/date.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `date` command output parser +r"""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/datetime_iso.py b/jc/parsers/datetime_iso.py index 6fddff335..f092b1aa1 100644 --- a/jc/parsers/datetime_iso.py +++ b/jc/parsers/datetime_iso.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert ISO 8601 Datetime string parser +r"""jc - JSON Convert ISO 8601 Datetime string parser This parser supports standard ISO 8601 strings that include both date and time. If no timezone or offset information is available in the string, then diff --git a/jc/parsers/debconf_show.py b/jc/parsers/debconf_show.py index a4dfc8d60..b7a366cb3 100644 --- a/jc/parsers/debconf_show.py +++ b/jc/parsers/debconf_show.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `debconf-show` command output parser +r"""jc - JSON Convert `debconf-show` command output parser Usage (cli): diff --git a/jc/parsers/df.py b/jc/parsers/df.py index 50fdfa8e1..fbe1ca802 100644 --- a/jc/parsers/df.py +++ b/jc/parsers/df.py @@ -1,4 +1,6 @@ -"""jc - JSON Convert `df` command output parser +r"""jc - JSON Convert `df` command output parser + +Values are normalized to bytes when using `df -h`. Usage (cli): @@ -18,7 +20,7 @@ [ { "filesystem": string, - "size": string, + "size": integer, "1k_blocks": integer, "512_blocks": integer, "used": integer, @@ -99,7 +101,7 @@ class info(): """Provides parser metadata (version, author, etc.)""" - version = '1.11' + version = '2.0' description = '`df` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -123,23 +125,19 @@ def _process(proc_data): List of Dictionaries. Structured data to conform to the schema: """ - int_list = {'used', 'available', 'use_percent', 'capacity_percent', 'ifree', - 'iused', 'iused_percent'} + int_list = {'use_percent', 'capacity_percent', 'ifree', 'iused', 'iused_percent'} + size_list = {'size', 'used', 'available'} for entry in proc_data: - # change 'avail' to 'available' if 'avail' in entry: entry['available'] = entry.pop('avail') - # change 'use%' to 'use_percent' if 'use%' in entry: entry['use_percent'] = entry.pop('use%') - # change 'capacity' to 'capacity_percent' if 'capacity' in entry: entry['capacity_percent'] = entry.pop('capacity') - # change '%iused' to 'iused_percent' if '%iused' in entry: entry['iused_percent'] = entry.pop('%iused') @@ -158,6 +156,11 @@ def _process(proc_data): if 'iused_percent' in entry: entry['iused_percent'] = entry['iused_percent'].rstrip('%') + # parse the size, used, and available fields to bytes + for key in entry: + if key in size_list: + entry[key] = jc.utils.convert_size_to_int(entry[key]) + # convert integers for key in entry: if key in int_list: @@ -245,7 +248,4 @@ def parse(data, raw=False, quiet=False): if item['filesystem'] in filesystem_map: item['filesystem'] = filesystem_map[item['filesystem']] - if raw: - return raw_output - else: - return _process(raw_output) + return raw_output if raw else _process(raw_output) diff --git a/jc/parsers/dig.py b/jc/parsers/dig.py index cc146019c..172ebeba4 100644 --- a/jc/parsers/dig.py +++ b/jc/parsers/dig.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `dig` command output parser +r"""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 0115fce63..d522d94a5 100644 --- a/jc/parsers/dir.py +++ b/jc/parsers/dir.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `dir` command output parser +r"""jc - JSON Convert `dir` command output parser Options supported: - `/T timefield` diff --git a/jc/parsers/disabled_parser.py b/jc/parsers/disabled_parser.py index 1ed79a890..b68a48791 100644 --- a/jc/parsers/disabled_parser.py +++ b/jc/parsers/disabled_parser.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert disabled parser +r"""jc - JSON Convert disabled parser This parser has been disabled due to an error in the parser code. """ diff --git a/jc/parsers/dmidecode.py b/jc/parsers/dmidecode.py index 98a342e31..043f715a3 100644 --- a/jc/parsers/dmidecode.py +++ b/jc/parsers/dmidecode.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `dmidecode` command output parser +r"""jc - JSON Convert `dmidecode` command output parser Usage (cli): diff --git a/jc/parsers/dpkg_l.py b/jc/parsers/dpkg_l.py index 6375c6080..26d870299 100644 --- a/jc/parsers/dpkg_l.py +++ b/jc/parsers/dpkg_l.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `dpkg -l` command output parser +r"""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 f55edda25..ad600fc16 100644 --- a/jc/parsers/du.py +++ b/jc/parsers/du.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `du` command output parser +r"""jc - JSON Convert `du` command output parser The `du -h` option is not supported with the default output. If you would like to use `du -h` or other options that change the output, be sure diff --git a/jc/parsers/efibootmgr.py b/jc/parsers/efibootmgr.py index 0d5b70153..0850c54e1 100644 --- a/jc/parsers/efibootmgr.py +++ b/jc/parsers/efibootmgr.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `efibootmgr` command output parser +r"""jc - JSON Convert `efibootmgr` command output parser The `-v` option is also supported. diff --git a/jc/parsers/email_address.py b/jc/parsers/email_address.py index 9dd6833f2..ea8e89f1c 100644 --- a/jc/parsers/email_address.py +++ b/jc/parsers/email_address.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Email Address string parser +r"""jc - JSON Convert Email Address string parser Usage (cli): diff --git a/jc/parsers/env.py b/jc/parsers/env.py index 4f2280c8b..68d08af60 100644 --- a/jc/parsers/env.py +++ b/jc/parsers/env.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `env` and `printenv` command output parser +r"""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/ethtool.py b/jc/parsers/ethtool.py new file mode 100644 index 000000000..3a353a3f8 --- /dev/null +++ b/jc/parsers/ethtool.py @@ -0,0 +1,440 @@ +r"""jc - JSON Convert `ethtool` command output parser + +Supports standard `ethtool` output and the `--module-info` option. + +Usage (cli): + + $ ethtool | jc --ethtool + $ ethtool --module-info | jc --ethtool + +or + + $ jc ethtool + $ jc ethtool --module-info + +Usage (module): + + import jc + result = jc.parse('ethtool', ethtool_command_output) + +Schema: + +Note: many units fields are converted to integers and floats +when detected. Use raw output for the original string values. + + { + "name": string, + "supported_ports": [ + string + ], + "supported_link_modes": [ + string + ], + "supported_pause_frame_use": string, + "supports_auto_negotiation": boolean, + "supported_fec_modes": [ + string + ], + "advertised_link_modes": [ + string + ], + "advertised_pause_frame_use": boolean, + "advertised_auto_negotiation": boolean, + "advertised_fec_modes": [ + string + ], + "speed": string, + "speed_bps": integer, + "duplex": string, + "auto_negotiation": boolean, + "port": string, + "phyad": string, + "mdi_x": string, + "transceiver": string, + "supports_wake_on": string, + "wake_on": string, + "current_message_level": [ + string + ], + "link_detected": boolean, + "identifier": string, + "extended_identifier": string, + "connector": string, + "transceiver_codes": string, + "transceiver_type": [ + string + ], + "encoding": string, + "br_nominal": string, + "rate_identifier": string, + "length_smf_km": string, + "length_smf": string, + "length_50um": string, + "length_62_5um": string, + "length_copper": string, + "length_om3": string, + "passive_cu_cmplnce": string, + "vendor_name": string, + "vendor_oui": string, + "vendor_pn": string, + "vendor_rev": string, + "option_values": string, + "br_margin_max": string, + "br_margin_min": string + } + +Examples: + + $ ethtool enp0s3 | jc --ethtool -p + { + "name": "enp0s3", + "supported_pause_frame_use": "No", + "supports_auto_negotiation": true, + "supported_fec_modes": "Not reported", + "advertised_pause_frame_use": false, + "advertised_auto_negotiation": true, + "advertised_fec_modes": "Not reported", + "speed": "1000Mb/s", + "duplex": "Full", + "port": "Twisted Pair", + "phyad": "0", + "transceiver": "internal", + "auto_negotiation": false, + "mdi_x": "off (auto)", + "supports_wake_on": "umbg", + "wake_on": "d", + "link_detected": true, + "supported_ports": [ + "TP" + ], + "supported_link_modes": [ + "10baseT/Half", + "10baseT/Full", + "100baseT/Half", + "100baseT/Full", + "1000baseT/Full" + ], + "advertised_link_modes": [ + "10baseT/Half", + "10baseT/Full", + "100baseT/Half", + "100baseT/Full", + "1000baseT/Full" + ], + "current_message_level": [ + "0x00000007 (7)", + "drv probe link" + ], + "speed_bps": 1000000000 + } + + $ ethtool --module-info enp0s3 | jc --ethtool -p + { + "identifier": "0x03 (SFP)", + "extended_identifier": "0x04 (GBIC/SFP defined by 2-wire interface ID)", + "connector": "0x21 (Copper pigtail)", + "transceiver_codes": "0x01 0x00 0x00 0x04 0x00 0x04 0x80 0xd5 0x00", + "transceiver_type": [ + "Infiniband: 1X Copper Passive", + "Ethernet: 1000BASE-CX", + "Passive Cable", + "FC: Twin Axial Pair (TW)", + "FC: 1200 MBytes/sec", + "FC: 800 MBytes/sec", + "FC: 400 MBytes/sec", + "FC: 200 MBytes/sec", + "FC: 100 MBytes/sec" + ], + "encoding": "0x00 (unspecified)", + "br_nominal": "10300MBd", + "rate_identifier": "0x00 (unspecified)", + "length_smf_km": "0km", + "length_smf": "0m", + "length_50um": "0m", + "length_62_5um": "0m", + "length_copper": "2m", + "length_om3": "0m", + "passive_cu_cmplnce": "0x01 (SFF-8431 appendix E) [SFF-8472 rev10.4 only]", + "vendor_name": "UbiquitiNetworks", + "vendor_oui": "00:40:20", + "vendor_pn": "UDC-2", + "vendor_rev": "", + "option_values": "0x00 0x00", + "br_margin_max": "0%", + "br_margin_min": "0%" + } +""" +import re +from typing import List, Dict +from jc.jc_types import JSONDictType +import jc.utils + + +class info(): + """Provides parser metadata (version, author, etc.)""" + version = '1.0' + description = '`ethtool` command parser' + author = 'Kelly Brazil' + author_email = 'kellyjonbrazil@gmail.com' + compatible = ['linux'] + tags = ['command'] + magic_commands = ['ethtool'] + + +__version__ = info.version + + +def _process(proc_data: JSONDictType) -> JSONDictType: + """ + 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. + """ + bool_list = {'supports_auto_negotiation', 'advertised_auto_negotiation', + 'auto_negotiation', 'link_detected', 'advertised_pause_frame_use'} + + if 'speed' in proc_data: + proc_data['speed_bps'] = jc.utils.convert_size_to_int(proc_data['speed']) + + for key in bool_list: + if key in proc_data: + proc_data[key] = jc.utils.convert_to_bool(proc_data[key]) + + # find and convert units + # "0.0468 mW / -13.30 dBm" or "-40.00 degrees C / -40.00 degrees F" + degrees_re = re.compile(r'(?P.*?) degrees C \/ (?P.*?) degrees F') + power_re = re.compile(r'(?P.*?) mW \/ (?P.*?) dBm') + + for key, val in proc_data.copy().items(): + if isinstance(val, str): + degrees_match = re.match(degrees_re, val) + if degrees_match: + degrees_dict = degrees_match.groupdict() + proc_data[key + '_celsius'] = float(degrees_dict['deg_c']) + proc_data[key + '_farenheit'] = float(degrees_dict['deg_f']) + del proc_data[key] + continue + + power_match = re.match(power_re, val) + if power_match: + power_dict = power_match.groupdict() + proc_data[key + '_mw'] = float(power_dict['pow_mw']) + proc_data[key + '_dbm'] = float(power_dict['pow_dbm']) + del proc_data[key] + continue + + if val.endswith(' V'): + proc_data[key + '_v'] = jc.utils.convert_to_float(val) + del proc_data[key] + continue + + if val.endswith(' mA'): + proc_data[key + '_ma'] = jc.utils.convert_to_float(val) + del proc_data[key] + continue + + return proc_data + + +def _parse_default(data: str) -> JSONDictType: + raw_output: Dict = {} + supported_ports: List[str] = [] + supported_link_modes: List[str] = [] + supported_fec_modes: List[str] = [] + advertised_link_modes: List[str] = [] + advertised_fec_modes: List[str] = [] + current_message_level: List[str] = [] + mode: str = '' # supported_link_modes, supported_fec_modes, advertised_link_modes, + # advertised_fec_modes, current_message_level + + for line in filter(None, data.splitlines()): + + if line.startswith('Settings for '): + raw_output['name'] = line.split()[2][:-1] + continue + + data_line = line.replace('\t', ' ') + if not data_line.startswith(' '): # 9 spaces + mode = '' + + if 'Supported ports:' in line: + _, val = line.split(':', maxsplit=1) + val = val.strip()[1:-1] + val_list = val.split() + supported_ports.extend(val_list) + continue + + if 'Supported link modes:' in line and 'Not reported' not in line: + _, val = line.split(':', maxsplit=1) + val = val.strip() + val_list = val.split() + supported_link_modes.extend(val_list) + mode = 'supported_link_modes' + continue + + if 'Supported FEC modes:' in line and 'Not reported' not in line: + _, val = line.split(':', maxsplit=1) + val = val.strip() + val_list = val.split() + supported_fec_modes.extend(val_list) + mode = 'supported_fec_modes' + continue + + if 'Advertised link modes:' in line and 'Not reported' not in line: + _, val = line.split(':', maxsplit=1) + val = val.strip() + val_list = val.split() + advertised_link_modes.extend(val_list) + mode = 'advertised_link_modes' + continue + + if 'Advertised FEC modes:' in line and 'Not reported' not in line: + _, val = line.split(':', maxsplit=1) + val = val.strip() + val_list = val.split() + advertised_fec_modes.extend(val_list) + mode = 'advertised_fec_modes' + continue + + if 'Current message level:' in line: + _, val = line.split(':', maxsplit=1) + current_message_level.append(val.strip()) + mode = 'current_message_level' + continue + + if mode == 'supported_link_modes': + val = line.strip() + val_list = val.split() + supported_link_modes.extend(val_list) + continue + + if mode == 'supported_fec_modes': + val = line.strip() + val_list = val.split() + supported_fec_modes.extend(val_list) + continue + + if mode == 'advertised_link_modes': + val = line.strip() + val_list = val.split() + advertised_link_modes.extend(val_list) + continue + + if mode == 'advertised_fec_modes': + val = line.strip() + val_list = val.split() + advertised_fec_modes.extend(val_list) + continue + + if mode == 'current_message_level': + current_message_level.append(line.strip()) + continue + + key, val = line.split(':', maxsplit=1) + key = jc.utils.normalize_key(key) + val = val.strip() + raw_output[key] = val + + list_vals = [ + (supported_ports, 'supported_ports'), + (supported_link_modes, 'supported_link_modes'), + (supported_fec_modes, 'supported_fec_modes'), + (advertised_link_modes, 'advertised_link_modes'), + (advertised_fec_modes, 'advertised_fec_modes'), + (current_message_level, 'current_message_level') + ] + + for obj_list, obj_key in list_vals: + if raw_output.get(obj_key, '').lower() == 'not reported': + raw_output[obj_key] = [] + else: + if obj_list: + raw_output[obj_key] = obj_list + + return raw_output + + +def _parse_module_info(data: str) -> JSONDictType: + raw_output: Dict = {} + previous_key: str = '' + multi_value: List[str] = [] + + for line in filter(None, data.splitlines()): + key, val = line.strip().split(':', maxsplit=1) + key = jc.utils.normalize_key(key) + val = val.strip() + + if key == previous_key: + multi_value.append(val) + continue + + else: + if len(multi_value) > 1: + raw_output[previous_key] = multi_value + multi_value = [] + multi_value.append(val) + previous_key = key + continue + + elif len(multi_value) == 1: + raw_output[previous_key] = multi_value[0] + multi_value = [] + multi_value.append(val) + previous_key = key + continue + + else: + raw_output[previous_key] = '' + multi_value.append(val) + previous_key = key + continue + + if len(multi_value) > 1: + raw_output[key] = multi_value + + elif len(multi_value) == 1: + raw_output[key] = multi_value[0] + + else: + raw_output[key] = '' + + if '' in raw_output: + del raw_output[''] + + return raw_output + + +def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType: + """ + 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: Dict = {} + + if jc.utils.has_data(data): + + if data.strip().startswith('Settings for '): + raw_output = _parse_default(data) + + elif data.strip().startswith('Identifier '): + raw_output = _parse_module_info(data) + + return raw_output if raw else _process(raw_output) diff --git a/jc/parsers/file.py b/jc/parsers/file.py index 264ccb3ad..227028250 100644 --- a/jc/parsers/file.py +++ b/jc/parsers/file.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `file` command output parser +r"""jc - JSON Convert `file` command output parser Usage (cli): diff --git a/jc/parsers/find.py b/jc/parsers/find.py index 059cf30dd..087995ac1 100644 --- a/jc/parsers/find.py +++ b/jc/parsers/find.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `find` command output parser +r"""jc - JSON Convert `find` command output parser This parser returns a list of objects by default and a list of strings if the `--raw` option is used. diff --git a/jc/parsers/findmnt.py b/jc/parsers/findmnt.py index 4d18c4f1f..a8113c6cf 100644 --- a/jc/parsers/findmnt.py +++ b/jc/parsers/findmnt.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `findmnt` command output parser +r"""jc - JSON Convert `findmnt` command output parser Supports `-a`, `-l`, or no `findmnt` options. diff --git a/jc/parsers/finger.py b/jc/parsers/finger.py index f46df76e5..8b680279c 100644 --- a/jc/parsers/finger.py +++ b/jc/parsers/finger.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `finger` command output parser +r"""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 8188e5179..afcb2a069 100644 --- a/jc/parsers/foo.py +++ b/jc/parsers/foo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `foo` command output parser +r"""jc - JSON Convert `foo` command output parser <> diff --git a/jc/parsers/foo_s.py b/jc/parsers/foo_s.py index 5d62c62f2..145871eb4 100644 --- a/jc/parsers/foo_s.py +++ b/jc/parsers/foo_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `foo` command output streaming parser +r"""jc - JSON Convert `foo` command output streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/free.py b/jc/parsers/free.py index b8d0b187e..55405f4cd 100644 --- a/jc/parsers/free.py +++ b/jc/parsers/free.py @@ -1,4 +1,6 @@ -"""jc - JSON Convert `free` command output parser +r"""jc - JSON Convert `free` command output parser + +Values are normalized to bytes when using `free -h`. Usage (cli): @@ -17,13 +19,13 @@ [ { - "type": string, - "total": integer, - "used": integer, - "free": integer, - "shared": integer, - "buff_cache": integer, - "available": integer + "type": string, + "total": integer, + "used": integer, + "free": integer, + "shared": integer, + "buff_cache": integer, + "available": integer } ] @@ -73,7 +75,7 @@ class info(): """Provides parser metadata (version, author, etc.)""" - version = '1.7' + version = '1.8' description = '`free` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -102,7 +104,7 @@ def _process(proc_data): for entry in proc_data: for key in entry: if key in int_list: - entry[key] = jc.utils.convert_to_int(entry[key]) + entry[key] = jc.utils.convert_size_to_int(entry[key]) return proc_data @@ -138,7 +140,4 @@ def parse(data, raw=False, quiet=False): for entry in raw_output: entry['type'] = entry['type'].rstrip(':') - if raw: - return raw_output - else: - return _process(raw_output) + return raw_output if raw else _process(raw_output) diff --git a/jc/parsers/fstab.py b/jc/parsers/fstab.py index c5618696d..242425147 100644 --- a/jc/parsers/fstab.py +++ b/jc/parsers/fstab.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `fstab` file parser +r"""jc - JSON Convert `fstab` file parser Usage (cli): diff --git a/jc/parsers/git_log.py b/jc/parsers/git_log.py index 8ad91dbda..e1f0ea490 100644 --- a/jc/parsers/git_log.py +++ b/jc/parsers/git_log.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `git log` command output parser +r"""jc - JSON Convert `git log` command output parser Can be used with the following format options: - `oneline` diff --git a/jc/parsers/git_log_s.py b/jc/parsers/git_log_s.py index e7b02a5a9..cb39e8b29 100644 --- a/jc/parsers/git_log_s.py +++ b/jc/parsers/git_log_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `git log` command output streaming parser +r"""jc - JSON Convert `git log` command output streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/git_ls_remote.py b/jc/parsers/git_ls_remote.py index e05c8993f..8af4aa498 100644 --- a/jc/parsers/git_ls_remote.py +++ b/jc/parsers/git_ls_remote.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `git ls-remote` command output parser +r"""jc - JSON Convert `git ls-remote` command output parser This parser outputs two schemas: diff --git a/jc/parsers/gpg.py b/jc/parsers/gpg.py index 21eb32fa5..2d8502bbb 100644 --- a/jc/parsers/gpg.py +++ b/jc/parsers/gpg.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `gpg --with-colons` command output parser +r"""jc - JSON Convert `gpg --with-colons` command output parser Usage (cli): diff --git a/jc/parsers/group.py b/jc/parsers/group.py index 6bf65f523..13aeaf5e0 100644 --- a/jc/parsers/group.py +++ b/jc/parsers/group.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/etc/group` file parser +r"""jc - JSON Convert `/etc/group` file parser Usage (cli): diff --git a/jc/parsers/gshadow.py b/jc/parsers/gshadow.py index b2b87dea9..b5d50ca11 100644 --- a/jc/parsers/gshadow.py +++ b/jc/parsers/gshadow.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/etc/gshadow` file parser +r"""jc - JSON Convert `/etc/gshadow` file parser Usage (cli): diff --git a/jc/parsers/hash.py b/jc/parsers/hash.py index c88b87a9d..8e79c78d5 100644 --- a/jc/parsers/hash.py +++ b/jc/parsers/hash.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `hash` command output parser +r"""jc - JSON Convert `hash` command output parser Usage (cli): diff --git a/jc/parsers/hashsum.py b/jc/parsers/hashsum.py index be47b7426..d86339974 100644 --- a/jc/parsers/hashsum.py +++ b/jc/parsers/hashsum.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `hash sum` command output parser +r"""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 7b7691729..15820eabd 100644 --- a/jc/parsers/hciconfig.py +++ b/jc/parsers/hciconfig.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `hciconfig` command output parser +r"""jc - JSON Convert `hciconfig` command output parser Usage (cli): diff --git a/jc/parsers/history.py b/jc/parsers/history.py index d07d09e01..dce1ee649 100644 --- a/jc/parsers/history.py +++ b/jc/parsers/history.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `history` command output parser +r"""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/host.py b/jc/parsers/host.py index a026a0b51..40a878aca 100644 --- a/jc/parsers/host.py +++ b/jc/parsers/host.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `host` command output parser +r"""jc - JSON Convert `host` command output parser Supports parsing of the most commonly used RR types (A, AAAA, MX, TXT) diff --git a/jc/parsers/hosts.py b/jc/parsers/hosts.py index bb5dd009f..b9b2efff2 100644 --- a/jc/parsers/hosts.py +++ b/jc/parsers/hosts.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/etc/hosts` file parser +r"""jc - JSON Convert `/etc/hosts` file parser Usage (cli): diff --git a/jc/parsers/http_headers.py b/jc/parsers/http_headers.py index e1de8c3ea..69ffdb4ba 100644 --- a/jc/parsers/http_headers.py +++ b/jc/parsers/http_headers.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert HTTP headers parser +r"""jc - JSON Convert HTTP headers parser Converts HTTP request and response headers into a list of dictionaries. Well-known headers are processed to allow multiple instances which are diff --git a/jc/parsers/id.py b/jc/parsers/id.py index d77961a41..da3d261f5 100644 --- a/jc/parsers/id.py +++ b/jc/parsers/id.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `id` command output parser +r"""jc - JSON Convert `id` command output parser Usage (cli): diff --git a/jc/parsers/ifconfig.py b/jc/parsers/ifconfig.py index 6192d699d..d24b91470 100644 --- a/jc/parsers/ifconfig.py +++ b/jc/parsers/ifconfig.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ifconfig` command output parser +r"""jc - JSON Convert `ifconfig` command output parser No `ifconfig` options are supported. diff --git a/jc/parsers/iftop.py b/jc/parsers/iftop.py index 3439507c5..ca1fe556e 100644 --- a/jc/parsers/iftop.py +++ b/jc/parsers/iftop.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `iftop` command output parser +r"""jc - JSON Convert `iftop` command output parser Usage (cli): diff --git a/jc/parsers/ini.py b/jc/parsers/ini.py index 21ce3cf4a..6455e3242 100644 --- a/jc/parsers/ini.py +++ b/jc/parsers/ini.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert INI file parser +r"""jc - JSON Convert INI file parser Parses standard INI files. diff --git a/jc/parsers/ini_dup.py b/jc/parsers/ini_dup.py index bb94ea437..f8dbd148e 100644 --- a/jc/parsers/ini_dup.py +++ b/jc/parsers/ini_dup.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert INI with duplicate key file parser +r"""jc - JSON Convert INI with duplicate key file parser Parses standard INI files and preserves duplicate values. All values are contained in lists/arrays. diff --git a/jc/parsers/iostat.py b/jc/parsers/iostat.py index 0a4b41076..746759805 100644 --- a/jc/parsers/iostat.py +++ b/jc/parsers/iostat.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `iostat` command output parser +r"""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 c2f5921fe..3fa92a533 100644 --- a/jc/parsers/iostat_s.py +++ b/jc/parsers/iostat_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `iostat` command output streaming parser +r"""jc - JSON Convert `iostat` command output streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/ip_address.py b/jc/parsers/ip_address.py index 991159c14..7e6b37cb4 100644 --- a/jc/parsers/ip_address.py +++ b/jc/parsers/ip_address.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert IP Address string parser +r"""jc - JSON Convert IP Address string parser Accepts standard and integer IP address notation for both IPv4 and IPv6 addresses. CIDR subnet mask and Scope ID is also allowed for standard diff --git a/jc/parsers/ip_route.py b/jc/parsers/ip_route.py index 0396dd329..eedd94226 100644 --- a/jc/parsers/ip_route.py +++ b/jc/parsers/ip_route.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ip route` command output parser +r"""jc - JSON Convert `ip route` command output parser Usage (cli): diff --git a/jc/parsers/iptables.py b/jc/parsers/iptables.py index 893a04768..dcaab5ebb 100644 --- a/jc/parsers/iptables.py +++ b/jc/parsers/iptables.py @@ -1,6 +1,6 @@ -"""jc - JSON Convert `iptables` command output parser +r"""jc - JSON Convert `iptables` command output parser -Supports `-vLn` and `--line-numbers` for all tables. +Supports `-vLnx` and `--line-numbers` for all tables. Usage (cli): @@ -163,7 +163,7 @@ class info(): """Provides parser metadata (version, author, etc.)""" - version = '1.10' + version = '1.11' description = '`iptables` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -247,7 +247,10 @@ def parse(data, raw=False, quiet=False): continue - elif line.startswith('target') or line.find('pkts') == 1 or line.startswith('num'): + elif line.startswith('target') or \ + (line.find('pkts') >= 1 and line.find('pkts') <= 5) or \ + line.startswith('num'): + headers = [h for h in ' '.join(line.lower().strip().split()).split() if h] headers.append("options") diff --git a/jc/parsers/iw_scan.py b/jc/parsers/iw_scan.py index 8b936807e..90e008af3 100644 --- a/jc/parsers/iw_scan.py +++ b/jc/parsers/iw_scan.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `iw dev scan` command output parser +r"""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/iwconfig.py b/jc/parsers/iwconfig.py index d4b7d46c4..e4bd43bf9 100644 --- a/jc/parsers/iwconfig.py +++ b/jc/parsers/iwconfig.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `iwconfig` command output parser +r"""jc - JSON Convert `iwconfig` command output parser No `iwconfig` options are supported. @@ -85,7 +85,7 @@ class info(): """Provides parser metadata (version, author, etc.)""" - version = '1.1' + version = '1.2' description = '`iwconfig` command parser' author = 'Thomas Vincent' author_email = 'vrince@gmail.com' @@ -146,7 +146,7 @@ def parse( raw_output: List[Dict] = [] - re_interface = re.compile(r'^(?P[a-zA-Z0-9:._\-]+)\s+(?P([a-zA-Z0-9]+\s)*[a-zA-Z0-9.]+)\s+ESSID:\"(?P[a-zA-Z0-9:._\s\-]+)\"') + re_interface = re.compile(r'^(?P[a-zA-Z0-9:._\-]+)\s+(?P([a-zA-Z0-9]+\s)*[a-zA-Z0-9.]+)\s+ESSID:\"(?P[a-zA-Z0-9:._\s\-^!#%&\'()*,/:;<>@`{|}~]+)\"') re_mode = re.compile(r'Mode:(?P\w+)') re_frequency = re.compile(r'Frequency:(?P[0-9.]+)\s(?P\w+)') re_access_point = re.compile(r'Access Point:\s*(?P[0-9A-F:]+)') diff --git a/jc/parsers/jar_manifest.py b/jc/parsers/jar_manifest.py index d54a2901b..235e47388 100644 --- a/jc/parsers/jar_manifest.py +++ b/jc/parsers/jar_manifest.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Java `MANIFEST.MF` file parser +r"""jc - JSON Convert Java `MANIFEST.MF` file parser Usage (cli): diff --git a/jc/parsers/jobs.py b/jc/parsers/jobs.py index 0befa601a..7815ab59e 100644 --- a/jc/parsers/jobs.py +++ b/jc/parsers/jobs.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `jobs` command output parser +r"""jc - JSON Convert `jobs` command output parser Also supports the `-l` option. diff --git a/jc/parsers/jwt.py b/jc/parsers/jwt.py index c1658cfaa..8356d9ea0 100644 --- a/jc/parsers/jwt.py +++ b/jc/parsers/jwt.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert JWT string parser +r"""jc - JSON Convert JWT string parser > Note: `jc` will not check the integrity of the JWT payload. diff --git a/jc/parsers/kv.py b/jc/parsers/kv.py index de3e34406..4fe3156f8 100644 --- a/jc/parsers/kv.py +++ b/jc/parsers/kv.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `Key/Value` file and string parser +r"""jc - JSON Convert `Key/Value` file and string parser Supports files containing simple key/value pairs. @@ -56,7 +56,7 @@ class info(): """Provides parser metadata (version, author, etc.)""" - version = '2.1' + version = '2.2' description = 'Key/Value file and string parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -84,4 +84,5 @@ def parse(data, raw=False, quiet=False): """ # This parser is an alias of ini.py ini.info = info # type: ignore + ini.__name__ = __name__ return ini.parse(data, raw, quiet) diff --git a/jc/parsers/kv_dup.py b/jc/parsers/kv_dup.py index 331c4c73b..417a38059 100644 --- a/jc/parsers/kv_dup.py +++ b/jc/parsers/kv_dup.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `Key/Value` with duplicate key file and string parser +r"""jc - JSON Convert `Key/Value` with duplicate key file and string parser Supports files containing simple key/value pairs and preserves duplicate values. All values are contained in lists/arrays. @@ -63,7 +63,7 @@ class info(): """Provides parser metadata (version, author, etc.)""" - version = '1.0' + version = '1.1' description = 'Key/Value with duplicate key file and string parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -91,4 +91,5 @@ def parse(data, raw=False, quiet=False): """ # This parser is an alias of ini_dup.py ini_dup.info = info # type: ignore + ini_dup.__name__ = __name__ return ini_dup.parse(data, raw, quiet) diff --git a/jc/parsers/last.py b/jc/parsers/last.py index 8683e3d17..821f8eb9c 100644 --- a/jc/parsers/last.py +++ b/jc/parsers/last.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `last` and `lastb` command output parser +r"""jc - JSON Convert `last` and `lastb` command output parser Supports `-w`, `-F`, and `-x` options. @@ -98,7 +98,6 @@ }, ... ] - """ import re import jc.utils diff --git a/jc/parsers/ls.py b/jc/parsers/ls.py index 85a69e422..4be45e897 100644 --- a/jc/parsers/ls.py +++ b/jc/parsers/ls.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ls` and `vdir` command output parser +r"""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 8cf2213d8..6f4b8e09d 100644 --- a/jc/parsers/ls_s.py +++ b/jc/parsers/ls_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ls` and `vdir` command output streaming parser +r"""jc - JSON Convert `ls` and `vdir` command output streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/lsattr.py b/jc/parsers/lsattr.py index 30d609454..dc3a3794c 100644 --- a/jc/parsers/lsattr.py +++ b/jc/parsers/lsattr.py @@ -1,162 +1,162 @@ -"""jc - JSON Convert `lsattr` command output parser - -Usage (cli): - - $ lsattr | jc --lsattr - -or - - $ jc lsattr - -Usage (module): - - import jc - result = jc.parse('lsattr', lsattr_command_output) - -Schema: - -Information from https://github.com/mirror/busybox/blob/2d4a3d9e6c1493a9520b907e07a41aca90cdfd94/e2fsprogs/e2fs_lib.c#L40 -used to define field names - - [ - { - "file": string, - "compressed_file": Optional[boolean], - "compressed_dirty_file": Optional[boolean], - "compression_raw_access": Optional[boolean], - "secure_deletion": Optional[boolean], - "undelete": Optional[boolean], - "synchronous_updates": Optional[boolean], - "synchronous_directory_updates": Optional[boolean], - "immutable": Optional[boolean], - "append_only": Optional[boolean], - "no_dump": Optional[boolean], - "no_atime": Optional[boolean], - "compression_requested": Optional[boolean], - "encrypted": Optional[boolean], - "journaled_data": Optional[boolean], - "indexed_directory": Optional[boolean], - "no_tailmerging": Optional[boolean], - "top_of_directory_hierarchies": Optional[boolean], - "extents": Optional[boolean], - "no_cow": Optional[boolean], - "casefold": Optional[boolean], - "inline_data": Optional[boolean], - "project_hierarchy": Optional[boolean], - "verity": Optional[boolean], - } - ] - -Examples: - - $ sudo lsattr /etc/passwd | jc --lsattr - [ - { - "file": "/etc/passwd", - "extents": true - } - ] -""" -from typing import List, Dict -from jc.jc_types import JSONDictType -import jc.utils - - -class info(): - """Provides parser metadata (version, author, etc.)""" - version = '1.0' - description = '`lsattr` command parser' - author = 'Mark Rotner' - author_email = 'rotner.mr@gmail.com' - compatible = ['linux'] - magic_commands = ['lsattr'] - tags = ['command'] - - -__version__ = info.version - - -ERROR_PREFIX = "lsattr:" - -# https://github.com/mirror/busybox/blob/2d4a3d9e6c1493a9520b907e07a41aca90cdfd94/e2fsprogs/e2fs_lib.c#L40 -# https://github.com/landley/toybox/blob/f1682dc79fd75f64042b5438918fe5a507977e1c/toys/other/lsattr.c#L97 -ATTRIBUTES = { - "B": "compressed_file", - "Z": "compressed_dirty_file", - "X": "compression_raw_access", - "s": "secure_deletion", - "u": "undelete", - "S": "synchronous_updates", - "D": "synchronous_directory_updates", - "i": "immutable", - "a": "append_only", - "d": "no_dump", - "A": "no_atime", - "c": "compression_requested", - "E": "encrypted", - "j": "journaled_data", - "I": "indexed_directory", - "t": "no_tailmerging", - "T": "top_of_directory_hierarchies", - "e": "extents", - "C": "no_cow", - "F": "casefold", - "N": "inline_data", - "P": "project_hierarchy", - "V": "verity", -} - - -def parse( - data: str, - raw: bool = False, - quiet: bool = False -) -> List[JSONDictType]: - """ - Main text parsing function - - Parameters: - - data: (string) text data to parse - 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) - - output: List = [] - - cleandata = list(filter(None, data.splitlines())) - - if not jc.utils.has_data(data): - return output - - for line in cleandata: - # -R flag returns the output in the format: - # Folder: - # attributes file_in_folder - if line.endswith(':'): - continue - - # lsattr: Operation not supported .... - if line.startswith(ERROR_PREFIX): - continue - - line_output: Dict = {} - - # attributes file - # --------------e----- /etc/passwd - attributes, file = line.split() - line_output['file'] = file - for attribute in list(attributes): - attribute_key = ATTRIBUTES.get(attribute) - if attribute_key: - line_output[attribute_key] = True - - if line_output: - output.append(line_output) - - return output +r"""jc - JSON Convert `lsattr` command output parser + +Usage (cli): + + $ lsattr | jc --lsattr + +or + + $ jc lsattr + +Usage (module): + + import jc + result = jc.parse('lsattr', lsattr_command_output) + +Schema: + +Information from https://github.com/mirror/busybox/blob/2d4a3d9e6c1493a9520b907e07a41aca90cdfd94/e2fsprogs/e2fs_lib.c#L40 +used to define field names + + [ + { + "file": string, + "compressed_file": Optional[boolean], + "compressed_dirty_file": Optional[boolean], + "compression_raw_access": Optional[boolean], + "secure_deletion": Optional[boolean], + "undelete": Optional[boolean], + "synchronous_updates": Optional[boolean], + "synchronous_directory_updates": Optional[boolean], + "immutable": Optional[boolean], + "append_only": Optional[boolean], + "no_dump": Optional[boolean], + "no_atime": Optional[boolean], + "compression_requested": Optional[boolean], + "encrypted": Optional[boolean], + "journaled_data": Optional[boolean], + "indexed_directory": Optional[boolean], + "no_tailmerging": Optional[boolean], + "top_of_directory_hierarchies": Optional[boolean], + "extents": Optional[boolean], + "no_cow": Optional[boolean], + "casefold": Optional[boolean], + "inline_data": Optional[boolean], + "project_hierarchy": Optional[boolean], + "verity": Optional[boolean], + } + ] + +Examples: + + $ sudo lsattr /etc/passwd | jc --lsattr + [ + { + "file": "/etc/passwd", + "extents": true + } + ] +""" +from typing import List, Dict +from jc.jc_types import JSONDictType +import jc.utils + + +class info(): + """Provides parser metadata (version, author, etc.)""" + version = '1.0' + description = '`lsattr` command parser' + author = 'Mark Rotner' + author_email = 'rotner.mr@gmail.com' + compatible = ['linux'] + magic_commands = ['lsattr'] + tags = ['command'] + + +__version__ = info.version + + +ERROR_PREFIX = "lsattr:" + +# https://github.com/mirror/busybox/blob/2d4a3d9e6c1493a9520b907e07a41aca90cdfd94/e2fsprogs/e2fs_lib.c#L40 +# https://github.com/landley/toybox/blob/f1682dc79fd75f64042b5438918fe5a507977e1c/toys/other/lsattr.c#L97 +ATTRIBUTES = { + "B": "compressed_file", + "Z": "compressed_dirty_file", + "X": "compression_raw_access", + "s": "secure_deletion", + "u": "undelete", + "S": "synchronous_updates", + "D": "synchronous_directory_updates", + "i": "immutable", + "a": "append_only", + "d": "no_dump", + "A": "no_atime", + "c": "compression_requested", + "E": "encrypted", + "j": "journaled_data", + "I": "indexed_directory", + "t": "no_tailmerging", + "T": "top_of_directory_hierarchies", + "e": "extents", + "C": "no_cow", + "F": "casefold", + "N": "inline_data", + "P": "project_hierarchy", + "V": "verity", +} + + +def parse( + data: str, + raw: bool = False, + quiet: bool = False +) -> List[JSONDictType]: + """ + Main text parsing function + + Parameters: + + data: (string) text data to parse + 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) + + output: List = [] + + cleandata = list(filter(None, data.splitlines())) + + if not jc.utils.has_data(data): + return output + + for line in cleandata: + # -R flag returns the output in the format: + # Folder: + # attributes file_in_folder + if line.endswith(':'): + continue + + # lsattr: Operation not supported .... + if line.startswith(ERROR_PREFIX): + continue + + line_output: Dict = {} + + # attributes file + # --------------e----- /etc/passwd + attributes, file = line.split() + line_output['file'] = file + for attribute in list(attributes): + attribute_key = ATTRIBUTES.get(attribute) + if attribute_key: + line_output[attribute_key] = True + + if line_output: + output.append(line_output) + + return output diff --git a/jc/parsers/lsb_release.py b/jc/parsers/lsb_release.py index 7d8198d97..ed7540fa6 100644 --- a/jc/parsers/lsb_release.py +++ b/jc/parsers/lsb_release.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `lsb_release` command parser +r"""jc - JSON Convert `lsb_release` command parser This parser is an alias to the Key/Value parser (`--kv`). @@ -36,7 +36,7 @@ class info(): """Provides parser metadata (version, author, etc.)""" - version = '1.1' + version = '1.2' description = '`lsb_release` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -69,4 +69,5 @@ def parse( """ # This parser is an alias of ini.py ini.info = info # type: ignore + ini.__name__ = __name__ return ini.parse(data, raw, quiet) diff --git a/jc/parsers/lsblk.py b/jc/parsers/lsblk.py index 7276711c1..f25e0e02d 100644 --- a/jc/parsers/lsblk.py +++ b/jc/parsers/lsblk.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `lsblk` command output parser +r"""jc - JSON Convert `lsblk` command output parser Usage (cli): diff --git a/jc/parsers/lsmod.py b/jc/parsers/lsmod.py index b4b65d05d..e794a8afd 100644 --- a/jc/parsers/lsmod.py +++ b/jc/parsers/lsmod.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `lsmod` command output parser +r"""jc - JSON Convert `lsmod` command output parser Usage (cli): diff --git a/jc/parsers/lsof.py b/jc/parsers/lsof.py index 0fc434ae5..03abbdc0a 100644 --- a/jc/parsers/lsof.py +++ b/jc/parsers/lsof.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `lsof` command output parser +r"""jc - JSON Convert `lsof` command output parser Usage (cli): diff --git a/jc/parsers/lspci.py b/jc/parsers/lspci.py index 771fe38a8..b47c38ebd 100644 --- a/jc/parsers/lspci.py +++ b/jc/parsers/lspci.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `lspci -mmv` command output parser +r"""jc - JSON Convert `lspci -mmv` command output parser This parser supports the following `lspci` options: - `-mmv` diff --git a/jc/parsers/lsusb.py b/jc/parsers/lsusb.py index 075c7fc0a..86ec6953a 100644 --- a/jc/parsers/lsusb.py +++ b/jc/parsers/lsusb.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `lsusb` command output parser +r"""jc - JSON Convert `lsusb` command output parser Supports the `-v` option or no options. diff --git a/jc/parsers/m3u.py b/jc/parsers/m3u.py index 76fbb4d3b..f5b0f5b1a 100644 --- a/jc/parsers/m3u.py +++ b/jc/parsers/m3u.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert M3U and M3U8 file parser +r"""jc - JSON Convert M3U and M3U8 file parser This parser will make a best-effort to parse extended field information. If the extended fields cannot be successfully parsed, then an `unparsed_info` diff --git a/jc/parsers/mdadm.py b/jc/parsers/mdadm.py index 852911aea..70744a30f 100644 --- a/jc/parsers/mdadm.py +++ b/jc/parsers/mdadm.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `mdadm` command output parser +r"""jc - JSON Convert `mdadm` command output parser Supports the `--query` and `--examine` options in `mdadm`. diff --git a/jc/parsers/mount.py b/jc/parsers/mount.py index 945ed81a6..c2297130e 100644 --- a/jc/parsers/mount.py +++ b/jc/parsers/mount.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `mount` command output parser +r"""jc - JSON Convert `mount` command output parser Usage (cli): diff --git a/jc/parsers/mpstat.py b/jc/parsers/mpstat.py index a89c940db..40184fc53 100644 --- a/jc/parsers/mpstat.py +++ b/jc/parsers/mpstat.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `mpstat` command output parser +r"""jc - JSON Convert `mpstat` command output parser > Note: Latest versions of `mpstat` support JSON output (v11.5.1+) diff --git a/jc/parsers/mpstat_s.py b/jc/parsers/mpstat_s.py index 3a746f2b9..c35493a79 100644 --- a/jc/parsers/mpstat_s.py +++ b/jc/parsers/mpstat_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `mpstat` command output streaming parser +r"""jc - JSON Convert `mpstat` command output streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/needrestart.py b/jc/parsers/needrestart.py new file mode 100644 index 000000000..c64f1cc20 --- /dev/null +++ b/jc/parsers/needrestart.py @@ -0,0 +1,190 @@ +r"""jc - JSON Convert `needrestart -b` command output parser + +Usage (cli): + + $ needrestart -b | jc --needrestart + +or + + $ jc needrestart -b + +Usage (module): + + import jc + result = jc.parse('needrestart', needrestart_command_output) + +Schema: + + { + "version": string, + "running_kernel_version": string, + "expected_kernel_version": string, + "kernel_status": integer, + "container": string, + "session": [ + string + ], + "service": [ + string + ], + "pid": [ + string + ] + } + +Examples: + + $ needrestart -b | jc --needrestart -p + { + "version": "2.1", + "running_kernel_version": "3.19.3-tl1+", + "expected_kernel_version": "3.19.3-tl1+", + "kernel_status": 1, + "container": "LXC web1", + "session": [ + "metabase @ user manager service", + "root @ session #28017" + ], + "service": [ + "systemd-journald.service", + "systemd-machined.service" + ] + } + + $ needrestart -b | jc --needrestart -p -r + { + "needrestart_ver": "2.1", + "needrestart_kcur": "3.19.3-tl1+", + "needrestart_kexp": "3.19.3-tl1+", + "needrestart_ksta": "1", + "needrestart_cont": "LXC web1", + "needrestart_sess": [ + "metabase @ user manager service", + "root @ session #28017" + ], + "needrestart_svc": [ + "systemd-journald.service", + "systemd-machined.service" + ] + } +""" +from typing import List, Dict +from jc.jc_types import JSONDictType +import jc.utils + + +class info(): + """Provides parser metadata (version, author, etc.)""" + version = '1.0' + description = '`needrestart -b` command parser' + author = 'Kelly Brazil' + author_email = 'kellyjonbrazil@gmail.com' + compatible = ['linux'] + tags = ['command'] + magic_commands = ['needrestart -b'] + + +__version__ = info.version + + +def _process(proc_data: JSONDictType) -> JSONDictType: + """ + 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. + """ + key_map = { + 'needrestart_ver': 'version', + 'needrestart_kcur': 'running_kernel_version', + 'needrestart_kexp': 'expected_kernel_version', + 'needrestart_ksta': 'kernel_status', + 'needrestart_svc': 'service', + 'needrestart_cont': 'container', + 'needrestart_sess': 'session', + 'needrestart_pid': 'pid' + } + + for key, val in proc_data.copy().items(): + if key == 'needrestart_ksta': + proc_data[key] = jc.utils.convert_to_int(val) + + if key in key_map: + proc_data[key_map[key]] = proc_data[key] + del proc_data[key] + + return proc_data + + +def parse( + data: str, + raw: bool = False, + quiet: bool = False +) -> JSONDictType: + """ + 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: + + Dictionary. Raw or processed structured data. + """ + jc.utils.compatibility(__name__, info.compatible, quiet) + jc.utils.input_type_check(data) + + raw_output: Dict = {} + sess_list: List[str] = [] + svc_list: List[str] = [] + pid_list: List[str] = [] + + if jc.utils.has_data(data): + + for line in filter(None, data.splitlines()): + + if any([ + line.startswith('NEEDRESTART-VER'), + line.startswith('NEEDRESTART-KCUR'), + line.startswith('NEEDRESTART-KEXP'), + line.startswith('NEEDRESTART-KSTA'), + line.startswith('NEEDRESTART-CONT') + ]): + key, val = line.split(':', maxsplit=1) + key = jc.utils.normalize_key(key) + raw_output[key] = val.strip() + continue + + if line.startswith('NEEDRESTART-SESS'): + _, val = line.split(':', maxsplit=1) + sess_list.append(val.strip()) + continue + + if line.startswith('NEEDRESTART-SVC'): + _, val = line.split(':', maxsplit=1) + svc_list.append(val.strip()) + continue + + if line.startswith('NEEDRESTART-PID'): + _, val = line.split(':', maxsplit=1) + pid_list.append(val.strip()) + continue + + if sess_list: + raw_output['needrestart_sess'] = sess_list + + if svc_list: + raw_output['needrestart_svc'] = svc_list + + if pid_list: + raw_output['needrestart_pid'] = pid_list + + return raw_output if raw else _process(raw_output) diff --git a/jc/parsers/netstat.py b/jc/parsers/netstat.py index df715541e..50c82b006 100644 --- a/jc/parsers/netstat.py +++ b/jc/parsers/netstat.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `netstat` command output parser +r"""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 eb610ea86..9eeb9e8d4 100644 --- a/jc/parsers/netstat_freebsd_osx.py +++ b/jc/parsers/netstat_freebsd_osx.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert FreeBSD and OSX netstat Parser""" +r"""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 322fcab86..222f2944d 100644 --- a/jc/parsers/netstat_linux.py +++ b/jc/parsers/netstat_linux.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Linux netstat Parser""" +r"""jc - JSON Convert Linux netstat Parser""" import string diff --git a/jc/parsers/netstat_windows.py b/jc/parsers/netstat_windows.py index 835bc1635..a14f57d8c 100644 --- a/jc/parsers/netstat_windows.py +++ b/jc/parsers/netstat_windows.py @@ -1,4 +1,4 @@ -""" +r""" jc - JSON Convert Windows `netstat` command output parser """ diff --git a/jc/parsers/nmcli.py b/jc/parsers/nmcli.py index 25572eb9d..4779725a0 100644 --- a/jc/parsers/nmcli.py +++ b/jc/parsers/nmcli.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `nmcli` command output parser +r"""jc - JSON Convert `nmcli` command output parser Supports the following `nmcli` subcommands: - `nmcli general` diff --git a/jc/parsers/nsd_control.py b/jc/parsers/nsd_control.py index 55ef7bd21..fd80e9501 100644 --- a/jc/parsers/nsd_control.py +++ b/jc/parsers/nsd_control.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `nsd-control` command output parser +r"""jc - JSON Convert `nsd-control` command output parser Usage (cli): @@ -58,7 +58,6 @@ } } ] - """ from typing import List, Dict import jc.utils diff --git a/jc/parsers/ntpq.py b/jc/parsers/ntpq.py index ab5740e95..fc75b65f3 100644 --- a/jc/parsers/ntpq.py +++ b/jc/parsers/ntpq.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ntpq -p` command output parser +r"""jc - JSON Convert `ntpq -p` command output parser Usage (cli): diff --git a/jc/parsers/openvpn.py b/jc/parsers/openvpn.py index 2aa3f1ad2..2917024fa 100644 --- a/jc/parsers/openvpn.py +++ b/jc/parsers/openvpn.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert openvpn-status.log file parser +r"""jc - JSON Convert openvpn-status.log file parser The `*_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/os_prober.py b/jc/parsers/os_prober.py index 94de1f5f4..a97f15db6 100644 --- a/jc/parsers/os_prober.py +++ b/jc/parsers/os_prober.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `os-prober` command output parser +r"""jc - JSON Convert `os-prober` command output parser Usage (cli): diff --git a/jc/parsers/os_release.py b/jc/parsers/os_release.py index d3797b372..2cbf1b63d 100644 --- a/jc/parsers/os_release.py +++ b/jc/parsers/os_release.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/etc/os-release` file parser +r"""jc - JSON Convert `/etc/os-release` file parser This parser is an alias to the Key/Value parser (`--kv`). @@ -61,7 +61,7 @@ class info(): """Provides parser metadata (version, author, etc.)""" - version = '1.1' + version = '1.2' description = '`/etc/os-release` file parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -93,4 +93,5 @@ def parse( """ # This parser is an alias of ini.py ini.info = info # type: ignore + ini.__name__ = __name__ return ini.parse(data, raw, quiet) diff --git a/jc/parsers/passwd.py b/jc/parsers/passwd.py index 523e5d52e..3ed407351 100644 --- a/jc/parsers/passwd.py +++ b/jc/parsers/passwd.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/etc/passwd` file Parser +r"""jc - JSON Convert `/etc/passwd` file Parser Usage (cli): diff --git a/jc/parsers/path.py b/jc/parsers/path.py index 9596bb093..c556bd9f7 100644 --- a/jc/parsers/path.py +++ b/jc/parsers/path.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert POSIX path string parser +r"""jc - JSON Convert POSIX path string parser Parse a POSIX path. diff --git a/jc/parsers/path_list.py b/jc/parsers/path_list.py index 09095ed50..61763187f 100644 --- a/jc/parsers/path_list.py +++ b/jc/parsers/path_list.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert POSIX path list string parser +r"""jc - JSON Convert POSIX path list string parser Parse a colon-separated POSIX path list, commonly found in environment variables. @@ -59,7 +59,6 @@ ] } ] - """ import jc.parsers.path as path diff --git a/jc/parsers/pci_ids.py b/jc/parsers/pci_ids.py index 2deb4031c..7d7bbba37 100644 --- a/jc/parsers/pci_ids.py +++ b/jc/parsers/pci_ids.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `pci.ids` file parser +r"""jc - JSON Convert `pci.ids` file parser This parser converts the pci.ids database file. diff --git a/jc/parsers/pgpass.py b/jc/parsers/pgpass.py index 409b2c2d2..02b0134ff 100644 --- a/jc/parsers/pgpass.py +++ b/jc/parsers/pgpass.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert PostgreSQL password file parser +r"""jc - JSON Convert PostgreSQL password file parser Usage (cli): diff --git a/jc/parsers/pidstat.py b/jc/parsers/pidstat.py index 29ac3aea9..db480e3d9 100644 --- a/jc/parsers/pidstat.py +++ b/jc/parsers/pidstat.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `pidstat -H` command output parser +r"""jc - JSON Convert `pidstat -H` command output parser Must use the `-H` (or `-h`, if `-H` is not available) option in `pidstat`. All other `pidstat` options are supported in combination with this option. diff --git a/jc/parsers/pidstat_s.py b/jc/parsers/pidstat_s.py index c347a13a2..3a4d6e3fd 100644 --- a/jc/parsers/pidstat_s.py +++ b/jc/parsers/pidstat_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `pidstat -H` command output streaming parser +r"""jc - JSON Convert `pidstat -H` command output streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/ping.py b/jc/parsers/ping.py index 624e6739d..6adf338bc 100644 --- a/jc/parsers/ping.py +++ b/jc/parsers/ping.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ping` command output parser +r"""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 6cb7220f0..8178f2d74 100644 --- a/jc/parsers/ping_s.py +++ b/jc/parsers/ping_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ping` command output streaming parser +r"""jc - JSON Convert `ping` command output streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/pip_list.py b/jc/parsers/pip_list.py index 7bafeec29..2135936e8 100644 --- a/jc/parsers/pip_list.py +++ b/jc/parsers/pip_list.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `pip-list` command output parser +r"""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 8d12ebd86..c3d9d9e8a 100644 --- a/jc/parsers/pip_show.py +++ b/jc/parsers/pip_show.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `pip-show` command output parser +r"""jc - JSON Convert `pip-show` command output parser Usage (cli): diff --git a/jc/parsers/pkg_index_apk.py b/jc/parsers/pkg_index_apk.py index 3dd228ddc..916a8ef53 100644 --- a/jc/parsers/pkg_index_apk.py +++ b/jc/parsers/pkg_index_apk.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Alpine Linux Package Index files +r"""jc - JSON Convert Alpine Linux Package Index files Usage (cli): diff --git a/jc/parsers/pkg_index_deb.py b/jc/parsers/pkg_index_deb.py index 038544000..5c9f1d285 100644 --- a/jc/parsers/pkg_index_deb.py +++ b/jc/parsers/pkg_index_deb.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Debian Package Index file parser +r"""jc - JSON Convert Debian Package Index file parser Usage (cli): @@ -22,9 +22,15 @@ "maintainer": string, "description": string, "homepage": string, - "depends": string, - "conflicts": string, - "replaces": string, + "depends": [ + string + ], + "conflicts": [ + string + ], + "replaces": [ + string + ], "vcs_git": string, "sha256": string, "size": integer, @@ -38,35 +44,44 @@ $ cat Packages | jc --pkg-index-deb [ { - "package": "aspnetcore-runtime-2.1", - "version": "2.1.22-1", + "package": "dotnet-host", + "version": "3.1.16-1", "architecture": "amd64", - "section": "devel", + "section": "libs", "priority": "standard", - "installed_size": 71081, - "maintainer": "Microsoft ", - "description": "Microsoft ASP.NET Core 2.1.22 Shared Framework", - "homepage": "https://www.asp.net/", - "depends": "libc6 (>= 2.14), dotnet-runtime-2.1 (>= 2.1.22)", - "sha256": "48d4e78a7ceff34105411172f4c3e91a0359b3929d84d26a493...", - "size": 21937036, - "filename": "pool/main/a/aspnetcore-runtime-2.1/aspnetcore-run..." + "installed_size": 146, + "maintainer": ".NET Core Team ", + "description": "Microsoft .NET Core Host - 3.1.16", + "homepage": "https://dot.net/core", + "conflicts": [ + "dotnet", + "dotnet-nightly" + ], + "depends": [ + "libgcc1", + "libstdc++6", + "libc6" + ], + "sha256": "2557da13447d61382f255eb751ba29cc1a8220899c1e3e640a7bb3d2a0c1d297", + "size": 32594, + "filename": "pool/main/d/dotnet-host/dotnet-host-3.1.16-x64.deb" }, { - "package": "azure-functions-core-tools-4", - "version": "4.0.4590-1", + "package": "aspnetcore-runtime-5.0", + "version": "5.0.10-1", "architecture": "amd64", "section": "devel", - "priority": "optional", - "maintainer": "Ahmed ElSayed ", - "description": "Azure Function Core Tools v4", - "homepage": "https://docs.microsoft.com/en-us/azure/azure-func...", - "conflicts": "azure-functions-core-tools-2, azure-functions-co...", - "replaces": "azure-functions-core-tools-2, azure-functions-cor...", - "vcs_git": "https://github.com/Azure/azure-functions-core-tool...", - "sha256": "a2a4f99d6d98ba0a46832570285552f2a93bab06cebbda2afc7...", - "size": 124417844, - "filename": "pool/main/a/azure-functions-core-tools-4/azure-fu..." + "priority": "standard", + "installed_size": 18551, + "maintainer": "Microsoft ", + "description": "Shared Framework for hosting of Microsoft ASP.NET Core applications. It is open source, cross-platform and is supported by Microsoft. We hope you enjoy using it! If you do, please consider joining the active community of developers that are contributing to the project on GitHub (https://github.com/dotnet/aspnetcore). We happily accept issues and PRs.", + "homepage": "https://asp.net", + "depends": [ + "dotnet-runtime-5.0 (>= 5.0.10)" + ], + "sha256": "1d9869f862cb4e9c46b245a343d8e39fbbc84d9f8ab9ef357c4643da20805ad3", + "size": 6084188, + "filename": "pool/main/a/aspnetcore-runtime-5.0/aspnetcore-runtime-5.0.10-x64.deb" } ] @@ -112,7 +127,7 @@ class info(): """Provides parser metadata (version, author, etc.)""" - version = '1.1' + version = '1.2' description = 'Debian Package Index file parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -144,4 +159,5 @@ def parse( """ # This parser is an alias of rpm_qi.py rpm_qi.info = info # type: ignore + rpm_qi.__name__ = __name__ return rpm_qi.parse(data, raw, quiet) diff --git a/jc/parsers/plist.py b/jc/parsers/plist.py index f7cd55142..e2c49eb90 100644 --- a/jc/parsers/plist.py +++ b/jc/parsers/plist.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert PLIST file parser +r"""jc - JSON Convert PLIST file parser Converts binary, XML, and NeXTSTEP PLIST files. diff --git a/jc/parsers/postconf.py b/jc/parsers/postconf.py index c4678fe0f..ee83c6608 100644 --- a/jc/parsers/postconf.py +++ b/jc/parsers/postconf.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `postconf -M` command output parser +r"""jc - JSON Convert `postconf -M` command output parser Usage (cli): diff --git a/jc/parsers/proc.py b/jc/parsers/proc.py index bfa1ad3d4..92b667aee 100644 --- a/jc/parsers/proc.py +++ b/jc/parsers/proc.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Proc file output parser +r"""jc - JSON Convert Proc file output parser This parser automatically identifies the Proc file and calls the corresponding parser to perform the parsing. @@ -47,7 +47,7 @@ Schemas can also be found online at: -https://kellyjonbrazil.github.io/jc/docs/parsers/proc_ + https://kellyjonbrazil.github.io/jc/docs/parsers/proc_ For example: @@ -118,15 +118,15 @@ ] """ import re -import importlib from typing import List, Dict, Union import jc.utils +from jc.lib import get_parser from jc.exceptions import ParseError class info(): """Provides parser metadata (version, author, etc.)""" - version = '1.3' + version = '1.4' description = '`/proc/` file parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -280,7 +280,7 @@ def parse( for reg_pattern, parse_mod in procmap.items(): if reg_pattern.search(data): try: - procparser = importlib.import_module('jc.parsers.' + parse_mod) + procparser = get_parser(parse_mod) return procparser.parse(data, quiet=quiet, raw=raw) except ModuleNotFoundError: raise ParseError('Proc file type not yet implemented.') diff --git a/jc/parsers/proc_buddyinfo.py b/jc/parsers/proc_buddyinfo.py index 8262ca454..8bb22b3ed 100644 --- a/jc/parsers/proc_buddyinfo.py +++ b/jc/parsers/proc_buddyinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/buddyinfo` file parser +r"""jc - JSON Convert `/proc/buddyinfo` file parser Usage (cli): diff --git a/jc/parsers/proc_cmdline.py b/jc/parsers/proc_cmdline.py index d4bf3d4ff..287cac8b8 100644 --- a/jc/parsers/proc_cmdline.py +++ b/jc/parsers/proc_cmdline.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/cmdline` file parser +r"""jc - JSON Convert `/proc/cmdline` file parser Usage (cli): diff --git a/jc/parsers/proc_consoles.py b/jc/parsers/proc_consoles.py index 3d8a95bea..095f94d52 100644 --- a/jc/parsers/proc_consoles.py +++ b/jc/parsers/proc_consoles.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/consoles` file parser +r"""jc - JSON Convert `/proc/consoles` file parser Usage (cli): diff --git a/jc/parsers/proc_cpuinfo.py b/jc/parsers/proc_cpuinfo.py index e7628e655..4355941fa 100644 --- a/jc/parsers/proc_cpuinfo.py +++ b/jc/parsers/proc_cpuinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/cpuinfo` file parser +r"""jc - JSON Convert `/proc/cpuinfo` file parser Usage (cli): diff --git a/jc/parsers/proc_crypto.py b/jc/parsers/proc_crypto.py index 76b270c56..7f392f351 100644 --- a/jc/parsers/proc_crypto.py +++ b/jc/parsers/proc_crypto.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/crypto` file parser +r"""jc - JSON Convert `/proc/crypto` file parser Usage (cli): diff --git a/jc/parsers/proc_devices.py b/jc/parsers/proc_devices.py index 20c2d1a56..63bf6a0d2 100644 --- a/jc/parsers/proc_devices.py +++ b/jc/parsers/proc_devices.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/devices` file parser +r"""jc - JSON Convert `/proc/devices` file parser Usage (cli): diff --git a/jc/parsers/proc_diskstats.py b/jc/parsers/proc_diskstats.py index 1067f8693..78686d335 100644 --- a/jc/parsers/proc_diskstats.py +++ b/jc/parsers/proc_diskstats.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/diskstats` file parser +r"""jc - JSON Convert `/proc/diskstats` file parser Usage (cli): diff --git a/jc/parsers/proc_driver_rtc.py b/jc/parsers/proc_driver_rtc.py index 8356755b4..292649f33 100644 --- a/jc/parsers/proc_driver_rtc.py +++ b/jc/parsers/proc_driver_rtc.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/driver/rtc` file parser +r"""jc - JSON Convert `/proc/driver/rtc` file parser Usage (cli): diff --git a/jc/parsers/proc_filesystems.py b/jc/parsers/proc_filesystems.py index 2e079b989..2ed7b1d83 100644 --- a/jc/parsers/proc_filesystems.py +++ b/jc/parsers/proc_filesystems.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/filesystems` file parser +r"""jc - JSON Convert `/proc/filesystems` file parser Usage (cli): diff --git a/jc/parsers/proc_interrupts.py b/jc/parsers/proc_interrupts.py index 376c053e9..acdd0615a 100644 --- a/jc/parsers/proc_interrupts.py +++ b/jc/parsers/proc_interrupts.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/interrupts` file parser +r"""jc - JSON Convert `/proc/interrupts` file parser Usage (cli): diff --git a/jc/parsers/proc_iomem.py b/jc/parsers/proc_iomem.py index 9d4b2766f..c0a18d1d1 100644 --- a/jc/parsers/proc_iomem.py +++ b/jc/parsers/proc_iomem.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/iomem` file parser +r"""jc - JSON Convert `/proc/iomem` file parser Usage (cli): diff --git a/jc/parsers/proc_ioports.py b/jc/parsers/proc_ioports.py index bac1c563e..128dbaa71 100644 --- a/jc/parsers/proc_ioports.py +++ b/jc/parsers/proc_ioports.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/ioports` file parser +r"""jc - JSON Convert `/proc/ioports` file parser Usage (cli): diff --git a/jc/parsers/proc_loadavg.py b/jc/parsers/proc_loadavg.py index 9247a41b4..2ad3146f9 100644 --- a/jc/parsers/proc_loadavg.py +++ b/jc/parsers/proc_loadavg.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/loadavg` file parser +r"""jc - JSON Convert `/proc/loadavg` file parser Usage (cli): diff --git a/jc/parsers/proc_locks.py b/jc/parsers/proc_locks.py index 01e8a3ca6..8c9e95e52 100644 --- a/jc/parsers/proc_locks.py +++ b/jc/parsers/proc_locks.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/locks` file parser +r"""jc - JSON Convert `/proc/locks` file parser Usage (cli): diff --git a/jc/parsers/proc_meminfo.py b/jc/parsers/proc_meminfo.py index d8ddce644..6181747ce 100644 --- a/jc/parsers/proc_meminfo.py +++ b/jc/parsers/proc_meminfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/meminfo` file parser +r"""jc - JSON Convert `/proc/meminfo` file parser Usage (cli): diff --git a/jc/parsers/proc_modules.py b/jc/parsers/proc_modules.py index 472c389a8..17c4ad3a4 100644 --- a/jc/parsers/proc_modules.py +++ b/jc/parsers/proc_modules.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/modules` file parser +r"""jc - JSON Convert `/proc/modules` file parser Usage (cli): diff --git a/jc/parsers/proc_mtrr.py b/jc/parsers/proc_mtrr.py index fbeae40b1..29195a546 100644 --- a/jc/parsers/proc_mtrr.py +++ b/jc/parsers/proc_mtrr.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/mtrr` file parser +r"""jc - JSON Convert `/proc/mtrr` file parser Usage (cli): diff --git a/jc/parsers/proc_net_arp.py b/jc/parsers/proc_net_arp.py index 47dfa6233..1ae44733d 100644 --- a/jc/parsers/proc_net_arp.py +++ b/jc/parsers/proc_net_arp.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/arp` file parser +r"""jc - JSON Convert `/proc/net/arp` file parser Usage (cli): diff --git a/jc/parsers/proc_net_dev.py b/jc/parsers/proc_net_dev.py index 14cf4af64..9c584fbf2 100644 --- a/jc/parsers/proc_net_dev.py +++ b/jc/parsers/proc_net_dev.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/dev` file parser +r"""jc - JSON Convert `/proc/net/dev` file parser Usage (cli): diff --git a/jc/parsers/proc_net_dev_mcast.py b/jc/parsers/proc_net_dev_mcast.py index 3984f3411..e585e6d2f 100644 --- a/jc/parsers/proc_net_dev_mcast.py +++ b/jc/parsers/proc_net_dev_mcast.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/dev_mcast` file parser +r"""jc - JSON Convert `/proc/net/dev_mcast` file parser Usage (cli): diff --git a/jc/parsers/proc_net_if_inet6.py b/jc/parsers/proc_net_if_inet6.py index a2e3d11ee..ea5d1b5aa 100644 --- a/jc/parsers/proc_net_if_inet6.py +++ b/jc/parsers/proc_net_if_inet6.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/if_inet6` file parser +r"""jc - JSON Convert `/proc/net/if_inet6` file parser Usage (cli): diff --git a/jc/parsers/proc_net_igmp.py b/jc/parsers/proc_net_igmp.py index d4f26b7d1..ff1b7aa89 100644 --- a/jc/parsers/proc_net_igmp.py +++ b/jc/parsers/proc_net_igmp.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/igmp` file parser +r"""jc - JSON Convert `/proc/net/igmp` file parser Usage (cli): diff --git a/jc/parsers/proc_net_igmp6.py b/jc/parsers/proc_net_igmp6.py index a16409590..594042f07 100644 --- a/jc/parsers/proc_net_igmp6.py +++ b/jc/parsers/proc_net_igmp6.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/igmp6` file parser +r"""jc - JSON Convert `/proc/net/igmp6` file parser Usage (cli): diff --git a/jc/parsers/proc_net_ipv6_route.py b/jc/parsers/proc_net_ipv6_route.py index b9643a8ff..123ae1764 100644 --- a/jc/parsers/proc_net_ipv6_route.py +++ b/jc/parsers/proc_net_ipv6_route.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/ipv6_route` file parser +r"""jc - JSON Convert `/proc/net/ipv6_route` file parser Usage (cli): diff --git a/jc/parsers/proc_net_netlink.py b/jc/parsers/proc_net_netlink.py index 31a8deb68..037af0b19 100644 --- a/jc/parsers/proc_net_netlink.py +++ b/jc/parsers/proc_net_netlink.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/netlink` file parser +r"""jc - JSON Convert `/proc/net/netlink` file parser Usage (cli): diff --git a/jc/parsers/proc_net_netstat.py b/jc/parsers/proc_net_netstat.py index d7ae90a73..7d769227e 100644 --- a/jc/parsers/proc_net_netstat.py +++ b/jc/parsers/proc_net_netstat.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/netstat` file parser +r"""jc - JSON Convert `/proc/net/netstat` file parser Usage (cli): diff --git a/jc/parsers/proc_net_packet.py b/jc/parsers/proc_net_packet.py index c29451719..fdff3b3e1 100644 --- a/jc/parsers/proc_net_packet.py +++ b/jc/parsers/proc_net_packet.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/packet` file parser +r"""jc - JSON Convert `/proc/net/packet` file parser Usage (cli): diff --git a/jc/parsers/proc_net_protocols.py b/jc/parsers/proc_net_protocols.py index 11a136ddd..b04fd47f9 100644 --- a/jc/parsers/proc_net_protocols.py +++ b/jc/parsers/proc_net_protocols.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/protocols` file parser +r"""jc - JSON Convert `/proc/net/protocols` file parser Usage (cli): diff --git a/jc/parsers/proc_net_route.py b/jc/parsers/proc_net_route.py index ff7e41d75..ffac2bb83 100644 --- a/jc/parsers/proc_net_route.py +++ b/jc/parsers/proc_net_route.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/route` file parser +r"""jc - JSON Convert `/proc/net/route` file parser Usage (cli): diff --git a/jc/parsers/proc_net_tcp.py b/jc/parsers/proc_net_tcp.py index 6b504f7ea..4f687e26f 100644 --- a/jc/parsers/proc_net_tcp.py +++ b/jc/parsers/proc_net_tcp.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/tcp` and `proc/net/tcp6` file parser +r"""jc - JSON Convert `/proc/net/tcp` and `proc/net/tcp6` file parser IPv4 and IPv6 addresses are converted to standard notation unless the raw (--raw) option is used. diff --git a/jc/parsers/proc_net_unix.py b/jc/parsers/proc_net_unix.py index db1f53381..dc51afd5c 100644 --- a/jc/parsers/proc_net_unix.py +++ b/jc/parsers/proc_net_unix.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/unix` file parser +r"""jc - JSON Convert `/proc/net/unix` file parser Usage (cli): diff --git a/jc/parsers/proc_pagetypeinfo.py b/jc/parsers/proc_pagetypeinfo.py index 92a0ed262..f14458e9a 100644 --- a/jc/parsers/proc_pagetypeinfo.py +++ b/jc/parsers/proc_pagetypeinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/pagetypeinfo` file parser +r"""jc - JSON Convert `/proc/pagetypeinfo` file parser Usage (cli): diff --git a/jc/parsers/proc_partitions.py b/jc/parsers/proc_partitions.py index 6afbeda06..494acff90 100644 --- a/jc/parsers/proc_partitions.py +++ b/jc/parsers/proc_partitions.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/partitions` file parser +r"""jc - JSON Convert `/proc/partitions` file parser Usage (cli): diff --git a/jc/parsers/proc_pid_fdinfo.py b/jc/parsers/proc_pid_fdinfo.py index d86d6ec3e..48cbfeae1 100644 --- a/jc/parsers/proc_pid_fdinfo.py +++ b/jc/parsers/proc_pid_fdinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc//fdinfo/` file parser +r"""jc - JSON Convert `/proc//fdinfo/` file parser Usage (cli): diff --git a/jc/parsers/proc_pid_io.py b/jc/parsers/proc_pid_io.py index c450302d0..a2fda8a81 100644 --- a/jc/parsers/proc_pid_io.py +++ b/jc/parsers/proc_pid_io.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc//io` file parser +r"""jc - JSON Convert `/proc//io` file parser Usage (cli): diff --git a/jc/parsers/proc_pid_maps.py b/jc/parsers/proc_pid_maps.py index e51c0fed4..28ca65676 100644 --- a/jc/parsers/proc_pid_maps.py +++ b/jc/parsers/proc_pid_maps.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc//maps` file parser +r"""jc - JSON Convert `/proc//maps` file parser Usage (cli): diff --git a/jc/parsers/proc_pid_mountinfo.py b/jc/parsers/proc_pid_mountinfo.py index 5b43bc94e..3d55fb1df 100644 --- a/jc/parsers/proc_pid_mountinfo.py +++ b/jc/parsers/proc_pid_mountinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc//mountinfo` file parser +r"""jc - JSON Convert `/proc//mountinfo` file parser Usage (cli): diff --git a/jc/parsers/proc_pid_numa_maps.py b/jc/parsers/proc_pid_numa_maps.py index 2210d4012..a9ebc3d4a 100644 --- a/jc/parsers/proc_pid_numa_maps.py +++ b/jc/parsers/proc_pid_numa_maps.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc//numa_maps` file parser +r"""jc - JSON Convert `/proc//numa_maps` file parser This parser will attempt to convert number values to integers. If that is not desired, please use the `--raw` option (cli) or `raw=True` argument diff --git a/jc/parsers/proc_pid_smaps.py b/jc/parsers/proc_pid_smaps.py index e20c3882c..d7be98fc5 100644 --- a/jc/parsers/proc_pid_smaps.py +++ b/jc/parsers/proc_pid_smaps.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc//smaps` file parser +r"""jc - JSON Convert `/proc//smaps` file parser Usage (cli): diff --git a/jc/parsers/proc_pid_stat.py b/jc/parsers/proc_pid_stat.py index 44ede29f1..4e83a7072 100644 --- a/jc/parsers/proc_pid_stat.py +++ b/jc/parsers/proc_pid_stat.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc//stat` file parser +r"""jc - JSON Convert `/proc//stat` file parser Usage (cli): @@ -202,7 +202,7 @@ class info(): """Provides parser metadata (version, author, etc.)""" - version = '1.1' + version = '1.2' description = '`/proc//stat` file parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -239,6 +239,7 @@ def _process(proc_data: Dict) -> Dict: 'K': 'Wakekill', 'W': 'Waking', 'P': 'Parked', + 'I': 'Idle' } if 'state' in proc_data: diff --git a/jc/parsers/proc_pid_statm.py b/jc/parsers/proc_pid_statm.py index a1cd2f42a..eae5b5eae 100644 --- a/jc/parsers/proc_pid_statm.py +++ b/jc/parsers/proc_pid_statm.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc//statm` file parser +r"""jc - JSON Convert `/proc//statm` file parser Usage (cli): diff --git a/jc/parsers/proc_pid_status.py b/jc/parsers/proc_pid_status.py index aae91e2f7..abd0bd7ab 100644 --- a/jc/parsers/proc_pid_status.py +++ b/jc/parsers/proc_pid_status.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc//status` file parser +r"""jc - JSON Convert `/proc//status` file parser Usage (cli): diff --git a/jc/parsers/proc_slabinfo.py b/jc/parsers/proc_slabinfo.py index 15488281f..630e31bd5 100644 --- a/jc/parsers/proc_slabinfo.py +++ b/jc/parsers/proc_slabinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/slabinfo` file parser +r"""jc - JSON Convert `/proc/slabinfo` file parser Usage (cli): diff --git a/jc/parsers/proc_softirqs.py b/jc/parsers/proc_softirqs.py index cac25ae9e..cd5c7ad10 100644 --- a/jc/parsers/proc_softirqs.py +++ b/jc/parsers/proc_softirqs.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/softirqs` file parser +r"""jc - JSON Convert `/proc/softirqs` file parser Usage (cli): diff --git a/jc/parsers/proc_stat.py b/jc/parsers/proc_stat.py index a09f67e90..f25f5a0fd 100644 --- a/jc/parsers/proc_stat.py +++ b/jc/parsers/proc_stat.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/stat` file parser +r"""jc - JSON Convert `/proc/stat` file parser Usage (cli): diff --git a/jc/parsers/proc_swaps.py b/jc/parsers/proc_swaps.py index 97269f4bd..b1a3f94bf 100644 --- a/jc/parsers/proc_swaps.py +++ b/jc/parsers/proc_swaps.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/swaps` file parser +r"""jc - JSON Convert `/proc/swaps` file parser Usage (cli): diff --git a/jc/parsers/proc_uptime.py b/jc/parsers/proc_uptime.py index c3207e471..a00ea4982 100644 --- a/jc/parsers/proc_uptime.py +++ b/jc/parsers/proc_uptime.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/uptime` file parser +r"""jc - JSON Convert `/proc/uptime` file parser Usage (cli): diff --git a/jc/parsers/proc_version.py b/jc/parsers/proc_version.py index e0fc46266..8d0c59c3f 100644 --- a/jc/parsers/proc_version.py +++ b/jc/parsers/proc_version.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/version` file parser +r"""jc - JSON Convert `/proc/version` file parser > Note: This parser will parse `/proc/version` files that follow the > common format used by most popular linux distributions. diff --git a/jc/parsers/proc_vmallocinfo.py b/jc/parsers/proc_vmallocinfo.py index 4001830e9..35545e214 100644 --- a/jc/parsers/proc_vmallocinfo.py +++ b/jc/parsers/proc_vmallocinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/vmallocinfo` file parser +r"""jc - JSON Convert `/proc/vmallocinfo` file parser This parser will attempt to convert number values to integers. If that is not desired, please use the `--raw` option (cli) or `raw=True` argument diff --git a/jc/parsers/proc_vmstat.py b/jc/parsers/proc_vmstat.py index 522f04bae..8298af6e0 100644 --- a/jc/parsers/proc_vmstat.py +++ b/jc/parsers/proc_vmstat.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/vmstat` file parser +r"""jc - JSON Convert `/proc/vmstat` file parser Usage (cli): diff --git a/jc/parsers/proc_zoneinfo.py b/jc/parsers/proc_zoneinfo.py index 77688b3b7..cfc30b078 100644 --- a/jc/parsers/proc_zoneinfo.py +++ b/jc/parsers/proc_zoneinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/zoneinfo` file parser +r"""jc - JSON Convert `/proc/zoneinfo` file parser Usage (cli): diff --git a/jc/parsers/ps.py b/jc/parsers/ps.py index 11ef2f90d..493fc015c 100644 --- a/jc/parsers/ps.py +++ b/jc/parsers/ps.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ps` command output parser +r"""jc - JSON Convert `ps` command output parser `ps` options supported: - `ef` diff --git a/jc/parsers/resolve_conf.py b/jc/parsers/resolve_conf.py index 82f221291..5de046e24 100644 --- a/jc/parsers/resolve_conf.py +++ b/jc/parsers/resolve_conf.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/etc/resolve.conf` file parser +r"""jc - JSON Convert `/etc/resolve.conf` file parser This parser may be more forgiving than the system parser. For example, if multiple `search` lists are defined, this parser will append all entries to diff --git a/jc/parsers/route.py b/jc/parsers/route.py index d6ae5a42d..17b7eff6f 100644 --- a/jc/parsers/route.py +++ b/jc/parsers/route.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `route` command output parser +r"""jc - JSON Convert `route` command output parser Usage (cli): diff --git a/jc/parsers/route_windows.py b/jc/parsers/route_windows.py index 46a8cbf77..a653f03b7 100644 --- a/jc/parsers/route_windows.py +++ b/jc/parsers/route_windows.py @@ -1,4 +1,4 @@ -""" +r""" jc - JSON Convert Windows `route` command output parser """ diff --git a/jc/parsers/rpm_qi.py b/jc/parsers/rpm_qi.py index 3251c38bf..e48fb731b 100644 --- a/jc/parsers/rpm_qi.py +++ b/jc/parsers/rpm_qi.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `rpm -qi` command output parser +r"""jc - JSON Convert `rpm -qi` command output parser Works with `rpm -qi [package]` or `rpm -qia`. @@ -43,6 +43,30 @@ "build_epoch_utc": integer, # [1] "build_host": string, "relocations": string, + "depends": [ + string + ], + "pre_depends": [ + string + ], + "recommends": [ + string + ], + "suggests": [ + string + ], + "conflicts": [ + string + ], + "breaks": [ + string + ], + "tag": [ + string + ], + "replaces": [ + string + ], "packager": string, "vendor": string, "url": string, @@ -161,7 +185,7 @@ class info(): """Provides parser metadata (version, author, etc.)""" - version = '1.7' + version = '1.8' description = '`rpm -qi` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -186,12 +210,20 @@ def _process(proc_data): List of Dictionaries. Structured data to conform to the schema. """ int_list = {'epoch', 'size', 'installed_size'} + split_list = {'depends', 'pre_depends', 'recommends', 'suggests', 'conflicts', + 'breaks', 'tag', 'replaces'} for entry in proc_data: for key in entry: if key in int_list: entry[key] = jc.utils.convert_to_int(entry[key]) + # for apt-cache show output + if key in split_list: + val_list = entry[key].split(',') + val_list = [x.strip() for x in val_list if x] + entry[key] = val_list + if 'build_date' in entry: timestamp = jc.utils.timestamp(entry['build_date'], format_hint=(3000,)) entry['build_epoch'] = timestamp.naive @@ -227,6 +259,7 @@ def parse(data, raw=False, quiet=False): last_entry = None this_entry = None desc_entry = False + desc_en_entry = False description = [] if jc.utils.has_data(data): @@ -245,24 +278,34 @@ def parse(data, raw=False, quiet=False): entry_obj = {} last_entry = this_entry desc_entry = False - - if len(split_line) == 2: - entry_obj[split_line[0].strip().lower().replace(' ', '_').replace('-', '_')] = split_line[1].strip() + desc_en_entry = False if line.startswith('Description :'): desc_entry = True description = [] continue + # for apt-cache show output + if line.startswith('Description-en:'): + desc_en_entry = True + description = [split_line[1].strip()] + continue + if desc_entry: description.append(line) + continue + + if desc_en_entry and line.startswith(' '): + description.append(line) + continue + + if len(split_line) == 2: + keyname = jc.utils.normalize_key(split_line[0]) + entry_obj[keyname] = split_line[1].strip() if entry_obj: if description: entry_obj['description'] = ' '.join(description) raw_output.append(entry_obj) - if raw: - return raw_output - else: - return _process(raw_output) + return raw_output if raw else _process(raw_output) diff --git a/jc/parsers/rsync.py b/jc/parsers/rsync.py index 137d2f7a1..195aae77d 100644 --- a/jc/parsers/rsync.py +++ b/jc/parsers/rsync.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `rsync` command output parser +r"""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 @@ -131,13 +131,13 @@ """ import re from copy import deepcopy -from typing import List, Dict +from typing import List, Dict, Union import jc.utils class info(): """Provides parser metadata (version, author, etc.)""" - version = '1.1' + version = '1.2' description = '`rsync` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -171,10 +171,26 @@ def _process(proc_data: List[Dict]) -> List[Dict]: for item in proc_data: for key in item['summary']: if key in int_list: - item['summary'][key] = jc.utils.convert_to_int(item['summary'][key]) + item['summary'][key] = jc.utils.convert_size_to_int(item['summary'][key]) if key in float_list: - item['summary'][key] = jc.utils.convert_to_float(item['summary'][key]) + converted_val: Union[float, None] = None + val = item['summary'][key] + if any([ + 'K' in val, + 'M' in val, + 'G' in val, + 'T' in val + ]): + converted_int_val = jc.utils.convert_size_to_int(val) + + if not converted_int_val is None: + converted_val = float(converted_int_val) + + else: + converted_val = jc.utils.convert_to_float(val) + + item['summary'][key] = converted_val for entry in item['files']: for key in entry: @@ -311,6 +327,9 @@ def parse( stat1_line_re = re.compile(r'(sent)\s+(?P[0-9,]+)\s+(bytes)\s+(received)\s+(?P[0-9,]+)\s+(bytes)\s+(?P[0-9,.]+)\s+(bytes/sec)') stat2_line_re = re.compile(r'(total size is)\s+(?P[0-9,]+)\s+(speedup is)\s+(?P[0-9,.]+)') + stat1_line_simple_re = re.compile(r'(sent)\s+(?P[0-9,.TGMK]+)\s+(bytes)\s+(received)\s+(?P[0-9,.TGMK]+)\s+(bytes)\s+(?P[0-9,.TGMK]+)\s+(bytes/sec)') + stat2_line_simple_re = re.compile(r'(total\s+size\s+is)\s+(?P[0-9,.TGMK]+)\s+(speedup\s+is)\s+(?P[0-9,.TGMK]+)') + file_line_log_re = re.compile(r'(?P\d\d\d\d/\d\d/\d\d)\s+(?P