#!/usr/bin/python import re import logging from logging.handlers import RotatingFileHandler import subprocess from subprocess import check_output import lib.helpers as helpers log_formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s") log_handler = RotatingFileHandler(__file__+'.log', maxBytes=1024*1024*10, mode='a', backupCount=0, encoding=None, delay=0) log_handler.setFormatter(log_formatter) log_handler.setLevel(logging.DEBUG) logger = logging.getLogger('root') logger.setLevel(logging.DEBUG) logger.addHandler(log_handler) 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-0a00 | 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: logger.info('wat') logger.info(temp) return temp print(get_temperature())