Update code style
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import os, signal
|
||||
import os
|
||||
import signal
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
@@ -57,7 +58,7 @@ class WifiManager():
|
||||
self.soc = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
||||
self.soc.bind(KS_SOCKET_FILE)
|
||||
self.soc.connect("/var/run/wpa_supplicant/%s" % interface)
|
||||
except:
|
||||
except Exception:
|
||||
logging.info("Error connecting to wifi socket: %s" % interface)
|
||||
return
|
||||
|
||||
@@ -77,15 +78,15 @@ class WifiManager():
|
||||
def add_network(self, ssid, psk):
|
||||
for id in list(self.supplicant_networks):
|
||||
if self.supplicant_networks[id]['ssid'] == ssid:
|
||||
#Modify network
|
||||
# Modify network
|
||||
return
|
||||
|
||||
# TODO: Add wpa_cli error checking
|
||||
network_id = self.wpa_cli("ADD_NETWORK")
|
||||
commands = [
|
||||
'ENABLE_NETWORK %s' % (network_id),
|
||||
'SET_NETWORK %s ssid "%s"' % (network_id, ssid.replace('"','\"')),
|
||||
'SET_NETWORK %s psk "%s"' % (network_id, psk.replace('"','\"'))
|
||||
'SET_NETWORK %s ssid "%s"' % (network_id, ssid.replace('"', '\"')),
|
||||
'SET_NETWORK %s psk "%s"' % (network_id, psk.replace('"', '\"'))
|
||||
]
|
||||
self.wpa_cli_batch(commands)
|
||||
|
||||
@@ -96,7 +97,7 @@ class WifiManager():
|
||||
id = i
|
||||
break
|
||||
|
||||
if id == None:
|
||||
if id is None:
|
||||
logging.info("Error adding network")
|
||||
return False
|
||||
|
||||
@@ -118,7 +119,7 @@ class WifiManager():
|
||||
id = netid
|
||||
break
|
||||
|
||||
if id == None:
|
||||
if id is None:
|
||||
logging.info("Wifi network is not defined in wpa_supplicant")
|
||||
return False
|
||||
|
||||
@@ -134,7 +135,7 @@ class WifiManager():
|
||||
id = i
|
||||
break
|
||||
|
||||
if id == None:
|
||||
if id is None:
|
||||
logging.debug("Unable to find network in wpa_supplicant")
|
||||
return
|
||||
self.wpa_cli("REMOVE_NETWORK %s" % id)
|
||||
@@ -243,7 +244,7 @@ class WifiManager():
|
||||
|
||||
aps = []
|
||||
for res in results:
|
||||
match = re.match("^([a-f0-9:]+)\s+([0-9]+)\s+([\-0-9]+)\s+(\S+)\s+(.+)?", res)
|
||||
match = re.match("^([a-f0-9:]+)\\s+([0-9]+)\\s+([\\-0-9]+)\\s+(\\S+)\\s+(.+)?", res)
|
||||
if match:
|
||||
net = {
|
||||
"mac": match.group(1),
|
||||
@@ -286,10 +287,10 @@ class WifiManager():
|
||||
cb, new_networks, deleted_networks)
|
||||
|
||||
def wpa_cli(self, command, wait=True):
|
||||
if wait == False:
|
||||
if wait is False:
|
||||
self.wpa_thread.skip_command()
|
||||
self.soc.send(command.encode())
|
||||
if wait == True:
|
||||
if wait is True:
|
||||
resp = self.queue.get()
|
||||
return resp
|
||||
|
||||
@@ -299,7 +300,7 @@ class WifiManager():
|
||||
|
||||
|
||||
class WpaSocket(Thread):
|
||||
def __init__ (self, wm, queue, callback):
|
||||
def __init__(self, wm, queue, callback):
|
||||
super().__init__()
|
||||
self.queue = queue
|
||||
self.callback = callback
|
||||
@@ -311,10 +312,10 @@ class WpaSocket(Thread):
|
||||
def run(self):
|
||||
event = threading.Event()
|
||||
logging.debug("Setting up wifi event loop")
|
||||
while self._stop_loop == False:
|
||||
while self._stop_loop is False:
|
||||
try:
|
||||
msg = self.soc.recv(4096).decode().strip()
|
||||
except:
|
||||
except Exception:
|
||||
# TODO: Socket error
|
||||
continue
|
||||
if msg.startswith("<"):
|
||||
@@ -322,7 +323,7 @@ class WpaSocket(Thread):
|
||||
Gdk.threads_add_idle(GLib.PRIORITY_DEFAULT_IDLE, self.wm.scan_results)
|
||||
elif "CTRL-EVENT-DISCONNECTED" in msg:
|
||||
self.callback("connecting_status", msg)
|
||||
match = re.match('<3>CTRL-EVENT-DISCONNECTED bssid=(\S+) reason=3 locally_generated=1', msg)
|
||||
match = re.match('<3>CTRL-EVENT-DISCONNECTED bssid=(\\S+) reason=3 locally_generated=1', msg)
|
||||
if match:
|
||||
for net in self.wm.networks:
|
||||
if self.wm.networks[net]['mac'] == match.group(1):
|
||||
@@ -353,117 +354,117 @@ class WifiChannels:
|
||||
@staticmethod
|
||||
def lookup(freq):
|
||||
if freq == "2412":
|
||||
return ("2.4","1")
|
||||
return ("2.4", "1")
|
||||
if freq == "2417":
|
||||
return ("2.4","2")
|
||||
return ("2.4", "2")
|
||||
if freq == "2422":
|
||||
return ("2.4","3")
|
||||
return ("2.4", "3")
|
||||
if freq == "2427":
|
||||
return ("2.4","4")
|
||||
return ("2.4", "4")
|
||||
if freq == "2432":
|
||||
return ("2.4","5")
|
||||
return ("2.4", "5")
|
||||
if freq == "2437":
|
||||
return ("2.4","6")
|
||||
return ("2.4", "6")
|
||||
if freq == "2442":
|
||||
return ("2.4","7")
|
||||
return ("2.4", "7")
|
||||
if freq == "2447":
|
||||
return ("2.4","8")
|
||||
return ("2.4", "8")
|
||||
if freq == "2452":
|
||||
return ("2.4","9")
|
||||
return ("2.4", "9")
|
||||
if freq == "2457":
|
||||
return ("2.4","10")
|
||||
return ("2.4", "10")
|
||||
if freq == "2462":
|
||||
return ("2.4","11")
|
||||
return ("2.4", "11")
|
||||
if freq == "2467":
|
||||
return ("2.4","12")
|
||||
return ("2.4", "12")
|
||||
if freq == "2472":
|
||||
return ("2.4","13")
|
||||
return ("2.4", "13")
|
||||
if freq == "2484":
|
||||
return ("2.4","14")
|
||||
return ("2.4", "14")
|
||||
if freq == "5035":
|
||||
return ("5","7")
|
||||
return ("5", "7")
|
||||
if freq == "5040":
|
||||
return ("5","8")
|
||||
return ("5", "8")
|
||||
if freq == "5045":
|
||||
return ("5","9")
|
||||
return ("5", "9")
|
||||
if freq == "5055":
|
||||
return ("5","11")
|
||||
return ("5", "11")
|
||||
if freq == "5060":
|
||||
return ("5","12")
|
||||
return ("5", "12")
|
||||
if freq == "5080":
|
||||
return ("5","16")
|
||||
return ("5", "16")
|
||||
if freq == "5170":
|
||||
return ("5","34")
|
||||
return ("5", "34")
|
||||
if freq == "5180":
|
||||
return ("5","36")
|
||||
return ("5", "36")
|
||||
if freq == "5190":
|
||||
return ("5","38")
|
||||
return ("5", "38")
|
||||
if freq == "5200":
|
||||
return ("5","40")
|
||||
return ("5", "40")
|
||||
if freq == "5210":
|
||||
return ("5","42")
|
||||
return ("5", "42")
|
||||
if freq == "5220":
|
||||
return ("5","44")
|
||||
return ("5", "44")
|
||||
if freq == "5230":
|
||||
return ("5","46")
|
||||
return ("5", "46")
|
||||
if freq == "5240":
|
||||
return ("5","48")
|
||||
return ("5", "48")
|
||||
if freq == "5260":
|
||||
return ("5","52")
|
||||
return ("5", "52")
|
||||
if freq == "5280":
|
||||
return ("5","56")
|
||||
return ("5", "56")
|
||||
if freq == "5300":
|
||||
return ("5","60")
|
||||
return ("5", "60")
|
||||
if freq == "5320":
|
||||
return ("5","64")
|
||||
return ("5", "64")
|
||||
if freq == "5500":
|
||||
return ("5","100")
|
||||
return ("5", "100")
|
||||
if freq == "5520":
|
||||
return ("5","104")
|
||||
return ("5", "104")
|
||||
if freq == "5540":
|
||||
return ("5","108")
|
||||
return ("5", "108")
|
||||
if freq == "5560":
|
||||
return ("5","112")
|
||||
return ("5", "112")
|
||||
if freq == "5580":
|
||||
return ("5","116")
|
||||
return ("5", "116")
|
||||
if freq == "5600":
|
||||
return ("5","120")
|
||||
return ("5", "120")
|
||||
if freq == "5620":
|
||||
return ("5","124")
|
||||
return ("5", "124")
|
||||
if freq == "5640":
|
||||
return ("5","128")
|
||||
return ("5", "128")
|
||||
if freq == "5660":
|
||||
return ("5","132")
|
||||
return ("5", "132")
|
||||
if freq == "5680":
|
||||
return ("5","136")
|
||||
return ("5", "136")
|
||||
if freq == "5700":
|
||||
return ("5","140")
|
||||
return ("5", "140")
|
||||
if freq == "5720":
|
||||
return ("5","144")
|
||||
return ("5", "144")
|
||||
if freq == "5745":
|
||||
return ("5","149")
|
||||
return ("5", "149")
|
||||
if freq == "5765":
|
||||
return ("5","153")
|
||||
return ("5", "153")
|
||||
if freq == "5785":
|
||||
return ("5","157")
|
||||
return ("5", "157")
|
||||
if freq == "5805":
|
||||
return ("5","161")
|
||||
return ("5", "161")
|
||||
if freq == "5825":
|
||||
return ("5","165")
|
||||
return ("5", "165")
|
||||
if freq == "4915":
|
||||
return ("5","183")
|
||||
return ("5", "183")
|
||||
if freq == "4920":
|
||||
return ("5","184")
|
||||
return ("5", "184")
|
||||
if freq == "4925":
|
||||
return ("5","185")
|
||||
return ("5", "185")
|
||||
if freq == "4935":
|
||||
return ("5","187")
|
||||
return ("5", "187")
|
||||
if freq == "4940":
|
||||
return ("5","188")
|
||||
return ("5", "188")
|
||||
if freq == "4945":
|
||||
return ("5","189")
|
||||
return ("5", "189")
|
||||
if freq == "4960":
|
||||
return ("5","192")
|
||||
return ("5", "192")
|
||||
if freq == "4980":
|
||||
return ("5","196")
|
||||
return None;
|
||||
return ("5", "196")
|
||||
return None
|
||||
|
Reference in New Issue
Block a user