Merge branch 'dnfm-master'

This commit is contained in:
Tobias Witek 2017-06-15 07:49:12 +02:00
commit e3f6642fcf
4 changed files with 55 additions and 5 deletions

View file

@ -30,6 +30,11 @@ def get_rtt(module, widget):
))
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
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-avg", 0.0)
widget.set("rtt-unit", "")
widget.set('packet-loss', 0)
self._next_check = 0
def rtt(self, widget):
if widget.get("rtt-unreachable"):
return "{}: unreachable".format(widget.get("address"))
return "{}: {:.1f}{}".format(
return "{}: {:.1f}{} ({}%)".format(
widget.get("address"),
widget.get("rtt-avg"),
widget.get("rtt-unit")
widget.get("rtt-unit"),
widget.get( 'packet-loss' )
)
def state(self, widget):

View file

@ -1,3 +1,4 @@
# -*- coding: UTF-8 -*-
# pylint: disable=C0111,R0903
"""Displays sensor temperature
@ -21,6 +22,7 @@ class Module(bumblebee.engine.Module):
super(Module, self).__init__(engine, config,
bumblebee.output.Widget(full_text=self.temperature))
self._temperature = "unknown"
self._mhz = "n/a"
pattern = self.parameter("match", "temp1_input")
pattern_string = r"^\s*{}:\s*([\d.]+)$".format(pattern)
self._match_number = int(self.parameter("match_number", "-1"))
@ -36,10 +38,21 @@ class Module(bumblebee.engine.Module):
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 "{:0.01f} GHz".format(float(mhz)/1000.0)
def temperature(self, _):
return self._temperature
return u"{}°c @ {}".format(self._temperature, self._mhz)
def update(self, widgets):
self._temperature = self.get_temp()
self._mhz = self.get_mhz()
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -51,6 +51,27 @@ class Module(bumblebee.engine.Module):
return u"?"
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):
timestamp = 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 = json.loads(requests.get(weather_url).text)
self._temperature = int(weather['main']['temp'])
self._weather = weather['weather'][0]['main'].lower()
self._valid = True
except RequestException:
self._valid = False

View file

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