...
 
Commits (2)
......@@ -8,12 +8,7 @@ stdenv.mkDerivation rec {
src = ./.;
postPatch = ''
substituteInPlace Makefile \
--replace "\$(shell git describe)" ${version}
'';
installFlags = [ "PREFIX=$(out)" ];
installFlags = [ "PREFIX=$(out)" "VERSION=${version}" ];
dontBuild = true;
buildInputs = [ python3 git ];
......
......@@ -4,7 +4,7 @@ from argparse import ArgumentParser
from subprocess import run, PIPE, CalledProcessError
from shutil import which
from sys import exit, stdout, argv
from typing import Optional, List, Dict
from typing import Optional, List, Dict, Any
from re import sub
import os
......@@ -15,16 +15,16 @@ def colorize(code: int, content: str) -> str:
return content
def match_property(name: str, line: str, prefix: int = 20) -> Optional[str]:
prefixStr = "{0}{1}:".format(' ' * prefix, name)
def match_property(name: str, line: str, prefix: int = 20, delim: str = ":") -> Optional[str]:
prefixStr = "{0}{1}{2}".format(' ' * prefix, name, delim)
if prefixStr in line:
return sub(r'^"(.*)"$', r"\1", line.split(prefixStr, 1)[1])
return None
def gather_wireless_info(output: List[str]) -> List[Dict[str, str]]:
networks: List[Dict[str, str]] = []
current_object: Dict[str, str] = {}
def gather_wireless_info(output: List[str]) -> List[Dict[str, Any]]:
networks: List[Dict[str, Any]] = []
current_object: Dict[str, Any] = {}
first_found: bool = False
for line in output:
if "{0}Cell".format(' ' * 10) in line:
......@@ -46,6 +46,11 @@ def gather_wireless_info(output: List[str]) -> List[Dict[str, str]]:
auth_suites = match_property("Authentication Suites (1) ", line, 24)
if auth_suites is not None:
current_object["auth"] = colorize(1, auth_suites[1:])
quality = match_property("Quality", line, 20, "=")
if quality is not None:
expression = quality.split(" ", 1)[0]
left, right = expression.split("/", 1)
current_object["quality"] = int(int(left) / int(right) * 100)
if current_object != {}:
networks.append(current_object)
......@@ -135,7 +140,8 @@ def main() -> None:
current_indicator = " "
wifi_dns = " "
print(f"{current_indicator} {colorize(1, colorize(32, 'Network'))}: {colorize(32, n['ssid'])}")
print(f"{current_indicator} {colorize(1, colorize(32, 'Network'))}: "
+ f"{colorize(32, n['ssid'])} ({colorize(1, n['quality'])}%)")
print(f" {colorize(1, 'Secured')}: {n['enc']} ({n['auth']})")
if current_indicator != " ":
......