1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00

efibootmgr updates

This commit is contained in:
Kelly Brazil
2024-02-05 11:35:59 -08:00
parent 539fe72d16
commit 3fbdffd028
10 changed files with 221 additions and 227 deletions

View File

@ -12,6 +12,7 @@ jc changelog
identifying which input matches to which output when using `--slurp` or when converting multiple
files via `/proc` file magic syntax.
- Add `curl-head` command parser for `curl --head` or `curl -I` with verbose support
- Add `efibootmgr` command parser
- Add `http-headers` parser for plain HTTP header output
- Add `kv-dup` parser for Key/Value files with duplicate keys
- Add `path` string parser to parse posix path

View File

@ -186,6 +186,7 @@ option.
| `--dmidecode` | `dmidecode` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/dmidecode) |
| `--dpkg-l` | `dpkg -l` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/dpkg_l) |
| `--du` | `du` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/du) |
| `--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) |
| `--file` | `file` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/file) |

View File

@ -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 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 --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 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_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)

View File

@ -9,7 +9,7 @@ _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 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 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_describe=(
'acpi:run "acpi" command with magic syntax.'
'airport:run "airport" command with magic syntax.'
@ -117,7 +117,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 --curl-head --date --datetime-iso --debconf-show --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 --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 --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_describe=(
'--acpi:`acpi` command parser'
'--airport:`airport -I` command parser'

104
docs/parsers/efibootmgr.md Normal file
View File

@ -0,0 +1,104 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.efibootmgr"></a>
# jc.parsers.efibootmgr
jc - JSON Convert `efibootmgr` command output parser
The `-v` option is also supported.
Usage (cli):
$ sudo efibootmgr | jc --efibootmgr
$ sudo efibootmgr -v | jc --efibootmgr
or
$ sudo jc efibootmgr
Usage (module):
import jc
result = jc.parse('efibootmgr', efibootmgr_command_output)
Schema:
{
"boot_current": string,
"timeout_seconds": integer,
"boot_order": [
string
],
mirrored_percentage_above_4g: float,
mirror_memory_below_4gb: boolean,
"boot_options": [
{
"boot_option_reference": string,
"display_name": string,
"uefi_device_path": string,
"boot_option_enabled": boolean
}
]
}
Examples:
$ sudo efibootmgr -v | jc --efibootmgr --p
{
"boot_current": "0002",
"timeout_seconds": 0,
"boot_order": [
"0002",
"0000",
"0001"
],
"mirrored_percentage_above_4g": 0.0,
"mirror_memory_below_4gb": false,
"boot_options": [
{
"boot_option_reference": "Boot0000",
"display_name": "WARNADO",
"uefi_device_path": "HD(1,GPT,05b9944c-1c60-492b-a510-7bbedccdc...",
"boot_option_enabled": true
},
{
"boot_option_reference": "Boot0001",
"display_name": "Embedded NIC 1 Port 1 Partition 1",
"uefi_device_path": "VenHw(3a191845-5f86-4e78-8fce-c4cff59f9daa)",
"boot_option_enabled": true
},
{
"boot_option_reference": "Boot0002",
"display_name": "opensuse-secureboot",
"uefi_device_path": "HD(1,GPT,c5d4f69d-6fc2-48c7-acee-af3f30336...",
"boot_option_enabled": true
}
]
}
<a id="jc.parsers.efibootmgr.parse"></a>
### parse
```python
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.
### Parser Information
Compatibility: linux
Source: [`jc/parsers/efibootmgr.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/efibootmgr.py)
Version 1.0 by Yaofei Zheng (zyf26256@gmail.com, Yaofei.Zheng@dell.com)

View File

@ -1,6 +1,6 @@
"""jc - JSON Convert `efibootmgr` command output parser
Only `efibootmgr -v` option is supported with the default output.
The `-v` option is also supported.
Usage (cli):
@ -18,143 +18,150 @@ Usage (module):
Schema:
[
{
"boot_current": string,
"timeout_seconds": number,
"boot_current": string,
"timeout_seconds": integer,
"boot_order": [
string,
string,
string
string
],
mirrored_percentage_above_4g: number,
mirror_memory_below_4gb: bool,
mirrored_percentage_above_4g: float,
mirror_memory_below_4gb: boolean,
"boot_options": [
{
"boot_option_reference": string,
"display_name": string,
"uefi_device_path": string,
"boot_option_enabled": bool
},
{
"boot_option_reference": string,
"display_name": string,
"uefi_device_path": string,
"boot_option_enabled": bool
},
{
"boot_option_reference": string,
"display_name": string,
"uefi_device_path": string,
"boot_option_enabled": bool
"boot_option_reference": string,
"display_name": string,
"uefi_device_path": string,
"boot_option_enabled": boolean
}
]
}
]
Examples:
$ sudo efibootmgr -v | jc --efibootmgr --pretty
[
{
"boot_current": "0002",
"timeout_seconds": 0,
"boot_order": [
"0002",
"0000",
"0001"
],
"mirrored_percentage_above_4g": 0.0,
"mirror_memory_below_4gb": false,
"boot_options": [
{
"boot_option_reference": "Boot0000",
"display_name": "WARNADO",
"uefi_device_path": "HD(1,GPT,05b9944c-1c60-492b-a510-7bbedccdc602,0x800,0xfa000)/File(EFI\\boot\\bootx64.efi)",
"boot_option_enabled": true
},
{
"boot_option_reference": "Boot0001",
"display_name": "Embedded NIC 1 Port 1 Partition 1",
"uefi_device_path": "VenHw(3a191845-5f86-4e78-8fce-c4cff59f9daa)",
"boot_option_enabled": true
},
{
"boot_option_reference": "Boot0002",
"display_name": "opensuse-secureboot",
"uefi_device_path": "HD(1,GPT,c5d4f69d-6fc2-48c7-acee-af3f30336dc5,0x800,0x19000)/File(\\EFI\\opensuse\\shim.efi)",
"boot_option_enabled": true
}
]
}
]
$ sudo efibootmgr -v | jc --efibootmgr --p
{
"boot_current": "0002",
"timeout_seconds": 0,
"boot_order": [
"0002",
"0000",
"0001"
],
"mirrored_percentage_above_4g": 0.0,
"mirror_memory_below_4gb": false,
"boot_options": [
{
"boot_option_reference": "Boot0000",
"display_name": "WARNADO",
"uefi_device_path": "HD(1,GPT,05b9944c-1c60-492b-a510-7bbedccdc...",
"boot_option_enabled": true
},
{
"boot_option_reference": "Boot0001",
"display_name": "Embedded NIC 1 Port 1 Partition 1",
"uefi_device_path": "VenHw(3a191845-5f86-4e78-8fce-c4cff59f9daa)",
"boot_option_enabled": true
},
{
"boot_option_reference": "Boot0002",
"display_name": "opensuse-secureboot",
"uefi_device_path": "HD(1,GPT,c5d4f69d-6fc2-48c7-acee-af3f30336...",
"boot_option_enabled": true
}
]
}
"""
from typing import List, Dict
from jc.jc_types import JSONDictType
import jc.utils
import jc.parsers.universal
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '0.1'
description = '`efibootmgr -v` command parser'
version = '1.0'
description = '`efibootmgr` command parser'
author = 'Yaofei Zheng'
author_email = ['zyf26256@gmail.com','Yaofei.Zheng@dell.com']
author_email = "zyf26256@gmail.com, Yaofei.Zheng@dell.com"
compatible = ['linux']
magic_commands = ['efibootmgr']
tags = ['command']
__version__ = info.version
def _process(proc_data):
if 0 == len(proc_data):
return proc_data
proc_data[0]["timeout_seconds"] = int(proc_data[0]["timeout_seconds"].replace("seconds","").strip(), 10)
proc_data[0]["boot_order"] = proc_data[0]["boot_order"].split(',')
for boot_opt in proc_data[0]["boot_options"]:
boot_opt["boot_option_enabled"] = boot_opt["boot_option_enabled"] == '*'
proc_data[0]["mirrored_percentage_above_4g"] = float(proc_data[0]["mirrored_percentage_above_4g"])
proc_data[0]["mirror_memory_below_4gb"] = not ("false" == proc_data[0]["mirror_memory_below_4gb"])
def _process(proc_data: JSONDictType) -> JSONDictType:
if 'timeout_seconds' in proc_data:
proc_data["timeout_seconds"] = jc.utils.convert_to_int(proc_data["timeout_seconds"])
if 'boot_order' in proc_data:
proc_data["boot_order"] = proc_data["boot_order"].split(',')
if 'boot_options' in proc_data:
for boot_opt in proc_data["boot_options"]:
boot_opt["boot_option_enabled"] = bool(boot_opt["boot_option_enabled"] == '*')
if 'mirrored_percentage_above_4g' in proc_data:
proc_data["mirrored_percentage_above_4g"] = float(proc_data["mirrored_percentage_above_4g"])
if 'mirror_memory_below_4gb' in proc_data:
proc_data["mirror_memory_below_4gb"] = not (proc_data["mirror_memory_below_4gb"] == "false")
return proc_data
def parse(data, raw=False, quiet=False):
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 = []
raw_output: Dict = {}
if jc.utils.has_data(data):
boot_opt_list = []
efibootmgr_dict = {}
boot_opt_list: List = []
for line in filter(None, data.splitlines()):
if "BootCurrent" in line:
efibootmgr_dict["boot_current"] = line.split(':')[1].strip()
raw_output["boot_current"] = line.split(':')[1].strip()
elif "Timeout" in line:
efibootmgr_dict["timeout_seconds"] = line.split(':')[1].strip()
raw_output["timeout_seconds"] = line.split(':')[1].strip()
elif "BootOrder" in line:
efibootmgr_dict["boot_order"] = line.split(':')[1].strip()
raw_output["boot_order"] = line.split(':')[1].strip()
elif "Boot" in line:
tmp_dict = {}
tmp_dict: Dict = {}
boot_record = line.split("\t")
tmp_dict["boot_option_reference"] = boot_record[0][0:8]
tmp_dict["display_name"] = boot_record[0][10:].strip()
if len(boot_record) > 1:
tmp_dict["uefi_device_path"] = boot_record[1].strip()
tmp_dict["boot_option_enabled"] = boot_record[0][8]
boot_opt_list.append(tmp_dict)
elif "MirroredPercentageAbove4G" in line:
efibootmgr_dict["mirrored_percentage_above_4g"] = line.split(':')[1].strip()
raw_output["mirrored_percentage_above_4g"] = line.split(':')[1].strip()
elif "MirrorMemoryBelow4GB" in line:
efibootmgr_dict["mirror_memory_below_4gb"] = line.split(':')[1].strip()
else:
# print(line)
continue
raw_output["mirror_memory_below_4gb"] = line.split(':')[1].strip()
efibootmgr_dict["boot_options"] = boot_opt_list
raw_output["boot_options"] = boot_opt_list
raw_output.append(efibootmgr_dict)
if raw:
return raw_output
else:
return _process(raw_output)
return raw_output if raw else _process(raw_output)

View File

@ -1,4 +1,4 @@
.TH jc 1 2024-02-04 1.25.0 "JSON Convert"
.TH jc 1 2024-02-05 1.25.0 "JSON Convert"
.SH NAME
\fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types,
and strings
@ -187,6 +187,11 @@ ISO 8601 Datetime string parser
\fB--du\fP
`du` command parser
.TP
.B
\fB--efibootmgr\fP
`efibootmgr` command parser
.TP
.B
\fB--email-address\fP

View File

@ -1,96 +1 @@
[
{
"boot_current": "0004",
"timeout_seconds": 0,
"boot_order": [
"0004",
"0001",
"0007",
"0002",
"0003",
"0009",
"0000",
"0005",
"0006",
"0008",
"000A",
"000B"
],
"mirrored_percentage_above_4g": 0.0,
"mirror_memory_below_4gb": false,
"boot_options": [
{
"boot_option_reference": "Boot0000",
"display_name": "debian",
"uefi_device_path": "HD(1,GPT,66b2a325-3129-45d3-84dd-c1a4e4bd846b,0x800,0x100000)/File(\\EFI\\debian\\shimx64.efi)",
"boot_option_enabled": true
},
{
"boot_option_reference": "Boot0001",
"display_name": "RecoveryBoot",
"uefi_device_path": "HD(3,GPT,a75ab570-de77-504c-be97-35faa629f1f3,0x5dc800,0x1f4000)/File(EFI\\boot\\bootx64.efi)",
"boot_option_enabled": true
},
{
"boot_option_reference": "Boot0002",
"display_name": "Embedded NIC 1 Port 1 Partition 1",
"uefi_device_path": "VenHw(3a191845-5f86-4e78-8fce-c4cff59f9daa)",
"boot_option_enabled": false
},
{
"boot_option_reference": "Boot0003",
"display_name": "Embedded NIC 2 Port 1 Partition 1",
"uefi_device_path": "VenHw(d227c733-f75f-4341-b749-4d1759ec8538)",
"boot_option_enabled": false
},
{
"boot_option_reference": "Boot0004",
"display_name": "PrimaryBoot",
"uefi_device_path": "HD(1,GPT,faf946be-a174-478f-82ea-d90aa476fb91,0x800,0xfa000)/File(EFI\\boot\\bootx64.efi)",
"boot_option_enabled": true
},
{
"boot_option_reference": "Boot0005",
"display_name": "EFI Fixed Disk Boot Device 3",
"uefi_device_path": "PciRoot(0x1)/Pci(0x4,0x0)/Pci(0x0,0x0)/NVMe(0x1,8C-E3-8E-E2-0A-D4-0F-01)/HD(1,GPT,c2336d30-9bde-4a0b-b9be-145d6958d5af,0x1000,0x80001)",
"boot_option_enabled": true
},
{
"boot_option_reference": "Boot0006",
"display_name": "EFI Fixed Disk Boot Device 4",
"uefi_device_path": "PciRoot(0x11)/Pci(0x1,0x0)/Pci(0x0,0x0)/NVMe(0x1,00-25-38-95-21-01-B8-C1)/HD(1,GPT,1fbfeaec-d78d-4d8c-93ae-77bba6c09d3f,0x1000,0x80001)",
"boot_option_enabled": true
},
{
"boot_option_reference": "Boot0007",
"display_name": "BackendBoot",
"uefi_device_path": "PciRoot(0x11)/Pci(0x3,0x0)/Pci(0x0,0x0)/NVMe(0x1,00-25-38-95-21-01-B5-B6)/HD(1,GPT,b95c4d58-849f-40fa-bf2b-4f0b8a0aa8bd,0x1000,0x80001)",
"boot_option_enabled": true
},
{
"boot_option_reference": "Boot0008",
"display_name": "EFI Fixed Disk Boot Device 6",
"uefi_device_path": "PciRoot(0x11)/Pci(0x6,0x0)/Pci(0x0,0x0)/NVMe(0x1,8C-E3-8E-E2-0A-D3-90-01)/HD(1,GPT,f543ab7b-9d55-4e57-8afe-bdb907428f15,0x1000,0x80001)",
"boot_option_enabled": true
},
{
"boot_option_reference": "Boot0009",
"display_name": "EFI Fixed Disk Boot Device 7",
"uefi_device_path": "PciRoot(0x12)/Pci(0x6,0x0)/Pci(0x0,0x0)/NVMe(0x1,00-25-38-95-21-01-B6-08)/HD(1,GPT,db9522dc-062b-4efa-84b5-6956cea7b5a6,0x1000,0x80001)",
"boot_option_enabled": true
},
{
"boot_option_reference": "Boot000A",
"display_name": "EFI Fixed Disk Boot Device 8",
"uefi_device_path": "PciRoot(0x12)/Pci(0x8,0x0)/Pci(0x0,0x0)/NVMe(0x1,00-25-38-95-21-01-B6-0D)/HD(1,GPT,4a9e1d40-b853-44a0-8d26-a4df6f112dc9,0x1000,0x80001)",
"boot_option_enabled": true
},
{
"boot_option_reference": "Boot000B",
"display_name": "EFI Fixed Disk Boot Device 9",
"uefi_device_path": "PciRoot(0x13)/Pci(0x5,0x0)/Pci(0x0,0x0)/NVMe(0x1,8C-E3-8E-E2-0A-D3-8E-01)/HD(1,GPT,5a80e168-bac7-4967-9507-e23a432bae18,0x1000,0x80001)",
"boot_option_enabled": true
}
]
}
]
{"boot_current":"0004","timeout_seconds":0,"boot_order":["0004","0001","0007","0002","0003","0009","0000","0005","0006","0008","000A","000B"],"mirrored_percentage_above_4g":0.0,"mirror_memory_below_4gb":false,"boot_options":[{"boot_option_reference":"Boot0000","display_name":"debian","uefi_device_path":"HD(1,GPT,66b2a325-3129-45d3-84dd-c1a4e4bd846b,0x800,0x100000)/File(\\EFI\\debian\\shimx64.efi)","boot_option_enabled":true},{"boot_option_reference":"Boot0001","display_name":"RecoveryBoot","uefi_device_path":"HD(3,GPT,a75ab570-de77-504c-be97-35faa629f1f3,0x5dc800,0x1f4000)/File(EFI\\boot\\bootx64.efi)","boot_option_enabled":true},{"boot_option_reference":"Boot0002","display_name":"Embedded NIC 1 Port 1 Partition 1","uefi_device_path":"VenHw(3a191845-5f86-4e78-8fce-c4cff59f9daa)","boot_option_enabled":false},{"boot_option_reference":"Boot0003","display_name":"Embedded NIC 2 Port 1 Partition 1","uefi_device_path":"VenHw(d227c733-f75f-4341-b749-4d1759ec8538)","boot_option_enabled":false},{"boot_option_reference":"Boot0004","display_name":"PrimaryBoot","uefi_device_path":"HD(1,GPT,faf946be-a174-478f-82ea-d90aa476fb91,0x800,0xfa000)/File(EFI\\boot\\bootx64.efi)","boot_option_enabled":true},{"boot_option_reference":"Boot0005","display_name":"EFI Fixed Disk Boot Device 3","uefi_device_path":"PciRoot(0x1)/Pci(0x4,0x0)/Pci(0x0,0x0)/NVMe(0x1,8C-E3-8E-E2-0A-D4-0F-01)/HD(1,GPT,c2336d30-9bde-4a0b-b9be-145d6958d5af,0x1000,0x80001)","boot_option_enabled":true},{"boot_option_reference":"Boot0006","display_name":"EFI Fixed Disk Boot Device 4","uefi_device_path":"PciRoot(0x11)/Pci(0x1,0x0)/Pci(0x0,0x0)/NVMe(0x1,00-25-38-95-21-01-B8-C1)/HD(1,GPT,1fbfeaec-d78d-4d8c-93ae-77bba6c09d3f,0x1000,0x80001)","boot_option_enabled":true},{"boot_option_reference":"Boot0007","display_name":"BackendBoot","uefi_device_path":"PciRoot(0x11)/Pci(0x3,0x0)/Pci(0x0,0x0)/NVMe(0x1,00-25-38-95-21-01-B5-B6)/HD(1,GPT,b95c4d58-849f-40fa-bf2b-4f0b8a0aa8bd,0x1000,0x80001)","boot_option_enabled":true},{"boot_option_reference":"Boot0008","display_name":"EFI Fixed Disk Boot Device 6","uefi_device_path":"PciRoot(0x11)/Pci(0x6,0x0)/Pci(0x0,0x0)/NVMe(0x1,8C-E3-8E-E2-0A-D3-90-01)/HD(1,GPT,f543ab7b-9d55-4e57-8afe-bdb907428f15,0x1000,0x80001)","boot_option_enabled":true},{"boot_option_reference":"Boot0009","display_name":"EFI Fixed Disk Boot Device 7","uefi_device_path":"PciRoot(0x12)/Pci(0x6,0x0)/Pci(0x0,0x0)/NVMe(0x1,00-25-38-95-21-01-B6-08)/HD(1,GPT,db9522dc-062b-4efa-84b5-6956cea7b5a6,0x1000,0x80001)","boot_option_enabled":true},{"boot_option_reference":"Boot000A","display_name":"EFI Fixed Disk Boot Device 8","uefi_device_path":"PciRoot(0x12)/Pci(0x8,0x0)/Pci(0x0,0x0)/NVMe(0x1,00-25-38-95-21-01-B6-0D)/HD(1,GPT,4a9e1d40-b853-44a0-8d26-a4df6f112dc9,0x1000,0x80001)","boot_option_enabled":true},{"boot_option_reference":"Boot000B","display_name":"EFI Fixed Disk Boot Device 9","uefi_device_path":"PciRoot(0x13)/Pci(0x5,0x0)/Pci(0x0,0x0)/NVMe(0x1,8C-E3-8E-E2-0A-D3-8E-01)/HD(1,GPT,5a80e168-bac7-4967-9507-e23a432bae18,0x1000,0x80001)","boot_option_enabled":true}]}

View File

@ -1,30 +1 @@
[
{
"boot_current": "0002",
"timeout_seconds": 0,
"boot_order": [
"0002",
"0000",
"0001"
],
"mirrored_percentage_above_4g": 0.0,
"mirror_memory_below_4gb": false,
"boot_options": [
{
"boot_option_reference": "Boot0000",
"display_name": "WARNING",
"boot_option_enabled": true
},
{
"boot_option_reference": "Boot0001",
"display_name": "Embedded NIC 1 Port 1 Partition 1",
"boot_option_enabled": true
},
{
"boot_option_reference": "Boot0002",
"display_name": "opensuse-secureboot",
"boot_option_enabled": true
}
]
}
]
{"boot_current":"0002","timeout_seconds":0,"boot_order":["0002","0000","0001"],"mirrored_percentage_above_4g":0.0,"mirror_memory_below_4gb":false,"boot_options":[{"boot_option_reference":"Boot0000","display_name":"WARNING","boot_option_enabled":true},{"boot_option_reference":"Boot0001","display_name":"Embedded NIC 1 Port 1 Partition 1","boot_option_enabled":true},{"boot_option_reference":"Boot0002","display_name":"opensuse-secureboot","boot_option_enabled":true}]}

View File

@ -26,7 +26,7 @@ class MyTests(unittest.TestCase):
"""
Test 'efibootmgr' with no data
"""
self.assertEqual(jc.parsers.efibootmgr.parse('', quiet=True), [])
self.assertEqual(jc.parsers.efibootmgr.parse('', quiet=True), {})
def test_efibootmgr_v_opensuse_leap_15_5(self):
"""