Skip to content

Commit

Permalink
Improve defensive detection in case of other init systems
Browse files Browse the repository at this point in the history
  • Loading branch information
AdnanHodzic committed Dec 5, 2021
1 parent db68390 commit 4c5681b
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions auto_cpufreq/power_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ def helper_opts():

# detect if gnome power profile service is running
if os.getenv('PKG_MARKER') != "SNAP":
gnome_power_stats = call(["systemctl", "is-active", "--quiet", "power-profiles-daemon"])
try:
gnome_power_stats = call(["systemctl", "is-active", "--quiet", "power-profiles-daemon"])
except:
print("\nUnable to determine init system")
print("If this causes any problems, please submit an issue:")
print("https://github.com/AdnanHodzic/auto-cpufreq/issues")

# alert in case gnome power profile service is running
def gnome_power_detect():
Expand All @@ -32,19 +37,17 @@ def gnome_power_detect():
print("\nSteps to perform this action using auto-cpufreq: power_helper script:")
print("git clone https://github.com/AdnanHodzic/auto-cpufreq.git")
print("cd auto-cpufreq/auto_cpufreq")
print("python3 power_helper.py --gnome-power-disable")
print("python3 power_helper.py --gnome_power_disable")


# automatically disable gnome power profile service in case it's running during install
def gnome_power_detect_install():
if gnome_power_stats == 0:
print("\n----------------------------------- Warning -----------------------------------\n")
print("Detected running GNOME Power Profiles daemon service!")
print("This daemon might interfere with auto-cpufreq and has been disabled.")
print("\nSteps to enabled disabled deamon (not recommended!) using auto-cpufreq: power_helper script:")
print("git clone https://github.com/AdnanHodzic/auto-cpufreq.git")
print("cd auto-cpufreq/auto_cpufreq")
print("python3 power_helper.py --gnome-power-enable")

print("This daemon might interfere with auto-cpufreq and has been disabled.\n")
print("Disabled daemon is not automatically disabled in \"live\" and \"monitor\" mode and")
print("will be enabled after auto-cpufreq is removed.")

# notification on snap
def gnome_power_detect_snap():
Expand All @@ -54,7 +57,7 @@ def gnome_power_detect_snap():
print("\nSteps to perform this action using auto-cpufreq: power_helper script:")
print("git clone https://github.com/AdnanHodzic/auto-cpufreq.git")
print("cd auto-cpufreq/auto_cpufreq")
print("python3 power_helper.py --gnome-power-disable")
print("python3 power_helper.py --gnome_power_disable")


# disable gnome >= 40 power profiles (live)
Expand All @@ -65,26 +68,42 @@ def gnome_power_disable_live():

# disable gnome >= 40 power profiles (install)
def gnome_power_svc_disable():
try:
print("\n* Disabling GNOME power profiles")
call(["systemctl", "stop", "power-profiles-daemon"])
call(["systemctl", "disable", "power-profiles-daemon"])
call(["systemctl", "mask", "power-profiles-daemon"])
call(["systemctl", "daemon-reload"])
except:
print("\nUnable to disable GNOME power profiles")
print("If this causes any problems, please submit an issue:")
print("https://github.com/AdnanHodzic/auto-cpufreq/issues")


# enable gnome >= 40 power profiles (uninstall)
def gnome_power_svc_enable():
try:
print("\n* Enabling GNOME power profiles")
call(["systemctl", "unmask", "power-profiles-daemon"])
call(["systemctl", "start", "power-profiles-daemon"])
call(["systemctl", "enable", "power-profiles-daemon"])
call(["systemctl", "daemon-reload"])
except:
print("\nUnable to enable GNOME power profiles")
print("If this causes any problems, please submit an issue:")
print("https://github.com/AdnanHodzic/auto-cpufreq/issues")


# gnome power profiles current status
def gnome_power_svc_status():
print("* GNOME power profiles status")
call(["systemctl", "status", "power-profiles-daemon"])

try:
print("* GNOME power profiles status")
call(["systemctl", "status", "power-profiles-daemon"])
except:
print("\nUnable to see GNOME power profiles status")
print("If this causes any problems, please submit an issue:")
print("https://github.com/AdnanHodzic/auto-cpufreq/issues")


# disable bluetooth on boot
def bluetooth_disable():
Expand Down Expand Up @@ -145,7 +164,7 @@ def gnome_power_rm_reminder():
if gnome_power_stats != 0:
print("\n----------------------------------- Warning -----------------------------------\n")
print("Detected GNOME Power Profiles daemon service is stopped!")
print("This service will now be enabled again.")
print("This service will now be enabled and started again.")

def gnome_power_rm_reminder_snap():
print("\n----------------------------------- Warning -----------------------------------\n")
Expand All @@ -154,12 +173,12 @@ def gnome_power_rm_reminder_snap():
print("\nSteps to perform this action using auto-cpufreq: power_helper script:")
print("git clone https://github.com/AdnanHodzic/auto-cpufreq.git")
print("cd auto-cpufreq/auto_cpufreq")
print("python3 power_helper.py --gnome-power-enable")
print("python3 power_helper.py --gnome_power_enable")


def valid_options():
print("--gnome-power-enable\t\tEnable GNOME Power Profiles daemon")
print("--gnome-power-disable\t\tDisable GNOME Power Profiles daemon\n")
print("--gnome_power_enable\t\tEnable GNOME Power Profiles daemon")
print("--gnome_power_disable\t\tDisable GNOME Power Profiles daemon\n")


# cli
Expand Down

0 comments on commit 4c5681b

Please sign in to comment.