Merge pull request #246 from kunalshetye/master
[module/nic] Added option to get the ssid (for wifi networks)
This commit is contained in:
commit
0fa27cca10
1 changed files with 14 additions and 10 deletions
|
@ -5,11 +5,12 @@
|
|||
Parameters:
|
||||
* nic.exclude: Comma-separated list of interface prefixes to exclude (defaults to "lo,virbr,docker,vboxnet,veth")
|
||||
* nic.states: Comma-separated list of states to show (prefix with "^" to invert - i.e. ^down -> show all devices that are not in state down)
|
||||
* nic.format: Format string (defaults to "{intf} {state} {ip}")
|
||||
* nic.format: Format string (defaults to "{intf} {state} {ip} {ssid}")
|
||||
"""
|
||||
|
||||
try:
|
||||
import netifaces
|
||||
import subprocess
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
@ -32,7 +33,7 @@ class Module(bumblebee.engine.Module):
|
|||
self._states["exclude"].append(state[1:])
|
||||
else:
|
||||
self._states["include"].append(state)
|
||||
self._format = self.parameter("format","{intf} {state} {ip}");
|
||||
self._format = self.parameter("format","{intf} {state} {ip} {ssid}");
|
||||
self._update_widgets(widgets)
|
||||
|
||||
def update(self, widgets):
|
||||
|
@ -71,7 +72,7 @@ class Module(bumblebee.engine.Module):
|
|||
except Exception:
|
||||
return []
|
||||
return retval
|
||||
|
||||
|
||||
def _update_widgets(self, widgets):
|
||||
interfaces = [i for i in netifaces.interfaces() if not i.startswith(self._exclude)]
|
||||
|
||||
|
@ -87,17 +88,12 @@ class Module(bumblebee.engine.Module):
|
|||
|
||||
if len(self._states["exclude"]) > 0 and state in self._states["exclude"]: continue
|
||||
if len(self._states["include"]) > 0 and state not in self._states["include"]: continue
|
||||
|
||||
|
||||
widget = self.widget(intf)
|
||||
if not widget:
|
||||
widget = bumblebee.output.Widget(name=intf)
|
||||
widgets.append(widget)
|
||||
widget.full_text(self._format.format(
|
||||
**{
|
||||
"intf": intf,
|
||||
"state": state,
|
||||
"ip": ", ".join(addr)
|
||||
}))
|
||||
widget.full_text(self._format.format(ip=", ".join(addr),intf=intf,state=state,ssid=self.get_ssid(intf)))
|
||||
widget.set("intf", intf)
|
||||
widget.set("state", state)
|
||||
widget.set("visited", True)
|
||||
|
@ -105,5 +101,13 @@ class Module(bumblebee.engine.Module):
|
|||
for widget in widgets:
|
||||
if widget.get("visited") == False:
|
||||
widgets.remove(widget)
|
||||
|
||||
def get_ssid(self, intf):
|
||||
if self._iswlan(intf):
|
||||
try:
|
||||
return subprocess.check_output(["iwgetid","-r",intf]).strip().decode('utf-8')
|
||||
except subprocess.CalledProcessError:
|
||||
return ""
|
||||
return ""
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
Loading…
Reference in a new issue