Complete power-profiles operations helper for non Snap install

This commit is contained in:
Adnan Hodzic 2021-11-28 14:49:14 +01:00
parent 677646abbd
commit 167b761888
2 changed files with 16 additions and 56 deletions

View File

@ -317,6 +317,9 @@ def deploy_daemon():
auto_cpufreq_stats_path.touch(exist_ok=True) auto_cpufreq_stats_path.touch(exist_ok=True)
# disable gnome power profiles
gnome_power_disable()
print("\n* Deploy auto-cpufreq install script") print("\n* Deploy auto-cpufreq install script")
shutil.copy( shutil.copy(
SCRIPTS_DIR / "auto-cpufreq-install.sh", "/usr/bin/auto-cpufreq-install" SCRIPTS_DIR / "auto-cpufreq-install.sh", "/usr/bin/auto-cpufreq-install"
@ -1084,34 +1087,3 @@ def running_daemon():
elif os.getenv("PKG_MARKER") == "SNAP" and dcheck == "enabled": elif os.getenv("PKG_MARKER") == "SNAP" and dcheck == "enabled":
daemon_running_msg() daemon_running_msg()
exit(1) 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")

View File

@ -1,5 +1,5 @@
# * add gnome_power_detect message after install (make it more visible) # * add status as one of the available options
# * make sure daemon is enabled after auto-cpufreq --remove (non snap) # * 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 # * if daemon is disabled and auto-cpufreq is removed (snap) remind user to enable it back
import os, sys, click import os, sys, click
from subprocess import getoutput, call, run, check_output, DEVNULL from subprocess import getoutput, call, run, check_output, DEVNULL
@ -8,18 +8,13 @@ sys.path.append('../')
from auto_cpufreq.core import * from auto_cpufreq.core import *
# app_name var # app_name var
#if os.getenv("PKG_MARKER") == "SNAP":
# app_name = "auto-cpufreq"
if sys.argv[0] == "gnome_power.py": if sys.argv[0] == "gnome_power.py":
app_name="gnome_power.py" app_name="python3 gnome_power.py"
else: else:
app_name="auto-cpufreq" app_name="auto-cpufreq"
# detect if gnome power profile service is running # detect if gnome power profile service is running
gnome_power_stats = call(["systemctl", "is-active", "--quiet", "power-profiles-daemon"]) 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 # alert in case gnome power profile service is running
def gnome_power_detect(): def gnome_power_detect():
@ -33,41 +28,34 @@ def gnome_power_detect():
elif gnome_power_stats == 0: elif gnome_power_stats == 0:
print("\nDetected running GNOME Power Profiles daemon service:") print("\nDetected running GNOME Power Profiles daemon service:")
print("This daemon might interfere with auto-cpufreq and it will be disabled!") 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("\nIf you wish to enable this daemon to run concurrently with auto-cpufreq run:")
print("cd ~/auto-cpufreq/auto_cpufreq") print("cd ~/auto-cpufreq/auto_cpufreq")
print("python3 gnome_power.py --enable") print("python3 gnome_power.py --enable")
# 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_stats == 0):
# ToDo: remove
print("\nDisabling GNOME power profiles")
call(["systemctl", "stop", "power-profiles-daemon"]) call(["systemctl", "stop", "power-profiles-daemon"])
else:
print("GNOME power already disabled")
# disable gnome >= 40 power profiles (install) # disable gnome >= 40 power profiles (install)
def gnome_power_disable(): def gnome_power_disable():
if(gnome_power_stats != 0): if(gnome_power_stats == 0):
# ToDo: remove print("\n* Disabling GNOME power profiles")
print("\nDisabling GNOME power profiles")
call(["systemctl", "stop", "power-profiles-daemon"]) call(["systemctl", "stop", "power-profiles-daemon"])
call(["systemctl", "disable", "power-profiles-daemon"]) call(["systemctl", "disable", "power-profiles-daemon"])
call(["systemctl", "mask", "power-profiles-daemon"]) call(["systemctl", "mask", "power-profiles-daemon"])
else: else:
print("GNOME power already disabled") print("\n* Disabling GNOME power profiles (already disabled)")
# enable gnome >= 40 power profiles (uninstall) # enable gnome >= 40 power profiles (uninstall)
def gnome_power_enable(): def gnome_power_enable():
# ToDo: remove if(gnome_power_stats == 0):
if(gnome_power_stats != 0): print("\n* Enabling GNOME power profiles")
print("\nEnabling GNOME power profiles")
call(["systemctl", "unmask", "power-profiles-daemon"]) call(["systemctl", "unmask", "power-profiles-daemon"])
call(["systemctl", "start", "power-profiles-daemon"]) call(["systemctl", "start", "power-profiles-daemon"])
call(["systemctl", "enable", "power-profiles-daemon"]) call(["systemctl", "enable", "power-profiles-daemon"])
else: else:
print("GNOME power already enabled") print("\n* Enabling GNOME power profiles (already enabled)")
def valid_options(): def valid_options():
print("--enable\t\tEnable GNOME Power Profiles daemon") print("--enable\t\tEnable GNOME Power Profiles daemon")
@ -81,8 +69,8 @@ def main(enable, disable):
root_check() root_check()
if len(sys.argv) == 1: if len(sys.argv) == 1:
footer() print("---------------- auto-cpufreq: GNOME Power Profiles helper --------------------\n")
print("Provided none of valid options.\n\nRun: \"" + app_name + " --help\" for more info") print("Unrecognized option!\n\nRun: \"" + app_name + " --help\" for list of available options.")
footer() footer()
else: else:
if enable: if enable: