Skip to content

Commit

Permalink
add deb-packages-index parser
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyjonbrazil committed Nov 21, 2023
1 parent 7951366 commit b5c22c6
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
jc changelog

20231114 v1.23.7
- Add `deb-packages` parser for Debian/Ubuntu Package Index files
- Add `deb-packages-index` parser for Debian/Ubuntu Package Index files
- Fix `iptables` parser for cases where the `target` field is blank in a rule
- Fix `vmstat` parsers for some cases where wide output is used
- Fix `mount` parser for cases with spaces in the mount point name
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ option.
| `--csv-s` | CSV file streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/csv_s) |
| `--date` | `date` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/date) |
| `--datetime-iso` | ISO 8601 Datetime string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/datetime_iso) |
| `--deb-packages-index` | Debian Packages Index file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/deb_packages_index) |
| `--df` | `df` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/df) |
| `--dig` | `dig` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/dig) |
| `--dir` | `dir` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/dir) |
Expand Down
2 changes: 1 addition & 1 deletion completions/jc_bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ _jc()
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 date df dig dmidecode dpkg du 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 sysctl systemctl systeminfo timedatectl top tracepath tracepath6 traceroute traceroute6 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 --date --datetime-iso --df --dig --dir --dmidecode --dpkg-l --du --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 --id --ifconfig --ini --ini-dup --iostat --iostat-s --ip-address --iptables --ip-route --iw-scan --iwconfig --jar-manifest --jobs --jwt --kv --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 --pci-ids --pgpass --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --plist --postconf --proc --proc-buddyinfo --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 --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 --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 --arp --asciitable --asciitable-m --blkid --bluetoothctl --cbt --cef --cef-s --certbot --chage --cksum --clf --clf-s --crontab --crontab-u --csv --csv-s --date --datetime-iso --deb-packages-index --df --dig --dir --dmidecode --dpkg-l --du --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 --id --ifconfig --ini --ini-dup --iostat --iostat-s --ip-address --iptables --ip-route --iw-scan --iwconfig --jar-manifest --jobs --jwt --kv --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 --pci-ids --pgpass --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --plist --postconf --proc --proc-buddyinfo --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 --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 --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 --unbuffer -u --yaml-out -y)
jc_about_options=(--about -a)
jc_about_mod_options=(--pretty -p --yaml-out -y --monochrome -m --force-color -C)
Expand Down
3 changes: 2 additions & 1 deletion completions/jc_zsh_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ _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 --date --datetime-iso --df --dig --dir --dmidecode --dpkg-l --du --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 --id --ifconfig --ini --ini-dup --iostat --iostat-s --ip-address --iptables --ip-route --iw-scan --iwconfig --jar-manifest --jobs --jwt --kv --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 --pci-ids --pgpass --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --plist --postconf --proc --proc-buddyinfo --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 --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 --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 --arp --asciitable --asciitable-m --blkid --bluetoothctl --cbt --cef --cef-s --certbot --chage --cksum --clf --clf-s --crontab --crontab-u --csv --csv-s --date --datetime-iso --deb-packages-index --df --dig --dir --dmidecode --dpkg-l --du --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 --id --ifconfig --ini --ini-dup --iostat --iostat-s --ip-address --iptables --ip-route --iw-scan --iwconfig --jar-manifest --jobs --jwt --kv --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 --pci-ids --pgpass --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --plist --postconf --proc --proc-buddyinfo --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 --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 --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'
Expand All @@ -136,6 +136,7 @@ _jc() {
'--csv-s:CSV file streaming parser'
'--date:`date` command parser'
'--datetime-iso:ISO 8601 Datetime string parser'
'--deb-packages-index:Debian Packages Index file parser'
'--df:`df` command parser'
'--dig:`dig` command parser'
'--dir:`dir` command parser'
Expand Down
1 change: 1 addition & 0 deletions jc/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'csv-s',
'date',
'datetime-iso',
'deb-packages-index',
'df',
'dig',
'dir',
Expand Down
148 changes: 148 additions & 0 deletions jc/parsers/deb_packages_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
"""jc - JSON Convert Debian Packages Index file parser
Usage (cli):
$ cat Packages | jc --deb-packages-index
Usage (module):
import jc
result = jc.parse('deb_packages_index', deb_package_index_output)
Schema:
[
{
"package": string,
"version": string,
"architecture": string,
"section": string,
"priority": string,
"installed_size": integer,
"maintainer": string,
"description": string,
"homepage": string,
"depends": string,
"conflicts": string,
"replaces": string,
"vcs_git": string,
"sha256": string,
"size": integer,
"vcs_git": string,
"filename": string
}
]
Examples:
$ cat Packages | jc --deb-packages-index
[
{
"package": "aspnetcore-runtime-2.1",
"version": "2.1.22-1",
"architecture": "amd64",
"section": "devel",
"priority": "standard",
"installed_size": 71081,
"maintainer": "Microsoft <[email protected]>",
"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..."
},
{
"package": "azure-functions-core-tools-4",
"version": "4.0.4590-1",
"architecture": "amd64",
"section": "devel",
"priority": "optional",
"maintainer": "Ahmed ElSayed <[email protected]>",
"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..."
}
]
$ cat Packages | jc --deb-packages-index -r
[
{
"package": "aspnetcore-runtime-2.1",
"version": "2.1.22-1",
"architecture": "amd64",
"section": "devel",
"priority": "standard",
"installed_size": "71081",
"maintainer": "Microsoft <[email protected]>",
"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..."
},
{
"package": "azure-functions-core-tools-4",
"version": "4.0.4590-1",
"architecture": "amd64",
"section": "devel",
"priority": "optional",
"maintainer": "Ahmed ElSayed <[email protected]>",
"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..."
}
]
"""
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 = 'Debian Packages Index file parser'
author = 'Kelly Brazil'
author_email = '[email protected]'
details = 'Using the rpm-qi parser'
compatible = ['linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd']
tags = ['file']


__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.compatible = ['linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd']
rpm_qi.info.tags = ['file']
return rpm_qi.parse(data, raw, quiet)
4 changes: 2 additions & 2 deletions jc/parsers/rpm_qi.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def _process(proc_data):
List of Dictionaries. Structured data to conform to the schema.
"""
int_list = {'epoch', 'size'}
int_list = {'epoch', 'size', 'installed_size'}

for entry in proc_data:
for key in entry:
Expand Down Expand Up @@ -247,7 +247,7 @@ def parse(data, raw=False, quiet=False):
desc_entry = False

if len(split_line) == 2:
entry_obj[split_line[0].strip().lower().replace(' ', '_')] = split_line[1].strip()
entry_obj[split_line[0].strip().lower().replace(' ', '_').replace('-', '_')] = split_line[1].strip()

if line.startswith('Description :'):
desc_entry = True
Expand Down
7 changes: 6 additions & 1 deletion man/jc.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH jc 1 2023-11-14 1.23.7 "JSON Convert"
.TH jc 1 2023-11-21 1.23.7 "JSON Convert"
.SH NAME
\fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types,
and strings
Expand Down Expand Up @@ -147,6 +147,11 @@ CSV file streaming parser
\fB--datetime-iso\fP
ISO 8601 Datetime string parser

.TP
.B
\fB--deb-packages-index\fP
Debian Packages Index file parser

.TP
.B
\fB--df\fP
Expand Down

0 comments on commit b5c22c6

Please sign in to comment.