Merge branch 'master' of git://github.com/dnfm/bumblebee-status into dnfm-master

This commit is contained in:
Tobias Witek 2017-06-15 07:42:05 +02:00
commit df6e323fa4
4 changed files with 56 additions and 5 deletions

View file

@ -30,6 +30,11 @@ def get_rtt(module, widget):
)) ))
for line in res.split("\n"): for line in res.split("\n"):
if line.startswith( "{} packets transmitted".format( widget.get( "rtt-probes" ) ) ):
m = re.search( r'(\d+)% packet loss', line )
widget.set( 'packet-loss', m.group(1) )
if not line.startswith("rtt"): continue if not line.startswith("rtt"): continue
m = re.search(r'([0-9\.]+)/([0-9\.]+)/([0-9\.]+)/([0-9\.]+)\s+(\S+)', line) m = re.search(r'([0-9\.]+)/([0-9\.]+)/([0-9\.]+)/([0-9\.]+)\s+(\S+)', line)
@ -51,16 +56,18 @@ class Module(bumblebee.engine.Module):
widget.set("rtt-timeout", self.parameter("timeout", 5.0)) widget.set("rtt-timeout", self.parameter("timeout", 5.0))
widget.set("rtt-avg", 0.0) widget.set("rtt-avg", 0.0)
widget.set("rtt-unit", "") widget.set("rtt-unit", "")
widget.set('packet-loss', 0)
self._next_check = 0 self._next_check = 0
def rtt(self, widget): def rtt(self, widget):
if widget.get("rtt-unreachable"): if widget.get("rtt-unreachable"):
return "{}: unreachable".format(widget.get("address")) return "{}: unreachable".format(widget.get("address"))
return "{}: {:.1f}{}".format( return "{}: {:.1f}{} ({}%)".format(
widget.get("address"), widget.get("address"),
widget.get("rtt-avg"), widget.get("rtt-avg"),
widget.get("rtt-unit") widget.get("rtt-unit"),
widget.get( 'packet-loss' )
) )
def state(self, widget): def state(self, widget):

View file

@ -11,6 +11,9 @@ Parameters:
""" """
import re import re
import decimal
from subprocess import call
import bumblebee.input import bumblebee.input
import bumblebee.output import bumblebee.output
@ -36,10 +39,21 @@ class Module(bumblebee.engine.Module):
return temperature return temperature
def get_mhz( self ):
output = open( '/proc/cpuinfo' ).read()
m = re.search( r"cpu MHz\s+:\s+(\d+)", output )
mhz = int( m.group( 1 ) )
if mhz < 1000:
return "{} MHz".format( mhz )
else:
return "%.1f GHz" % ( decimal.Decimal( mhz ) / 1000 )
def temperature(self, _): def temperature(self, _):
return self._temperature return u"{}°c @ {}".format( self._temperature, self._mhz )
def update(self, widgets): def update(self, widgets):
self._temperature = self.get_temp() self._temperature = self.get_temp()
self._mhz = self.get_mhz()
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -51,6 +51,27 @@ class Module(bumblebee.engine.Module):
return u"?" return u"?"
return u"{}°{}".format(self._temperature, self._unit_suffix()) return u"{}°{}".format(self._temperature, self._unit_suffix())
def state( self, widget ):
if self._valid:
if "thunderstorm" in self._weather:
return [ 'thunder' ]
elif "drizzle" in self._weather:
return [ 'rain' ]
elif "rain" in self._weather:
return [ 'rain' ]
elif "snow" in self._weather:
return [ 'snow' ]
elif "sleet" in self._weather:
return [ 'sleet' ]
elif "clear" in self._weather:
return [ 'clear' ]
elif "cloud" in self._weather:
return [ 'clouds' ]
else:
return []
return []
def update(self, widgets): def update(self, widgets):
timestamp = int(time.time()) timestamp = int(time.time())
if self._nextcheck < int(time.time()): if self._nextcheck < int(time.time()):
@ -67,6 +88,7 @@ class Module(bumblebee.engine.Module):
weather_url = "{url}&q={city}".format(url=weather_url, city=self._location) weather_url = "{url}&q={city}".format(url=weather_url, city=self._location)
weather = json.loads(requests.get(weather_url).text) weather = json.loads(requests.get(weather_url).text)
self._temperature = int(weather['main']['temp']) self._temperature = int(weather['main']['temp'])
self._weather = weather['weather'][0]['main'].lower()
self._valid = True self._valid = True
except RequestException: except RequestException:
self._valid = False self._valid = False

View file

@ -5,8 +5,9 @@
}, },
"date": { "prefix": "" }, "date": { "prefix": "" },
"time": { "prefix": "" }, "time": { "prefix": "" },
"datetime": { "prefix": "" },
"memory": { "prefix": "" }, "memory": { "prefix": "" },
"cpu": { "prefix": "" }, "cpu": { "prefix": "" },
"disk": { "prefix": "" }, "disk": { "prefix": "" },
"dnf": { "prefix": "" }, "dnf": { "prefix": "" },
"pacman": { "prefix": "" }, "pacman": { "prefix": "" },
@ -79,7 +80,7 @@
"on": { "prefix": " "}, "off": { "prefix": " " } "on": { "prefix": " "}, "off": { "prefix": " " }
}, },
"redshift": { "redshift": {
"day": { "prefix": "" }, "night": { "prefix": "" }, "transition": { "prefix": "" } "day": { "prefix": "" }, "night": { "prefix": "" }, "transition": { "prefix": "" }
}, },
"sensors": { "sensors": {
"prefix": "" "prefix": ""
@ -107,5 +108,12 @@
}, },
"publicip": { "publicip": {
"prefix": "  " "prefix": "  "
},
"weather": {
"clouds": { "prefix": "" },
"rain": { "prefix": "" },
"snow": { "prefix": "" },
"clear": { "prefix": "" },
"thunder": { "prefix": "" }
} }
} }