11""" Network Manager CLI (nmcli) functions """
22
3- from __future__ import annotations
4- import typing as T
53import subprocess
64import logging
7- import pandas
85import io
96from time import sleep
107
11- from .cmd import get_nmcli
8+ import pandas
9+
10+ from .exe import get_exe
1211
1312
1413def cli_config_check () -> bool :
1514 # %% check that NetworkManager CLI is available and WiFi is active
15+ exe = get_exe ("nmcli" )
1616
1717 try :
18- ret = subprocess .check_output ([get_nmcli () , "-t" , "radio" , "wifi" ], text = True , timeout = 2 )
18+ ret = subprocess .check_output ([exe , "-t" , "radio" , "wifi" ], text = True , timeout = 2 )
1919 except subprocess .CalledProcessError as err :
2020 logging .error (err )
2121 return False
@@ -36,7 +36,9 @@ def cli_config_check() -> bool:
3636
3737
3838def get_signal () -> str :
39- cmd = [get_nmcli (), "-g" , "SSID,BSSID,FREQ,SIGNAL" , "device" , "wifi" ]
39+ exe = get_exe ("nmcli" )
40+
41+ cmd = [exe , "-g" , "SSID,BSSID,FREQ,SIGNAL" , "device" , "wifi" ]
4042 # Debian stretch, Ubuntu 18.04
4143 # cmd = [EXE, "-t", "-f", "SSID,BSSID,FREQ,SIGNAL", "device", "wifi"]
4244 # ubuntu 16.04
@@ -49,7 +51,7 @@ def get_signal() -> str:
4951 sleep (0.5 ) # nmcli errored for less than about 0.2 sec.
5052 # takes several seconds to update, so do it now.
5153
52- scan = [get_nmcli () , "device" , "wifi" , "rescan" ]
54+ scan = [exe , "device" , "wifi" , "rescan" ]
5355
5456 try :
5557 ret = subprocess .check_output (scan , timeout = 1.0 , text = True )
@@ -59,7 +61,7 @@ def get_signal() -> str:
5961 return ret
6062
6163
62- def parse_signal (raw : str ) -> list [ dict [ str , T . Any ]] :
64+ def parse_signal (raw : str ) -> pandas . DataFrame :
6365 dat = pandas .read_csv (
6466 io .StringIO (raw ),
6567 sep = r"(?<!\\):" ,
0 commit comments