From ea915b787bb3a072bcfa3d5ad4e0330ef8f1831cfeb3787ab9113b3867738b26 Mon Sep 17 00:00:00 2001 From: ranomier Date: Thu, 16 Jan 2025 03:24:23 +0100 Subject: [PATCH] added and removed startup checks --- wifi.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/wifi.py b/wifi.py index 6f54750..8066af5 100755 --- a/wifi.py +++ b/wifi.py @@ -4,11 +4,11 @@ import subprocess as sp import sys import argparse +from shutil import which CFG = { "nmcli": { - #"device": "", "fields": ["ssid", "signal", "security", "chan", "rate", "mode", "bssid"], }, "rfkill": { @@ -16,8 +16,18 @@ CFG = { } } -if not CFG["nmcli"]["fields"][0].lower() == "ssid": - raise NotImplementedError("ssid must be the first element in fields, will hopefully be fixed in the future") +def _startup_check(): + #if not CFG["nmcli"]["fields"][0].lower() == "ssid": + # raise NotImplementedError("ssid must be the first element in fields, will hopefully be fixed in the future") + + binary_depencies = ["nmcli", "rfkill"] + gathered_missing = [] + for binary in binary_depencies: + if which(binary) is None: + gathered_missing.append(binary) + if gathered_missing: + raise OSError("missing the following binaries: " + str(gathered_missing).strip("[]")) + def _split_blocks(text: str) -> list: @@ -99,8 +109,8 @@ def connect(ssid: str) -> bool: def main(): + _startup_check() try: - ap = argparse.ArgumentParser() ap.add_argument("-j", "--json", help="just output current scanned wifi as json", action="store_true") args = ap.parse_args()