corrected flake8 warnings

This commit is contained in:
Krzysztof Koziarek 2015-10-24 11:20:57 +02:00
parent 29c9c5a7ec
commit 50fbd83b3d

View File

@ -49,7 +49,8 @@ class UbusDeviceScanner(object):
Read only access will be fine. Read only access will be fine.
To use this class you have to install rpcd-mod-file package in your OpenWrt router: To use this class you have to install rpcd-mod-file package
in your OpenWrt router:
opkg install rpcd-mod-file opkg install rpcd-mod-file
@ -84,15 +85,19 @@ class UbusDeviceScanner(object):
with self.lock: with self.lock:
if self.leasefile is None: if self.leasefile is None:
result = _req_json_rpc(self.url, self.session_id, 'call', 'uci', 'get', config="dhcp", type="dnsmasq") result = _req_json_rpc(self.url, self.session_id,
'call', 'uci', 'get',
config="dhcp", type="dnsmasq")
if result: if result:
self.leasefile=next (iter (result["values"].values()))["leasefile"] self.leasefile = next(iter(result["values"].
values()))["leasefile"]
else: else:
return return
if self.mac2name is None: if self.mac2name is None:
result = _req_json_rpc(self.url, self.session_id, 'call', 'file', 'read', path=self.leasefile) result = _req_json_rpc(self.url, self.session_id,
'call', 'file', 'read',
path=self.leasefile)
if result: if result:
self.mac2name = dict() self.mac2name = dict()
for line in result["data"].splitlines(): for line in result["data"].splitlines():
@ -117,14 +122,16 @@ class UbusDeviceScanner(object):
_LOGGER.info("Checking ARP") _LOGGER.info("Checking ARP")
if not self.hostapd: if not self.hostapd:
hostapd = _req_json_rpc(self.url, self.session_id, 'list', 'hostapd.*', '') hostapd = _req_json_rpc(self.url, self.session_id,
'list', 'hostapd.*', '')
for key in hostapd.keys(): for key in hostapd.keys():
self.hostapd.append(key) self.hostapd.append(key)
self.last_results = [] self.last_results = []
results = 0 results = 0
for hostapd in self.hostapd: for hostapd in self.hostapd:
result = _req_json_rpc(self.url, self.session_id, 'call', hostapd, 'get_clients') result = _req_json_rpc(self.url, self.session_id,
'call', hostapd, 'get_clients')
if result: if result:
results = results + 1 results = results + 1
@ -136,6 +143,7 @@ class UbusDeviceScanner(object):
else: else:
return False return False
def _req_json_rpc(url, session_id, rpcmethod, subsystem, method, **params): def _req_json_rpc(url, session_id, rpcmethod, subsystem, method, **params):
""" Perform one JSON RPC operation. """ """ Perform one JSON RPC operation. """
@ -162,10 +170,10 @@ def _req_json_rpc(url, session_id, rpcmethod, subsystem, method, **params):
else: else:
return response["result"] return response["result"]
def _get_session_id(url, username, password): def _get_session_id(url, username, password):
""" Get authentication token for the given host+username+password. """ """ Get authentication token for the given host+username+password. """
res = _req_json_rpc(url, "00000000000000000000000000000000", 'call', 'session', 'login', username=username, password=password) res = _req_json_rpc(url, "00000000000000000000000000000000", 'call',
'session', 'login', username=username,
password=password)
return res["ubus_rpc_session"] return res["ubus_rpc_session"]
# root@dom:~# ubus call uci get '{ "config": "dhcp", "type": "dnsmasq" }'