scripts/gputemp.py

56 lines
1.5 KiB
Python
Raw Normal View History

2015-04-25 19:16:45 +03:00
#!/usr/bin/python
2015-04-25 19:16:45 +03:00
import re
2017-02-18 09:32:51 +02:00
import logging
2017-12-23 14:08:23 +02:00
import subprocess
2015-04-25 19:16:45 +03:00
from subprocess import check_output
import lib.helpers as helpers
2015-04-25 19:16:45 +03:00
2017-02-18 09:32:51 +02:00
FORMAT = "%(asctime)s %(levelname)s %(message)s"
logging.basicConfig(format=FORMAT, filename=__file__+'.log', level=logging.DEBUG)
ATICONFIG_AVAILABLE = helpers.is_exe("/usr/bin/aticonfig")
SENSORS_AVAILABLE = helpers.is_exe("/usr/bin/sensors")
def get_temperature():
command = None
if SENSORS_AVAILABLE:
commands = ["sensors amdgpu-pci-0800 | grep edge",
"sensors radeon-pci-* | grep temp1",
"sensors thinkpad-isa-0000 | grep ATI"]
for try_command in commands:
try:
return_command = check_output(try_command, stderr=subprocess.STDOUT, shell=True)
if return_command is not None:
command = try_command
break
except subprocess.CalledProcessError as commandexc:
continue
if ATICONFIG_AVAILABLE:
command = "aticonfig --odgt"
if command is None:
exit(1)
# Run command
return_value = check_output(command, shell=True)
temp = '?'
# Default return value
if SENSORS_AVAILABLE:
m = re.search(r'\+(.*)°C ', return_value.decode("utf-8"))
temp = m.group(1)
elif ATICONFIG_AVAILABLE:
m = re.search(r'- (.*) C', return_value.decode("utf-8"))
temp = m.group(1)
else:
logging.info('wat')
logging.info(temp)
return temp
print(get_temperature())