diff --git a/auto-cpufreq-installer b/auto-cpufreq-installer index e4012a9..4d76f03 100755 --- a/auto-cpufreq-installer +++ b/auto-cpufreq-installer @@ -183,11 +183,6 @@ function tool_remove { [ -f $srv_remove ] && rm $srv_remove [ -f $stats_file ] && rm $stats_file - # enable GNOME power profiles in case it was disabled by auto-cpufreq - systemctl unmask power-profiles-daemon - systemctl start power-profiles-daemon - systemctl enable power-profiles-daemon - separator echo -e "\nauto-cpufreq tool and all its supporting files successfully removed." separator diff --git a/auto_cpufreq/core.py b/auto_cpufreq/core.py index 2e9b698..f75e4b1 100644 --- a/auto_cpufreq/core.py +++ b/auto_cpufreq/core.py @@ -80,7 +80,6 @@ def get_config(config_file=''): # get distro name dist_name = distro.id() - # display running version of auto-cpufreq def app_version(): @@ -317,9 +316,6 @@ 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" @@ -328,8 +324,12 @@ def deploy_daemon(): print("\n* Deploy auto-cpufreq remove script") shutil.copy(SCRIPTS_DIR / "auto-cpufreq-remove.sh", "/usr/bin/auto-cpufreq-remove") + # output warning if gnome power profile is running + gnome_power_detect() + call("/usr/bin/auto-cpufreq-install", shell=True) +# ToDo: change to be a warning and move to power_helper? def bt_snap(): if os.getenv("PKG_MARKER") == "SNAP": try: @@ -365,10 +365,10 @@ def remove(): else: print("* Turn on bluetooth on boot [skipping] (package providing bluetooth access is not present)") - # enable gnome power profiles - gnome_power_enable() + # output warning if gnome power profile is stopped + gnome_power_rm_reminder() - # run auto-cpufreq daemon install script + # run auto-cpufreq daemon remove script call("/usr/bin/auto-cpufreq-remove", shell=True) # remove auto-cpufreq-remove diff --git a/auto_cpufreq/gnome_power.py b/auto_cpufreq/gnome_power.py index 36a1765..7a5ec41 100644 --- a/auto_cpufreq/gnome_power.py +++ b/auto_cpufreq/gnome_power.py @@ -20,25 +20,34 @@ if os.getenv('PKG_MARKER') != "SNAP": # alert in case gnome power profile service is running def gnome_power_detect(): if 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!") - 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") + print("\n----------------------------------- Warning -----------------------------------\n") + print("Detected running GNOME Power Profiles daemon service!") + print("This daemon might interfere with auto-cpufreq and should be disabled.") + 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") + # ToDo: add proper argument after rename + print("python3 gnome_power.py --disable") + # notification on snap def gnome_power_detect_snap(): - print("\nUnable to detect state of GNOME Power Profiles daemon service:") - print("This daemon might interfere with auto-cpufreq and should be disabled!\n") - print("Due to Snap limitations, it needs to be disabled manually by running, i.e:") - print("cd ~/auto-cpufreq/auto_cpufreq") + print("\n----------------------------------- Warning -----------------------------------\n") + print("Unable to detect state of GNOME Power Profiles daemon service!") + print("This daemon might interfere with auto-cpufreq and should be disabled.") + 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 gnome_power.py --disable") + +# ToDo: remove function? # disable gnome >= 40 power profiles (live) def gnome_power_disable_live(): if(gnome_power_stats == 0): call(["systemctl", "stop", "power-profiles-daemon"]) + # disable gnome >= 40 power profiles (install) def gnome_power_disable(): if(gnome_power_stats == 0): @@ -46,46 +55,79 @@ def gnome_power_disable(): call(["systemctl", "stop", "power-profiles-daemon"]) call(["systemctl", "disable", "power-profiles-daemon"]) call(["systemctl", "mask", "power-profiles-daemon"]) - else: - print("\n* Disabling GNOME power profiles (already disabled)") + call(["systemctl", "daemon-reload"]) # enable gnome >= 40 power profiles (uninstall) def gnome_power_enable(): - if(gnome_power_stats == 0): + 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("\n* Enabling GNOME power profiles (already enabled)") + call(["systemctl", "daemon-reload"]) + +# gnome power profiles current status +def gnome_power_status(): + print("\n* GNOME power profiles status") + call(["systemctl", "status", "power-profiles-daemon"]) + # ToDo: add how to disable/enable + +# gnome power removal reminder +def gnome_power_rm_reminder(): + if gnome_power_stats != 0: + print("\n----------------------------------- Warning -----------------------------------\n") + print("Detected GNOME Power Profiles daemon service is stopped!") + print("Now it's recommended to enable this service.") + 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 gnome_power.py --enable") + +def gnome_power_rm_reminder_snap(): + print("\n----------------------------------- Warning -----------------------------------\n") + print("\nUnable to detect state of GNOME Power Profiles daemon service!") + print("Now it's recommended to enable this service.") + 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 gnome_power.py --enable") def valid_options(): print("--enable\t\tEnable GNOME Power Profiles daemon") print("--disable\t\tDisable GNOME Power Profiles daemon\n") + # cli -# ToDo: implement status option @click.command() -@click.option("--enable", is_flag=True, help="Monitor and see suggestions for CPU optimizations") -@click.option("--disable", is_flag=True, help="Monitor and make (temp.) suggested CPU optimizations") -def main(enable, disable): +@click.option("--enable", is_flag=True, help="Enable GNOME Power profiles service") +@click.option("--disable", is_flag=True, help="Disable GNOME Power profiles service") +@click.option("--status", is_flag=True, help="Get status of GNOME Power profiles service") +def main(enable, disable, status): root_check() if len(sys.argv) == 1: - print("---------------- auto-cpufreq: GNOME Power Profiles helper --------------------\n") + print("\n------------------------- auto-cpufreq: Power helper -------------------------\n") print("Unrecognized option!\n\nRun: \"" + app_name + " --help\" for list of available options.") footer() else: if enable: - # Todo: prettify output + footer() root_check() - print("Enabling") + print("Enabling GNOME Power Profiles") gnome_power_enable() + footer() elif disable: - # Todo: prettify output + footer() root_check() - print("Disabling") + print("Disabling GNOME Power Profiles") gnome_power_disable() + footer() + elif status: + footer() + root_check() + print("Status of GNOME Power Profiles") + gnome_power_status() + footer() else: print("whatever") diff --git a/bin/auto-cpufreq b/bin/auto-cpufreq index 9c80961..66db935 100755 --- a/bin/auto-cpufreq +++ b/bin/auto-cpufreq @@ -2,7 +2,7 @@ # # auto-cpufreq - Automatic CPU speed & power optimizer for Linux # -# Blog post: http://foolcontrol.org/?p=3124 +# Blog post: https://foolcontrol.org/?p=3124 # core import import sys @@ -12,7 +12,7 @@ from subprocess import call, run sys.path.append('../') from auto_cpufreq.core import * -#from auto_cpufreq.gnome_power import * +from auto_cpufreq.gnome_power import * # cli @click.command() @@ -44,11 +44,11 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don else: if daemon: config_info_dialog() + root_check() file_stats() if os.getenv("PKG_MARKER") == "SNAP" and dcheck == "enabled": gnome_power_detect_snap() while True: - root_check() footer() gov_check() cpufreqctl() @@ -58,10 +58,7 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don countdown(5) elif os.getenv("PKG_MARKER") != "SNAP": gnome_power_detect() - # ToDo: disable only if not disabled already - gnome_power_disable() while True: - root_check() footer() gov_check() cpufreqctl() @@ -73,11 +70,14 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don daemon_not_found() elif monitor: config_info_dialog() + root_check() + print("\nNote: You can quit monitor mode by pressing \"ctrl+c\"") + if os.getenv("PKG_MARKER") == "SNAP": + gnome_power_detect_snap() + else: + gnome_power_detect() while True: - print("\nNote: You can quit monitor mode by pressing \"ctrl+c\"") time.sleep(1) - root_check() - # ToDO: add gnome profile detect/disable? running_daemon() footer() gov_check() @@ -87,6 +87,7 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don mon_autofreq() countdown(5) elif live: + root_check() config_info_dialog() print("\nNote: You can quit live mode by pressing \"ctrl+c\"") time.sleep(1) @@ -94,10 +95,7 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don gnome_power_detect_snap() else: gnome_power_detect() - # ToDo: disable only if not disabled already - gnome_power_disable() while True: - root_check() running_daemon() footer() gov_check() @@ -109,11 +107,16 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don elif stats: config_info_dialog() print("\nNote: You can quit stats mode by pressing \"ctrl+c\"") + if os.getenv("PKG_MARKER") == "SNAP": + gnome_power_detect_snap() + else: + gnome_power_detect() time.sleep(1) read_stats() elif log: deprecated_log_msg() elif debug: + # ToDo: add status of GNOME Power Profile servie status config_info_dialog() root_check() footer() @@ -151,7 +154,8 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don root_check() running_daemon() gnome_power_detect_snap() - bt_snap() + # ToDo: move elsewhere after func revamp + #bt_snap() gov_check() run("snapctl set daemon=enabled", shell=True) run("snapctl start --enable auto-cpufreq", shell=True) @@ -159,9 +163,6 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don else: root_check() running_daemon() - gnome_power_detect() - # ToDo: disable only if not disabled already - gnome_power_disable() gov_check() deploy_daemon() deploy_complete_msg() @@ -176,8 +177,8 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don auto_cpufreq_stats_path.unlink() # ToDo: - # * add message to enable GNOME power profiles again # * undo bluetooth boot disable + gnome_power_rm_reminder_snap() remove_complete_msg() else: root_check() diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 150dd4c..25cc31e 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -26,7 +26,6 @@ parts: stage-packages: - coreutils - dmidecode - - rfkill source: . deploy-scripts: @@ -39,7 +38,7 @@ parts: plugs: etc-auto-cpufreq-conf: interface: system-files - write: + read: - /etc/auto-cpufreq.conf apps: @@ -54,7 +53,6 @@ apps: - cpu-control - system-observe - hardware-observe - - network-control - etc-auto-cpufreq-conf service: @@ -63,7 +61,6 @@ apps: - cpu-control - system-observe - hardware-observe - - network-control - etc-auto-cpufreq-conf environment: LC_ALL: C.UTF-8