scripts/gputemp.py

46 lines
1.3 KiB
Python
Raw Normal View History

2015-04-25 19:16:45 +03:00
#!/usr/bin/python
import os
import re
2017-02-18 09:32:51 +02:00
import logging
2017-12-23 14:08:23 +02:00
import subprocess
import lib.helpers as helpers
2015-04-25 19:16:45 +03:00
from subprocess import check_output
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")
2015-04-25 19:16:45 +03:00
if sensors_available:
commands = ["sensors amdgpu-pci-* | grep temp1", "sensors radeon-pci-* | grep temp1", "sensors thinkpad-isa-0000 | grep ATI"]
2017-02-19 23:30:12 +02:00
for try_command in commands:
command = try_command
2017-12-23 14:08:23 +02:00
try:
return_command = check_output(command, stderr=subprocess.STDOUT, shell=True)
if return_command is not None:
break
except subprocess.CalledProcessError as commandexc:
continue
2015-04-25 19:16:45 +03:00
if aticonfig_available:
command = "aticonfig --odgt"
# Run command
2017-02-18 09:39:31 +02:00
2015-04-25 19:16:45 +03:00
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))
2017-02-18 09:32:51 +02:00
logging.info(m.group(1))
2015-04-25 19:16:45 +03:00
elif aticonfig_available:
m = re.search(r'- (.*) C',return_value.decode("utf-8"))
print(m.group(1))
2017-02-18 09:32:51 +02:00
logging.info(m.group(1))
2015-04-25 19:16:45 +03:00
else:
print("?")
2017-02-18 09:32:51 +02:00
logging.info('?')