summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--py3status/modules/dpms.py11
-rwxr-xr-xpy3status/modules/nvidia_temp.py89
-rw-r--r--py3status/modules/sysdata.py6
3 files changed, 97 insertions, 9 deletions
diff --git a/py3status/modules/dpms.py b/py3status/modules/dpms.py
index c2d9c4e..ecbc3a7 100644
--- a/py3status/modules/dpms.py
+++ b/py3status/modules/dpms.py
@@ -15,19 +15,17 @@ from os import system
class Py3status:
"""
"""
- def __init__(self):
- """
- Detect current state on start.
- """
- self.run = system('xset -q | grep -iq "DPMS is enabled"') == 0
-
def dpms(self, i3s_output_list, i3s_config):
"""
Display a colorful state of DPMS.
"""
+
+ self.run = system('xset -q | grep -iq "DPMS is enabled"') == 0
+
response = {
'full_text': 'DPMS'
}
+
if self.run:
response['color'] = i3s_config['color_good']
else:
@@ -45,4 +43,3 @@ class Py3status:
else:
self.run = True
system("xset +dpms;xset s on")
- system("killall -USR1 py3status")
diff --git a/py3status/modules/nvidia_temp.py b/py3status/modules/nvidia_temp.py
new file mode 100755
index 0000000..ba17d27
--- /dev/null
+++ b/py3status/modules/nvidia_temp.py
@@ -0,0 +1,89 @@
+# -*- coding: utf-8 -*-
+"""
+Display NVIDIA GPU temperature.
+
+Configuration parameters:
+ - cache_timeout: how often we refresh this module in seconds
+ - color_bad: the color used if the temperature can't be read.
+ - color_good: the color used if everything is OK.
+ - format_prefix: a prefix for the output.
+ - format_units: the temperature units. Will appear at the end.
+ - separator: the separator char between temperatures (only if more than one GPU)
+
+Requires:
+ - nvidia-smi
+
+@author jmdana <https://github.com/jmdana>
+@license BSD
+"""
+
+import re
+import shlex
+from subprocess import check_output
+from time import time
+
+TEMP_RE = re.compile(r"Current Temp\s+:\s+([0-9]+)")
+
+
+class Py3status:
+ """
+ """
+ # configuration parameters
+ cache_timeout = 10
+ color_bad = None
+ color_good = None
+ format_prefix = "GPU: "
+ format_units = "°C"
+ separator = '|'
+
+ def nvidia_temp(self, i3s_output_list, i3s_config):
+ # The whole command:
+ # nvidia-smi -q -d TEMPERATURE | sed -nr 's/.*Current Temp.*:[[:space:]]*([0-9]+).*/\1/p'
+
+ out = check_output(shlex.split("nvidia-smi -q -d TEMPERATURE"))
+ temps = re.findall(TEMP_RE, out.decode("utf-8"))
+
+ if temps != []:
+ data = []
+ for temp in temps:
+ fmt_str = "{temp}{format_units}".format(
+ temp=temp,
+ format_units=self.format_units
+ )
+ data.append(fmt_str)
+
+ output = "{format_prefix}{data}".format(
+ format_prefix=self.format_prefix,
+ data=self.separator.join(data)
+ )
+
+ color = self.color_good or i3s_config['color_good']
+ else:
+ output = "{format_prefix}OFF".format(
+ format_prefix=self.format_prefix
+ )
+
+ color = self.color_bad or i3s_config['color_bad']
+
+ response = {
+ 'cached_until': time() + self.cache_timeout,
+ 'color': color,
+ 'full_text': output
+ }
+
+ return response
+
+if __name__ == "__main__":
+ """
+ Test this module by calling it directly.
+ """
+ from time import sleep
+ x = Py3status()
+ config = {
+ "color_good": "#00FF00",
+ "color_bad": "#FF0000",
+ }
+
+ while True:
+ print(x.nvidia_temp([], config))
+ sleep(1)
diff --git a/py3status/modules/sysdata.py b/py3status/modules/sysdata.py
index f836bc1..9343722 100644
--- a/py3status/modules/sysdata.py
+++ b/py3status/modules/sysdata.py
@@ -24,6 +24,7 @@ class GetData:
- `arg`: argument.
"""
result = subprocess.check_output([cmd, arg])
+ result = result.decode('utf-8')
return result
def cpu(self):
@@ -60,8 +61,9 @@ class GetData:
"""
# Run 'free -m' command and make a list from output.
mem_data = self.execCMD('free', '-m').split()
- total_mem = int(mem_data[7]) / 1024.
- used_mem = int(mem_data[15]) / 1024.
+ mem_index = mem_data.index('Mem:')
+ total_mem = int(mem_data[mem_index + 1]) / 1024.
+ used_mem = int(mem_data[mem_index + 2]) / 1024.
# Caculate percentage
used_mem_percent = int(used_mem / (total_mem / 100))