scripts/getGPUTemp.py
2017-02-18 09:39:31 +02:00

38 lines
988 B
Python
Executable File

#!/usr/bin/python
import os
import re
import logging
from subprocess import check_output
FORMAT = "%(asctime)s %(levelname)s %(message)s"
logging.basicConfig(format=FORMAT, filename=__file__+'.log', level=logging.DEBUG)
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
aticonfig_available = is_exe("/usr/bin/aticonfig")
sensors_available = is_exe("/usr/bin/sensors")
if sensors_available:
#command = "sensors radeon-pci-* | grep temp1"
command = "sensors thinkpad-isa-* | grep ATI"
if aticonfig_available:
command = "aticonfig --odgt"
# Run command
return_value = check_output(command, shell=True)
# Default return value
if sensors_available:
m = re.search(r'\+(.*)°C ',return_value.decode("utf-8"))
print(m.group(1))
logging.info(m.group(1))
elif aticonfig_available:
m = re.search(r'- (.*) C',return_value.decode("utf-8"))
print(m.group(1))
logging.info(m.group(1))
else:
print("?")
logging.info('?')