From 70d8ad40e02d42b88cbe90f5efdfb4408eb263b1 Mon Sep 17 00:00:00 2001 From: Oskar Hollmann Date: Sat, 20 Nov 2021 15:11:22 +0100 Subject: [PATCH] Fix turning the screen on/off on some RPI systems On some systems, vcgencmd is not on PATH. There doesn't seem to be a simple way to customize env vars passed to Kodi Python scripts but adding it to the PATH in screensaver.py works. This should not break anything on other systems, just fix the problem on OSMC and other similar distributions. --- screensaver.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/screensaver.py b/screensaver.py index ad89bac..143b8d3 100644 --- a/screensaver.py +++ b/screensaver.py @@ -4,11 +4,16 @@ ''' This Kodi addon turns off display devices when Kodi goes into screensaver-mode ''' from __future__ import absolute_import, division, unicode_literals +import os import sys import atexit from xbmc import Monitor from xbmcgui import WindowXMLDialog +# On some systems, commands might be in directories not on PATH env var, e.g. `vcgencmd` is under +# /opt/vc/bin/ on OSMC. Add these paths to ensure the commands work on all systems. +PATH = ':'.join((os.environ.get('PATH', ''),'/opt/vc/bin')) + # NOTE: The below order relates to resources/settings.xml DISPLAY_METHODS = [ dict(name='do-nothing', title='Do nothing', @@ -212,7 +217,7 @@ def run_command(*command, **kwargs): import subprocess # TODO: Add options for running using su or sudo try: - cmd = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False, **kwargs) + cmd = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False, env={"PATH": PATH}, **kwargs) (out, err) = cmd.communicate() if cmd.returncode == 0: log(2, "Running command '{command}' returned rc={rc}", command=' '.join(command), rc=cmd.returncode)