From fa9feec61964d2720b989ba11c25b7a91fa216a8 Mon Sep 17 00:00:00 2001 From: Darryl Lee Date: Thu, 25 Feb 2016 20:57:18 -0800 Subject: [PATCH 1/2] Fix for Quality/Signal level output variations As mentioned in https://github.com/KanoComputing/kano-toolset/issues/198, the format of Quality and Signal level changes when iwlist cannot get a range for some Access Points (or perhaps it's related to the wireless driver). At any rate, I've observed a 2Wire/AT&T U-verse router showing: `Quality:40 Signal level:0 Noise level:0` The original parser only accounts for Quality/Signal level in this format: `Quality=72/100 Signal level=65/100` This change accommodates the possibility of for a colon in addition to an equals sign, and also can handle an integer value for Quality as opposed to a fraction. --- kano/network.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/kano/network.py b/kano/network.py index 00f9cd2..a05cb6a 100755 --- a/kano/network.py +++ b/kano/network.py @@ -131,7 +131,7 @@ def getCellEncryption(s): return s.strip().split(":")[1] def getCellSignal(s): - s = s.split("Signal level=")[1] + s = re.split('Signal level(=|:)', s)[2] return s.strip().split(" ")[0] def getCellNoise(s): @@ -142,7 +142,7 @@ def getCellNoise(s): return 0 def getCellQuality(s): - s = s.split("=")[1] + s = re.split('(=|:)', s)[2] return s.strip().split(" ")[0] def getCellMAC(s): @@ -177,7 +177,7 @@ def getCellMode(s): if s.strip().startswith("Frequency:"): cellData["Frequency"] = getCellFrequency(s) cellData["Channel"] = getCellChannel(s) - if s.strip().startswith("Quality="): + if s.strip().startswith("Quality"): cellData["Quality"] = getCellQuality(s) cellData["Signal"] = getCellSignal(s) cellData["Noise"] = getCellNoise(s) @@ -233,8 +233,11 @@ def getList(self, unsecure=False, first=False, debug=False): ''' def sortNetworks(adict): - x, z = adict['quality'].split('/') - factor = int(x) / float(z) + if '/' in adict['quality']: + x, z = adict['quality'].split('/') + factor = int(x) / float(z) + else: + factor = int(adict['quality']) / 100 return factor def add_wnet(wlist, new_wnet): From 4dd0223fb11defb9cc0c8d0e48d4969209e1ce3f Mon Sep 17 00:00:00 2001 From: Darryl Lee Date: Fri, 26 Feb 2016 09:16:16 -0800 Subject: [PATCH 2/2] Fix to make sure factor gets computed via float division Let's make sure factor doesn't just result in 0 or 1. --- kano/network.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kano/network.py b/kano/network.py index a05cb6a..ff3e77a 100755 --- a/kano/network.py +++ b/kano/network.py @@ -237,7 +237,7 @@ def sortNetworks(adict): x, z = adict['quality'].split('/') factor = int(x) / float(z) else: - factor = int(adict['quality']) / 100 + factor = float(int(adict['quality'])) / 100 return factor def add_wnet(wlist, new_wnet):