#!/usr/bin/python import re import logging import subprocess from subprocess import check_output import lib.helpers as helpers 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())