[modules/traffic] Update to new API
This commit is contained in:
parent
f46796c653
commit
c998af5649
1 changed files with 20 additions and 18 deletions
|
@ -18,26 +18,28 @@ import time
|
||||||
import psutil
|
import psutil
|
||||||
import netifaces
|
import netifaces
|
||||||
|
|
||||||
import bumblebee.util
|
import core.module
|
||||||
import bumblebee.input
|
import core.widget
|
||||||
import bumblebee.output
|
|
||||||
import bumblebee.engine
|
|
||||||
|
|
||||||
class Module(bumblebee.engine.Module):
|
import util.format
|
||||||
def __init__(self, engine, config):
|
import util.graph
|
||||||
|
|
||||||
|
class Module(core.module.Module):
|
||||||
|
def __init__(self, config):
|
||||||
widgets = []
|
widgets = []
|
||||||
super(Module, self).__init__(engine, config, widgets)
|
super().__init__(config, widgets)
|
||||||
self._exclude = tuple(filter(len, self.parameter('exclude', 'lo,virbr,docker,vboxnet,veth').split(',')))
|
|
||||||
|
self._exclude = tuple(filter(len, util.format.aslist(self.parameter('exclude', 'lo,virbr,docker,vboxnet,veth'))))
|
||||||
self._status = ''
|
self._status = ''
|
||||||
|
|
||||||
self._showname = bumblebee.util.asbool(self.parameter('showname', True))
|
self._showname = util.format.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, util.format.aslist(self.parameter('states', '')))):
|
||||||
if state[0] == '^':
|
if state[0] == '^':
|
||||||
self._states['exclude'].append(state[1:])
|
self._states['exclude'].append(state[1:])
|
||||||
else:
|
else:
|
||||||
|
@ -49,17 +51,17 @@ class Module(bumblebee.engine.Module):
|
||||||
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):
|
||||||
self._update_widgets(widgets)
|
self._update_widgets(self.widgets())
|
||||||
|
|
||||||
def create_widget(self, widgets, name, txt=None, attributes={}):
|
def create_widget(self, widgets, name, txt=None, attributes={}):
|
||||||
widget = bumblebee.output.Widget(name=name)
|
widget = core.widget.Widget(name=name, module=self)
|
||||||
widget.full_text(txt)
|
widget.full_text(txt)
|
||||||
widgets.append(widget)
|
widgets.append(widget)
|
||||||
|
|
||||||
|
@ -120,7 +122,7 @@ class Module(bumblebee.engine.Module):
|
||||||
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 util.format.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
|
||||||
|
@ -141,7 +143,7 @@ class Module(bumblebee.engine.Module):
|
||||||
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 = util.format.byte(bspeed, self._format)
|
||||||
txtspeed = '{0}/s'.format(speed)
|
txtspeed = '{0}/s'.format(speed)
|
||||||
if self._graphlen > 0:
|
if self._graphlen > 0:
|
||||||
# skip first value returned by psutil, because it is
|
# skip first value returned by psutil, because it is
|
||||||
|
@ -152,7 +154,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(util.graph.braille(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