[modules/sensors2] Double to single quotes
This commit is contained in:
parent
d0406ffe83
commit
665fde5399
1 changed files with 54 additions and 54 deletions
|
@ -1,16 +1,16 @@
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: UTF-8 -*-
|
||||||
|
|
||||||
"""Displays sensor temperature and CPU frequency
|
'''Displays sensor temperature and CPU frequency
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
|
|
||||||
* sensors2.chip: "sensors -u" compatible filter for chip to display (default to empty - show all chips)
|
* sensors2.chip: 'sensors -u' compatible filter for chip to display (default to empty - show all chips)
|
||||||
* sensors2.showcpu: Enable or disable CPU frequency display (default: true)
|
* sensors2.showcpu: Enable or disable CPU frequency display (default: true)
|
||||||
* sensors2.showtemp: Enable or disable temperature display (default: true)
|
* sensors2.showtemp: Enable or disable temperature display (default: true)
|
||||||
* sensors2.showfan: Enable or disable fan display (default: true)
|
* sensors2.showfan: Enable or disable fan display (default: true)
|
||||||
* sensors2.showother: Enable or display "other" sensor readings (default: false)
|
* sensors2.showother: Enable or display 'other' sensor readings (default: false)
|
||||||
* sensors2.showname: Enable or disable show of sensor name (default: false)
|
* sensors2.showname: Enable or disable show of sensor name (default: false)
|
||||||
"""
|
'''
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import bumblebee.engine
|
||||||
class Module(bumblebee.engine.Module):
|
class Module(bumblebee.engine.Module):
|
||||||
def __init__(self, engine, config):
|
def __init__(self, engine, config):
|
||||||
super(Module, self).__init__(engine, config, None)
|
super(Module, self).__init__(engine, config, None)
|
||||||
self._chip = self.parameter("chip", "")
|
self._chip = self.parameter('chip', '')
|
||||||
self._data = {}
|
self._data = {}
|
||||||
self._update()
|
self._update()
|
||||||
|
|
||||||
|
@ -33,86 +33,86 @@ class Module(bumblebee.engine.Module):
|
||||||
self._update_widget(widget)
|
self._update_widget(widget)
|
||||||
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
widget_type = widget.get("type", "")
|
widget_type = widget.get('type', '')
|
||||||
try:
|
try:
|
||||||
data = self._data[widget.get("adapter")][widget.get("package")][widget.get("field")]
|
data = self._data[widget.get('adapter')][widget.get('package')][widget.get('field')]
|
||||||
if "crit" in data and float(data["input"]) > float(data["crit"]):
|
if 'crit' in data and float(data['input']) > float(data['crit']):
|
||||||
return ["critical", widget_type]
|
return ['critical', widget_type]
|
||||||
if "max" in data and float(data["input"]) > float(data["max"]):
|
if 'max' in data and float(data['input']) > float(data['max']):
|
||||||
return ["warning", widget_type]
|
return ['warning', widget_type]
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return [widget_type]
|
return [widget_type]
|
||||||
|
|
||||||
def _create_widgets(self):
|
def _create_widgets(self):
|
||||||
widgets = []
|
widgets = []
|
||||||
show_temp = bumblebee.util.asbool(self.parameter("showtemp", "true"))
|
show_temp = bumblebee.util.asbool(self.parameter('showtemp', 'true'))
|
||||||
show_fan = bumblebee.util.asbool(self.parameter("showfan", "true"))
|
show_fan = bumblebee.util.asbool(self.parameter('showfan', 'true'))
|
||||||
show_other = bumblebee.util.asbool(self.parameter("showother", "false"))
|
show_other = bumblebee.util.asbool(self.parameter('showother', 'false'))
|
||||||
|
|
||||||
if bumblebee.util.asbool(self.parameter("showcpu", "true")):
|
if bumblebee.util.asbool(self.parameter('showcpu', 'true')):
|
||||||
widget = bumblebee.output.Widget(full_text=self._cpu)
|
widget = bumblebee.output.Widget(full_text=self._cpu)
|
||||||
widget.set("type", "cpu")
|
widget.set('type', 'cpu')
|
||||||
widgets.append(widget)
|
widgets.append(widget)
|
||||||
|
|
||||||
for adapter in self._data:
|
for adapter in self._data:
|
||||||
for package in self._data[adapter]:
|
for package in self._data[adapter]:
|
||||||
if bumblebee.util.asbool(self.parameter("showname", "false")):
|
if bumblebee.util.asbool(self.parameter('showname', 'false')):
|
||||||
widget = bumblebee.output.Widget(full_text=package)
|
widget = bumblebee.output.Widget(full_text=package)
|
||||||
widget.set("data", self._data[adapter][package])
|
widget.set('data', self._data[adapter][package])
|
||||||
widget.set("package", package)
|
widget.set('package', package)
|
||||||
widget.set("field", "")
|
widget.set('field', '')
|
||||||
widget.set("adapter", adapter)
|
widget.set('adapter', adapter)
|
||||||
widgets.append(widget)
|
widgets.append(widget)
|
||||||
for field in self._data[adapter][package]:
|
for field in self._data[adapter][package]:
|
||||||
widget = bumblebee.output.Widget()
|
widget = bumblebee.output.Widget()
|
||||||
widget.set("package", package)
|
widget.set('package', package)
|
||||||
widget.set("field", field)
|
widget.set('field', field)
|
||||||
widget.set("adapter", adapter)
|
widget.set('adapter', adapter)
|
||||||
if "temp" in field and show_temp:
|
if 'temp' in field and show_temp:
|
||||||
# seems to be a temperature
|
# seems to be a temperature
|
||||||
widget.set("type", "temp")
|
widget.set('type', 'temp')
|
||||||
widgets.append(widget)
|
widgets.append(widget)
|
||||||
if "fan" in field and show_fan:
|
if 'fan' in field and show_fan:
|
||||||
# seems to be a fan
|
# seems to be a fan
|
||||||
widget.set("type", "fan")
|
widget.set('type', 'fan')
|
||||||
widgets.append(widget)
|
widgets.append(widget)
|
||||||
elif show_other:
|
elif show_other:
|
||||||
# everything else
|
# everything else
|
||||||
widget.set("type", "other")
|
widget.set('type', 'other')
|
||||||
widgets.append(widget)
|
widgets.append(widget)
|
||||||
return widgets
|
return widgets
|
||||||
|
|
||||||
def _update_widget(self, widget):
|
def _update_widget(self, widget):
|
||||||
if widget.get("field", "") == "":
|
if widget.get('field', '') == '':
|
||||||
return # nothing to do
|
return # nothing to do
|
||||||
data = self._data[widget.get("adapter")][widget.get("package")][widget.get("field")]
|
data = self._data[widget.get('adapter')][widget.get('package')][widget.get('field')]
|
||||||
if "temp" in widget.get("field"):
|
if 'temp' in widget.get('field'):
|
||||||
widget.full_text(u"{:0.01f}°C".format(data["input"]))
|
widget.full_text(u'{:0.01f}°C'.format(data['input']))
|
||||||
elif "fan" in widget.get("field"):
|
elif 'fan' in widget.get('field'):
|
||||||
widget.full_text(u"{:0.0f}RPM".format(data["input"]))
|
widget.full_text(u'{:0.0f}RPM'.format(data['input']))
|
||||||
else:
|
else:
|
||||||
widget.full_text(u"{:0.0f}".format(data["input"]))
|
widget.full_text(u'{:0.0f}'.format(data['input']))
|
||||||
|
|
||||||
def _update(self):
|
def _update(self):
|
||||||
output = bumblebee.util.execute("sensors -u {}".format(self._chip))
|
output = bumblebee.util.execute('sensors -u {}'.format(self._chip))
|
||||||
self._data = self._parse(output)
|
self._data = self._parse(output)
|
||||||
|
|
||||||
def _parse(self, data):
|
def _parse(self, data):
|
||||||
output = {}
|
output = {}
|
||||||
package = ""
|
package = ''
|
||||||
adapter = None
|
adapter = None
|
||||||
chip = None
|
chip = None
|
||||||
for line in data.split("\n"):
|
for line in data.split('\n'):
|
||||||
if "Adapter" in line:
|
if 'Adapter' in line:
|
||||||
# new adapter
|
# new adapter
|
||||||
line = line.replace("Adapter: ", "")
|
line = line.replace('Adapter: ', '')
|
||||||
output[chip + " " + line] = {}
|
output[chip + ' ' + line] = {}
|
||||||
adapter = chip + " " + line
|
adapter = chip + ' ' + line
|
||||||
chip = line #default - line before adapter is always the chip
|
chip = line #default - line before adapter is always the chip
|
||||||
if not adapter: continue
|
if not adapter: continue
|
||||||
key, value = (line.split(":") + ["", ""])[:2]
|
key, value = (line.split(':') + ['', ''])[:2]
|
||||||
if not line.startswith(" "):
|
if not line.startswith(' '):
|
||||||
# assume this starts a new package
|
# assume this starts a new package
|
||||||
if package in output[adapter] and output[adapter][package] == {}:
|
if package in output[adapter] and output[adapter][package] == {}:
|
||||||
del output[adapter][package]
|
del output[adapter][package]
|
||||||
|
@ -121,7 +121,7 @@ class Module(bumblebee.engine.Module):
|
||||||
else:
|
else:
|
||||||
# feature for this chip
|
# feature for this chip
|
||||||
try:
|
try:
|
||||||
name, variant = (key.strip().split("_", 1) + ["",""])[:2]
|
name, variant = (key.strip().split('_', 1) + ['',''])[:2]
|
||||||
if not name in output[adapter][package]:
|
if not name in output[adapter][package]:
|
||||||
output[adapter][package][name] = { }
|
output[adapter][package][name] = { }
|
||||||
if variant:
|
if variant:
|
||||||
|
@ -134,23 +134,23 @@ class Module(bumblebee.engine.Module):
|
||||||
def _cpu(self, _):
|
def _cpu(self, _):
|
||||||
mhz = None
|
mhz = None
|
||||||
try:
|
try:
|
||||||
output = open("/sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq").read()
|
output = open('/sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq').read()
|
||||||
mhz = int(float(output)/1000.0)
|
mhz = int(float(output)/1000.0)
|
||||||
except:
|
except:
|
||||||
output = open("/proc/cpuinfo").read()
|
output = open('/proc/cpuinfo').read()
|
||||||
m = re.search(r"cpu MHz\s+:\s+(\d+)", output)
|
m = re.search(r'cpu MHz\s+:\s+(\d+)', output)
|
||||||
if m:
|
if m:
|
||||||
mhz = int(m.group(1))
|
mhz = int(m.group(1))
|
||||||
else:
|
else:
|
||||||
m = re.search(r"BogoMIPS\s+:\s+(\d+)", output)
|
m = re.search(r'BogoMIPS\s+:\s+(\d+)', output)
|
||||||
if m:
|
if m:
|
||||||
return "{} BogoMIPS".format(int(m.group(1)))
|
return '{} BogoMIPS'.format(int(m.group(1)))
|
||||||
if not mhz:
|
if not mhz:
|
||||||
return "n/a"
|
return 'n/a'
|
||||||
|
|
||||||
if mhz < 1000:
|
if mhz < 1000:
|
||||||
return "{} MHz".format(mhz)
|
return '{} MHz'.format(mhz)
|
||||||
else:
|
else:
|
||||||
return "{:0.01f} GHz".format(float(mhz)/1000.0)
|
return '{:0.01f} GHz'.format(float(mhz)/1000.0)
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue