[modules/traffic] update quotes
This commit is contained in:
parent
605b3bc20b
commit
008f0dc4f2
1 changed files with 42 additions and 42 deletions
|
@ -3,11 +3,11 @@
|
||||||
"""Displays network IO for interfaces.
|
"""Displays network IO for interfaces.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
* traffic.exclude: Comma-separated list of interface prefixes to exclude (defaults to "lo,virbr,docker,vboxnet,veth")
|
* traffic.exclude: Comma-separated list of interface prefixes to exclude (defaults to 'lo,virbr,docker,vboxnet,veth')
|
||||||
* traffic.states: Comma-separated list of states to show (prefix with "^" to invert - i.e. ^down -> show all devices that are not in state down)
|
* traffic.states: Comma-separated list of states to show (prefix with '^' to invert - i.e. ^down -> show all devices that are not in state down)
|
||||||
* traffic.showname: If set to False, hide network interface name (defaults to True)
|
* traffic.showname: If set to False, hide network interface name (defaults to True)
|
||||||
* traffic.format: Format string for download/upload speeds.
|
* traffic.format: Format string for download/upload speeds.
|
||||||
Defaults to "{:.2f}"
|
Defaults to '{:.2f}'
|
||||||
* traffic.graphlen: Graph lenth in seconds. Positive even integer. Each
|
* traffic.graphlen: Graph lenth in seconds. Positive even integer. Each
|
||||||
char shows 2 seconds. If set, enables up/down traffic
|
char shows 2 seconds. If set, enables up/down traffic
|
||||||
graphs
|
graphs
|
||||||
|
@ -27,32 +27,32 @@ class Module(bumblebee.engine.Module):
|
||||||
def __init__(self, engine, config):
|
def __init__(self, engine, config):
|
||||||
widgets = []
|
widgets = []
|
||||||
super(Module, self).__init__(engine, config, widgets)
|
super(Module, self).__init__(engine, config, widgets)
|
||||||
self._exclude = tuple(filter(len, self.parameter("exclude", "lo,virbr,docker,vboxnet,veth").split(",")))
|
self._exclude = tuple(filter(len, self.parameter('exclude', 'lo,virbr,docker,vboxnet,veth').split(',')))
|
||||||
self._status = ""
|
self._status = ''
|
||||||
|
|
||||||
self._showname = bumblebee.util.asbool(self.parameter("showname", True))
|
self._showname = bumblebee.util.asbool(self.parameter('showname', True))
|
||||||
self._format = self.parameter("format", "{:.2f}")
|
self._format = self.parameter('format', '{:.2f}')
|
||||||
self._prev = {}
|
self._prev = {}
|
||||||
self._states = {}
|
self._states = {}
|
||||||
self._lastcheck = 0
|
self._lastcheck = 0
|
||||||
self._states["include"] = []
|
self._states['include'] = []
|
||||||
self._states["exclude"] = []
|
self._states['exclude'] = []
|
||||||
for state in tuple(filter(len, self.parameter("states", "").split(","))):
|
for state in tuple(filter(len, self.parameter('states', '').split(','))):
|
||||||
if state[0] == "^":
|
if state[0] == '^':
|
||||||
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._graphlen = int(self.parameter("graphlen", 0))
|
self._graphlen = int(self.parameter('graphlen', 0))
|
||||||
if self._graphlen > 0:
|
if self._graphlen > 0:
|
||||||
self._graphdata = {}
|
self._graphdata = {}
|
||||||
self._first_run = True
|
self._first_run = True
|
||||||
self._update_widgets(widgets)
|
self._update_widgets(widgets)
|
||||||
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
if "traffic.rx" in widget.name:
|
if 'traffic.rx' in widget.name:
|
||||||
return "rx"
|
return 'rx'
|
||||||
if "traffic.tx" in widget.name:
|
if 'traffic.tx' in widget.name:
|
||||||
return "tx"
|
return 'tx'
|
||||||
return self._status
|
return self._status
|
||||||
|
|
||||||
def update(self, widgets):
|
def update(self, widgets):
|
||||||
|
@ -72,8 +72,8 @@ class Module(bumblebee.engine.Module):
|
||||||
retval = []
|
retval = []
|
||||||
try:
|
try:
|
||||||
for ip in netifaces.ifaddresses(intf).get(netifaces.AF_INET, []):
|
for ip in netifaces.ifaddresses(intf).get(netifaces.AF_INET, []):
|
||||||
if ip.get("addr", "") != "":
|
if ip.get('addr', '') != '':
|
||||||
retval.append(ip.get("addr"))
|
retval.append(ip.get('addr'))
|
||||||
except Exception:
|
except Exception:
|
||||||
return []
|
return []
|
||||||
return retval
|
return retval
|
||||||
|
@ -83,21 +83,21 @@ class Module(bumblebee.engine.Module):
|
||||||
computes theme.minwidth string
|
computes theme.minwidth string
|
||||||
based on traffic.format and traffic.graphlen parameters
|
based on traffic.format and traffic.graphlen parameters
|
||||||
"""
|
"""
|
||||||
minwidth_str = ""
|
minwidth_str = ''
|
||||||
if self._graphlen > 0:
|
if self._graphlen > 0:
|
||||||
graph_len = int(self._graphlen / 2)
|
graph_len = int(self._graphlen / 2)
|
||||||
graph_prefix = "0" * graph_len
|
graph_prefix = '0' * graph_len
|
||||||
minwidth_str += graph_prefix
|
minwidth_str += graph_prefix
|
||||||
minwidth_str += "1000"
|
minwidth_str += '1000'
|
||||||
try:
|
try:
|
||||||
length = int(re.match("{:\.(\d+)f}", self._format).group(1))
|
length = int(re.match('{:\.(\d+)f}', self._format).group(1))
|
||||||
if length > 0:
|
if length > 0:
|
||||||
minwidth_str += "." + "0" * length
|
minwidth_str += '.' + '0' * length
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# return default value
|
# return default value
|
||||||
return "1000.00KiB/s"
|
return '1000.00KiB/s'
|
||||||
finally:
|
finally:
|
||||||
minwidth_str += "KiB/s"
|
minwidth_str += 'KiB/s'
|
||||||
return minwidth_str
|
return minwidth_str
|
||||||
|
|
||||||
def _update_widgets(self, widgets):
|
def _update_widgets(self, widgets):
|
||||||
|
@ -114,31 +114,31 @@ class Module(bumblebee.engine.Module):
|
||||||
if self._graphlen > 0:
|
if self._graphlen > 0:
|
||||||
if interface not in self._graphdata:
|
if interface not in self._graphdata:
|
||||||
self._graphdata[interface] = {
|
self._graphdata[interface] = {
|
||||||
"rx": [0] * self._graphlen,
|
'rx': [0] * self._graphlen,
|
||||||
"tx": [0] * self._graphlen}
|
'tx': [0] * self._graphlen}
|
||||||
if not interface: interface = "lo"
|
if not interface: interface = 'lo'
|
||||||
state = "down"
|
state = 'down'
|
||||||
if len(self.get_addresses(interface)) > 0:
|
if len(self.get_addresses(interface)) > 0:
|
||||||
state = "up"
|
state = 'up'
|
||||||
elif bumblebee.util.asbool(self.parameter("hide_down", True)):
|
elif bumblebee.util.asbool(self.parameter('hide_down', True)):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if len(self._states["exclude"]) > 0 and state in self._states["exclude"]: continue
|
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
|
if len(self._states['include']) > 0 and state not in self._states['include']: continue
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"rx": counters[interface].bytes_recv,
|
'rx': counters[interface].bytes_recv,
|
||||||
"tx": counters[interface].bytes_sent,
|
'tx': counters[interface].bytes_sent,
|
||||||
}
|
}
|
||||||
|
|
||||||
name = "traffic-{}".format(interface)
|
name = 'traffic-{}'.format(interface)
|
||||||
|
|
||||||
if self._showname:
|
if self._showname:
|
||||||
self.create_widget(widgets, name, interface)
|
self.create_widget(widgets, name, interface)
|
||||||
|
|
||||||
for direction in ["rx", "tx"]:
|
for direction in ['rx', 'tx']:
|
||||||
name = "traffic.{}-{}".format(direction, interface)
|
name = 'traffic.{}-{}'.format(direction, interface)
|
||||||
widget = self.create_widget(widgets, name, attributes={"theme.minwidth": self.get_minwidth_str()})
|
widget = self.create_widget(widgets, name, attributes={'theme.minwidth': self.get_minwidth_str()})
|
||||||
prev = self._prev.get(name, 0)
|
prev = self._prev.get(name, 0)
|
||||||
bspeed = (int(data[direction]) - int(prev))/timediff
|
bspeed = (int(data[direction]) - int(prev))/timediff
|
||||||
speed = bumblebee.util.bytefmt(bspeed, self._format)
|
speed = bumblebee.util.bytefmt(bspeed, self._format)
|
||||||
|
@ -152,7 +152,7 @@ class Module(bumblebee.engine.Module):
|
||||||
else:
|
else:
|
||||||
self._graphdata[interface][direction] = self._graphdata[interface][direction][1:]
|
self._graphdata[interface][direction] = self._graphdata[interface][direction][1:]
|
||||||
self._graphdata[interface][direction].append(bspeed)
|
self._graphdata[interface][direction].append(bspeed)
|
||||||
txtspeed = "{}{}".format(bumblebee.output.bgraph(self._graphdata[interface][direction]), txtspeed)
|
txtspeed = '{}{}'.format(bumblebee.output.bgraph(self._graphdata[interface][direction]), txtspeed)
|
||||||
widget.full_text(txtspeed)
|
widget.full_text(txtspeed)
|
||||||
self._prev[name] = data[direction]
|
self._prev[name] = data[direction]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue