Added option to get the ssid (for wifi networks)

This commit is contained in:
Kunal Shetye 2018-04-11 20:42:12 +02:00
parent b23b97625e
commit fb6a9b1f7d

View file

@ -5,11 +5,12 @@
Parameters: Parameters:
* nic.exclude: Comma-separated list of interface prefixes to exclude (defaults to "lo,virbr,docker,vboxnet,veth") * 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.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: try:
import netifaces import netifaces
import subprocess
except ImportError: except ImportError:
pass pass
@ -32,7 +33,7 @@ class Module(bumblebee.engine.Module):
self._states["exclude"].append(state[1:]) self._states["exclude"].append(state[1:])
else: else:
self._states["include"].append(state) 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) self._update_widgets(widgets)
def update(self, widgets): def update(self, widgets):
@ -92,12 +93,7 @@ class Module(bumblebee.engine.Module):
if not widget: if not widget:
widget = bumblebee.output.Widget(name=intf) widget = bumblebee.output.Widget(name=intf)
widgets.append(widget) widgets.append(widget)
widget.full_text(self._format.format( widget.full_text(self._format.format(ip=", ".join(addr),intf=intf,state=state,ssid=self.get_ssid(intf)))
**{
"intf": intf,
"state": state,
"ip": ", ".join(addr)
}))
widget.set("intf", intf) widget.set("intf", intf)
widget.set("state", state) widget.set("state", state)
widget.set("visited", True) widget.set("visited", True)
@ -106,4 +102,12 @@ class Module(bumblebee.engine.Module):
if widget.get("visited") == False: if widget.get("visited") == False:
widgets.remove(widget) 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 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4