Add a warning when using TLP (#305)

* Add function to check if binary is present

* Rename gnome_power_stats to gnome_power_status

* Added warning when using TLP
This commit is contained in:
bobslept 2021-12-11 11:59:41 +01:00 committed by GitHub
parent c719646e41
commit c1b898906a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 73 additions and 14 deletions

View File

@ -315,6 +315,9 @@ def deploy_daemon():
gnome_power_detect_install() gnome_power_detect_install()
gnome_power_svc_disable() gnome_power_svc_disable()
# output warning if TLP service is detected
tlp_service_detect()
call("/usr/bin/auto-cpufreq-install", shell=True) call("/usr/bin/auto-cpufreq-install", shell=True)
# remove auto-cpufreq daemon # remove auto-cpufreq daemon

View File

@ -6,6 +6,7 @@ from subprocess import getoutput, call, run, check_output, DEVNULL
sys.path.append('../') sys.path.append('../')
from auto_cpufreq.core import * from auto_cpufreq.core import *
from auto_cpufreq.tlp_stat_parser import TLPStatusParser
# app_name var # app_name var
if sys.argv[0] == "power_helper.py": if sys.argv[0] == "power_helper.py":
@ -19,20 +20,46 @@ def header():
def helper_opts(): def helper_opts():
print("\nFor full list of options run: python3 power_helper.py --help") print("\nFor full list of options run: python3 power_helper.py --help")
# used to check if binary exists on the system
def does_command_exists(cmd):
return which(cmd) is not None
systemctl_exists = does_command_exists("systemctl")
bluetoothctl_exists = does_command_exists("bluetoothctl")
tlp_stat_exists = does_command_exists("tlp-stat")
# detect if gnome power profile service is running # detect if gnome power profile service is running
if os.getenv('PKG_MARKER') != "SNAP": if os.getenv('PKG_MARKER') != "SNAP":
if which("systemctl") is not None: if systemctl_exists:
try: try:
gnome_power_stats = call(["systemctl", "is-active", "--quiet", "power-profiles-daemon"]) gnome_power_status = call(["systemctl", "is-active", "--quiet", "power-profiles-daemon"])
except: except:
print("\nUnable to determine init system") print("\nUnable to determine init system")
print("If this causes any problems, please submit an issue:") print("If this causes any problems, please submit an issue:")
print("https://github.com/AdnanHodzic/auto-cpufreq/issues") print("https://github.com/AdnanHodzic/auto-cpufreq/issues")
# alert in case TLP service is running
def tlp_service_detect():
if tlp_stat_exists:
status_output = getoutput("tlp-stat -s")
tlp_status = TLPStatusParser(status_output)
if tlp_status.is_enabled():
print("\n----------------------------------- Warning -----------------------------------\n")
print("Detected you are running a TLP service!")
print("This daemon might interfere with auto-cpufreq which can lead to unexpected results.")
print("We strongly encourage you to remove TLP unless you really know what you are doing.")
# alert about TLP when using snap
def tlp_service_detect_snap():
print("\n----------------------------------- Warning -----------------------------------\n")
print("Unable to detect if you are using a TLP service!")
print("This daemon might interfere with auto-cpufreq which can lead to unexpected results.")
print("We strongly encourage you not to use TLP unless you really know what you are doing.")
# alert in case gnome power profile service is running # alert in case gnome power profile service is running
def gnome_power_detect(): def gnome_power_detect():
if which("systemctl") is not None: if systemctl_exists:
if gnome_power_stats == 0: if gnome_power_status == 0:
print("\n----------------------------------- Warning -----------------------------------\n") print("\n----------------------------------- Warning -----------------------------------\n")
print("Detected running GNOME Power Profiles daemon service!") print("Detected running GNOME Power Profiles daemon service!")
print("This daemon might interfere with auto-cpufreq and should be disabled.") print("This daemon might interfere with auto-cpufreq and should be disabled.")
@ -44,8 +71,8 @@ def gnome_power_detect():
# automatically disable gnome power profile service in case it's running during install # automatically disable gnome power profile service in case it's running during install
def gnome_power_detect_install(): def gnome_power_detect_install():
if which("systemctl") is not None: if systemctl_exists:
if gnome_power_stats == 0: if gnome_power_status == 0:
print("\n----------------------------------- Warning -----------------------------------\n") print("\n----------------------------------- Warning -----------------------------------\n")
print("Detected running GNOME Power Profiles daemon service!") print("Detected running GNOME Power Profiles daemon service!")
print("This daemon might interfere with auto-cpufreq and has been disabled.\n") print("This daemon might interfere with auto-cpufreq and has been disabled.\n")
@ -65,13 +92,13 @@ def gnome_power_detect_snap():
# disable gnome >= 40 power profiles (live) # disable gnome >= 40 power profiles (live)
def gnome_power_disable_live(): def gnome_power_disable_live():
if(gnome_power_stats == 0): if(gnome_power_status == 0):
call(["systemctl", "stop", "power-profiles-daemon"]) call(["systemctl", "stop", "power-profiles-daemon"])
# disable gnome >= 40 power profiles (install) # disable gnome >= 40 power profiles (install)
def gnome_power_svc_disable(): def gnome_power_svc_disable():
if which("systemctl") is not None: if systemctl_exists:
try: try:
print("\n* Disabling GNOME power profiles") print("\n* Disabling GNOME power profiles")
call(["systemctl", "stop", "power-profiles-daemon"]) call(["systemctl", "stop", "power-profiles-daemon"])
@ -86,7 +113,7 @@ def gnome_power_svc_disable():
# enable gnome >= 40 power profiles (uninstall) # enable gnome >= 40 power profiles (uninstall)
def gnome_power_svc_enable(): def gnome_power_svc_enable():
if which("systemctl") is not None: if systemctl_exists:
try: try:
print("\n* Enabling GNOME power profiles") print("\n* Enabling GNOME power profiles")
call(["systemctl", "unmask", "power-profiles-daemon"]) call(["systemctl", "unmask", "power-profiles-daemon"])
@ -101,7 +128,7 @@ def gnome_power_svc_enable():
# gnome power profiles current status # gnome power profiles current status
def gnome_power_svc_status(): def gnome_power_svc_status():
if which("systemctl") is not None: if systemctl_exists:
try: try:
print("* GNOME power profiles status") print("* GNOME power profiles status")
call(["systemctl", "status", "power-profiles-daemon"]) call(["systemctl", "status", "power-profiles-daemon"])
@ -115,7 +142,7 @@ def gnome_power_svc_status():
def bluetooth_disable(): def bluetooth_disable():
if os.getenv("PKG_MARKER") == "SNAP": if os.getenv("PKG_MARKER") == "SNAP":
bluetooth_notif_snap() bluetooth_notif_snap()
elif which("bluetoothctl") is not None: elif bluetoothctl_exists:
print("* Turn off bluetooth on boot") print("* Turn off bluetooth on boot")
btconf = Path("/etc/bluetooth/main.conf") btconf = Path("/etc/bluetooth/main.conf")
try: try:
@ -136,7 +163,7 @@ def bluetooth_disable():
def bluetooth_enable(): def bluetooth_enable():
if os.getenv("PKG_MARKER") == "SNAP": if os.getenv("PKG_MARKER") == "SNAP":
bluetooth_on_notif_snap() bluetooth_on_notif_snap()
if which("bluetoothctl") is not None: if bluetoothctl_exists:
print("* Turn on bluetooth on boot") print("* Turn on bluetooth on boot")
btconf = "/etc/bluetooth/main.conf" btconf = "/etc/bluetooth/main.conf"
try: try:
@ -167,8 +194,8 @@ def bluetooth_on_notif_snap():
# gnome power removal reminder # gnome power removal reminder
def gnome_power_rm_reminder(): def gnome_power_rm_reminder():
if which("systemctl") is not None: if systemctl_exists:
if gnome_power_stats != 0: if gnome_power_status != 0:
print("\n----------------------------------- Warning -----------------------------------\n") print("\n----------------------------------- Warning -----------------------------------\n")
print("Detected GNOME Power Profiles daemon service is stopped!") print("Detected GNOME Power Profiles daemon service is stopped!")
print("This service will now be enabled and started again.") print("This service will now be enabled and started again.")

View File

@ -0,0 +1,20 @@
class TLPStatusParser():
def __init__(self, tlp_stat_output):
self.data = {}
self._parse(tlp_stat_output)
def _parse(self, data):
for line in data.split("\n"):
key_val = line.split("=", 1)
if len(key_val) > 1:
self.data[key_val[0].strip().lower()] = key_val[1].strip()
def _get_key(self, key):
if key in self.data:
return self.data[key]
else:
return ""
def is_enabled(self):
return self._get_key("state") == "enabled"

View File

@ -48,6 +48,7 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don
file_stats() file_stats()
if os.getenv("PKG_MARKER") == "SNAP" and dcheck == "enabled": if os.getenv("PKG_MARKER") == "SNAP" and dcheck == "enabled":
gnome_power_detect_snap() gnome_power_detect_snap()
tlp_service_detect_snap()
while True: while True:
footer() footer()
gov_check() gov_check()
@ -58,6 +59,7 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don
countdown(5) countdown(5)
elif os.getenv("PKG_MARKER") != "SNAP": elif os.getenv("PKG_MARKER") != "SNAP":
gnome_power_detect() gnome_power_detect()
tlp_service_detect()
while True: while True:
footer() footer()
gov_check() gov_check()
@ -74,8 +76,10 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don
print("\nNote: You can quit monitor mode by pressing \"ctrl+c\"") print("\nNote: You can quit monitor mode by pressing \"ctrl+c\"")
if os.getenv("PKG_MARKER") == "SNAP": if os.getenv("PKG_MARKER") == "SNAP":
gnome_power_detect_snap() gnome_power_detect_snap()
tlp_service_detect_snap()
else: else:
gnome_power_detect() gnome_power_detect()
tlp_service_detect()
while True: while True:
time.sleep(1) time.sleep(1)
running_daemon() running_daemon()
@ -93,8 +97,10 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don
time.sleep(1) time.sleep(1)
if os.getenv("PKG_MARKER") == "SNAP": if os.getenv("PKG_MARKER") == "SNAP":
gnome_power_detect_snap() gnome_power_detect_snap()
tlp_service_detect_snap()
else: else:
gnome_power_detect() gnome_power_detect()
tlp_service_detect()
while True: while True:
running_daemon() running_daemon()
footer() footer()
@ -109,8 +115,10 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don
print("\nNote: You can quit stats mode by pressing \"ctrl+c\"") print("\nNote: You can quit stats mode by pressing \"ctrl+c\"")
if os.getenv("PKG_MARKER") == "SNAP": if os.getenv("PKG_MARKER") == "SNAP":
gnome_power_detect_snap() gnome_power_detect_snap()
tlp_service_detect_snap()
else: else:
gnome_power_detect() gnome_power_detect()
tlp_service_detect()
time.sleep(1) time.sleep(1)
read_stats() read_stats()
elif log: elif log:
@ -154,6 +162,7 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don
root_check() root_check()
running_daemon() running_daemon()
gnome_power_detect_snap() gnome_power_detect_snap()
tlp_service_detect_snap()
bluetooth_notif_snap() bluetooth_notif_snap()
gov_check() gov_check()
run("snapctl set daemon=enabled", shell=True) run("snapctl set daemon=enabled", shell=True)