From 167b76188800563b351bbd803fb011db521c07bb Mon Sep 17 00:00:00 2001 From: Adnan Hodzic Date: Sun, 28 Nov 2021 14:49:14 +0100 Subject: [PATCH] Complete power-profiles operations helper for non Snap install --- auto_cpufreq/core.py | 36 ++++-------------------------------- auto_cpufreq/gnome_power.py | 36 ++++++++++++------------------------ 2 files changed, 16 insertions(+), 56 deletions(-) diff --git a/auto_cpufreq/core.py b/auto_cpufreq/core.py index 86d106b..47771c0 100644 --- a/auto_cpufreq/core.py +++ b/auto_cpufreq/core.py @@ -317,6 +317,9 @@ def deploy_daemon(): auto_cpufreq_stats_path.touch(exist_ok=True) + # disable gnome power profiles + gnome_power_disable() + print("\n* Deploy auto-cpufreq install script") shutil.copy( SCRIPTS_DIR / "auto-cpufreq-install.sh", "/usr/bin/auto-cpufreq-install" @@ -1083,35 +1086,4 @@ def running_daemon(): exit(1) elif os.getenv("PKG_MARKER") == "SNAP" and dcheck == "enabled": daemon_running_msg() - exit(1) - -# # disable gnome >= 40 power profiles (live) -# def gnome_power_disable_live(): -# gnome_power_stats = call(["systemctl", "is-active", "--quiet", "power-profiles-daemon"]) -# if(gnome_power_stats == 0): -# print("Disabling GNOME power profiles") -# call(["systemctl", "stop", "power-profiles-daemon"]) -# else: -# print("GNOME power already disabled") - -# # disable gnome >= 40 power profiles (install) -# def gnome_power_disable(): -# gnome_power_stats = call(["systemctl", "is-active", "--quiet", "power-profiles-daemon"]) -# if(gnome_power_stats == 0): -# print("Disabling GNOME power profiles") -# call(["systemctl", "stop", "power-profiles-daemon"]) -# call(["systemctl", "disable", "power-profiles-daemon"]) -# call(["systemctl", "mask", "power-profiles-daemon"]) -# else: -# print("GNOME power already disabled") - -# # enable gnome >= 40 power profiles (uninstall) -# def gnome_power_enable(): -# gnome_power_stats = call(["systemctl", "is-active", "--quiet", "power-profiles-daemon"]) -# if(gnome_power_stats == 0): -# print("Enabling GNOME power profiles") -# call(["systemctl", "unmask", "power-profiles-daemon"]) -# call(["systemctl", "start", "power-profiles-daemon"]) -# call(["systemctl", "enable", "power-profiles-daemon"]) -# else: -# print("GNOME power already enabled") \ No newline at end of file + exit(1) \ No newline at end of file diff --git a/auto_cpufreq/gnome_power.py b/auto_cpufreq/gnome_power.py index 5bf6f1d..7f00de7 100644 --- a/auto_cpufreq/gnome_power.py +++ b/auto_cpufreq/gnome_power.py @@ -1,5 +1,5 @@ -# * add gnome_power_detect message after install (make it more visible) -# * make sure daemon is enabled after auto-cpufreq --remove (non snap) +# * add status as one of the available options +# * alert user on snap if detected and how to remove first time live/stats message starts # * if daemon is disabled and auto-cpufreq is removed (snap) remind user to enable it back import os, sys, click from subprocess import getoutput, call, run, check_output, DEVNULL @@ -8,18 +8,13 @@ sys.path.append('../') from auto_cpufreq.core import * # app_name var -#if os.getenv("PKG_MARKER") == "SNAP": -# app_name = "auto-cpufreq" if sys.argv[0] == "gnome_power.py": - app_name="gnome_power.py" + app_name="python3 gnome_power.py" else: app_name="auto-cpufreq" # detect if gnome power profile service is running gnome_power_stats = call(["systemctl", "is-active", "--quiet", "power-profiles-daemon"]) -# ToDo: remove -print(gnome_power_stats) -print(os.getenv('PKG_MARKER')) # alert in case gnome power profile service is running def gnome_power_detect(): @@ -33,41 +28,34 @@ def gnome_power_detect(): elif gnome_power_stats == 0: print("\nDetected running GNOME Power Profiles daemon service:") print("This daemon might interfere with auto-cpufreq and it will be disabled!") - gnome_power_disable() print("\nIf you wish to enable this daemon to run concurrently with auto-cpufreq run:") print("cd ~/auto-cpufreq/auto_cpufreq") print("python3 gnome_power.py --enable") # disable gnome >= 40 power profiles (live) def gnome_power_disable_live(): - if(gnome_power_stats != 0): - # ToDo: remove - print("\nDisabling GNOME power profiles") + if(gnome_power_stats == 0): call(["systemctl", "stop", "power-profiles-daemon"]) - else: - print("GNOME power already disabled") # disable gnome >= 40 power profiles (install) def gnome_power_disable(): - if(gnome_power_stats != 0): - # ToDo: remove - print("\nDisabling GNOME power profiles") + if(gnome_power_stats == 0): + print("\n* Disabling GNOME power profiles") call(["systemctl", "stop", "power-profiles-daemon"]) call(["systemctl", "disable", "power-profiles-daemon"]) call(["systemctl", "mask", "power-profiles-daemon"]) else: - print("GNOME power already disabled") + print("\n* Disabling GNOME power profiles (already disabled)") # enable gnome >= 40 power profiles (uninstall) def gnome_power_enable(): - # ToDo: remove - if(gnome_power_stats != 0): - print("\nEnabling GNOME power profiles") + if(gnome_power_stats == 0): + print("\n* Enabling GNOME power profiles") call(["systemctl", "unmask", "power-profiles-daemon"]) call(["systemctl", "start", "power-profiles-daemon"]) call(["systemctl", "enable", "power-profiles-daemon"]) else: - print("GNOME power already enabled") + print("\n* Enabling GNOME power profiles (already enabled)") def valid_options(): print("--enable\t\tEnable GNOME Power Profiles daemon") @@ -81,8 +69,8 @@ def main(enable, disable): root_check() if len(sys.argv) == 1: - footer() - print("Provided none of valid options.\n\nRun: \"" + app_name + " --help\" for more info") + print("---------------- auto-cpufreq: GNOME Power Profiles helper --------------------\n") + print("Unrecognized option!\n\nRun: \"" + app_name + " --help\" for list of available options.") footer() else: if enable: