mirror of
https://github.com/AdnanHodzic/auto-cpufreq.git
synced 2025-07-26 15:14:11 +02:00
Implement dedicated functionality to turn Bluetooth on/off at boot (#836)
* Add flag to turn off bluetooth on boot * Add bluetooth on flag & completions * Remove completions flag & add missing footer * Explain bluetooth_boot_on/off options in Readme * Remove message to cd into auto-cpufreq dir for Snap * Add message how to enable bluetooth on boot during daemon install * Add flag message for those using Snap package
This commit is contained in:
parent
6789cb6ce4
commit
f9b9fe42c9
34
README.md
34
README.md
@ -58,6 +58,8 @@ Example of `auto-cpufreq --stats` CLI output
|
|||||||
- [Update - auto-cpufreq update](#update---auto-cpufreq-update)
|
- [Update - auto-cpufreq update](#update---auto-cpufreq-update)
|
||||||
- [Remove - auto-cpufreq daemon](#remove---auto-cpufreq-daemon)
|
- [Remove - auto-cpufreq daemon](#remove---auto-cpufreq-daemon)
|
||||||
- [stats](#stats)
|
- [stats](#stats)
|
||||||
|
- [bluetooth_boot_off](#bluetooth_boot_off)
|
||||||
|
- [bluetooth_boot_on](#bluetooth_boot_on)
|
||||||
- [Battery charging thresholds](#battery-charging-thresholds)
|
- [Battery charging thresholds](#battery-charging-thresholds)
|
||||||
- [Supported Devices](#supported-devices)
|
- [Supported Devices](#supported-devices)
|
||||||
- [Battery config](#battery-config)
|
- [Battery config](#battery-config)
|
||||||
@ -291,17 +293,23 @@ the repository:
|
|||||||
|
|
||||||
`git clone https://github.com/AdnanHodzic/auto-cpufreq`
|
`git clone https://github.com/AdnanHodzic/auto-cpufreq`
|
||||||
|
|
||||||
Navigate to the directory where `power_helper.py` resides:
|
Make sure to have `psutil` & `pyinotify` Python library installed before next step:
|
||||||
|
|
||||||
`cd auto-cpufreq/auto_cpufreq`
|
If you're using Debian based distro install them by running:
|
||||||
|
|
||||||
Make sure to have `psutil` Python library installed before next step:
|
`sudo apt install python3-psutil python3-pyinotify`
|
||||||
|
|
||||||
`sudo python3 -m pip install psutil`
|
or manually using pip, e.g:
|
||||||
|
|
||||||
|
`sudo pip3 install psutil pyinotify --break-system-packages`
|
||||||
|
|
||||||
Then disable the GNOME Power Profiles daemon:
|
Then disable the GNOME Power Profiles daemon:
|
||||||
|
|
||||||
`sudo python3 power_helper.py --gnome_power_disable`
|
`sudo python3 -m auto_cpufreq.power_helper --gnome_power_disable`
|
||||||
|
|
||||||
|
for full list of options run --help, e.g:
|
||||||
|
|
||||||
|
`sudo python3 -m auto_cpufreq.power_helper --help`
|
||||||
|
|
||||||
### 2: `--force` governor override
|
### 2: `--force` governor override
|
||||||
|
|
||||||
@ -434,6 +442,12 @@ auto-cpufreq should be run with with one of the following options:
|
|||||||
- [stats](#stats)
|
- [stats](#stats)
|
||||||
- View live stats of CPU optimizations made by daemon
|
- View live stats of CPU optimizations made by daemon
|
||||||
|
|
||||||
|
- [bluetooth_boot_off](#bluetooth_boot_off)
|
||||||
|
- Turn off Bluetooth on boot (only)! Can be turned on any time later on.
|
||||||
|
|
||||||
|
- [bluetooth_boot_on](#bluetooth_boot_on)
|
||||||
|
- Turn on Bluetooth on boot.
|
||||||
|
|
||||||
- [force=TEXT](#overriding-governor)
|
- [force=TEXT](#overriding-governor)
|
||||||
- Force use of either the "powersave" or "performance" governor, or set to "reset" to go back to normal mode
|
- Force use of either the "powersave" or "performance" governor, or set to "reset" to go back to normal mode
|
||||||
|
|
||||||
@ -544,6 +558,16 @@ If the daemon has been installed, live stats of CPU/system load monitoring and o
|
|||||||
|
|
||||||
`auto-cpufreq --stats`
|
`auto-cpufreq --stats`
|
||||||
|
|
||||||
|
### bluetooth_boot_off
|
||||||
|
|
||||||
|
Turn off Bluetooth on boot (only)! Bluetooth can still be turned on manually when needed. This option is executed during the installation of the auto-cpufreq daemon, but it can also be run independently without installing the daemon.
|
||||||
|
|
||||||
|
It prevents GNOME from automatically enabling Bluetooth on every reboot or after suspend/wake up even if you manually disable it, GNOME will turn it back on unless this option is used.
|
||||||
|
|
||||||
|
### bluetooth_boot_on
|
||||||
|
|
||||||
|
Useful if you prefer Bluetooth to be enabled at boot time, especially after installing the auto-cpufreq daemon, which will disable it by default.
|
||||||
|
|
||||||
## Battery charging thresholds
|
## Battery charging thresholds
|
||||||
|
|
||||||
***Please note:** [Original implementor](https://github.com/AdnanHodzic/auto-cpufreq/pull/637) is looking for user input & testing to further improve this functionality. If you would like to help in this process, please refer to [Looking for developers and co-maintainers](https://github.com/AdnanHodzic/auto-cpufreq/#looking-for-developers-and-co-maintainers)*.
|
***Please note:** [Original implementor](https://github.com/AdnanHodzic/auto-cpufreq/pull/637) is looking for user input & testing to further improve this functionality. If you would like to help in this process, please refer to [Looking for developers and co-maintainers](https://github.com/AdnanHodzic/auto-cpufreq/#looking-for-developers-and-co-maintainers)*.
|
||||||
|
@ -5,15 +5,16 @@
|
|||||||
# Blog post: https://foolcontrol.org/?p=3124
|
# Blog post: https://foolcontrol.org/?p=3124
|
||||||
|
|
||||||
# core import
|
# core import
|
||||||
import sys, time
|
import sys, time, os
|
||||||
from subprocess import run
|
from subprocess import run
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
|
|
||||||
from auto_cpufreq.battery_scripts.battery import *
|
from auto_cpufreq.battery_scripts.battery import *
|
||||||
from auto_cpufreq.config.config import config as conf, find_config_file
|
from auto_cpufreq.config.config import config as conf, find_config_file
|
||||||
from auto_cpufreq.core import *
|
from auto_cpufreq.core import *
|
||||||
from auto_cpufreq.globals import GITHUB, IS_INSTALLED_WITH_AUR, IS_INSTALLED_WITH_SNAP
|
from auto_cpufreq.globals import GITHUB, IS_INSTALLED_WITH_AUR, IS_INSTALLED_WITH_SNAP, SNAP_DAEMON_CHECK
|
||||||
from auto_cpufreq.modules.system_monitor import ViewType, SystemMonitor
|
from auto_cpufreq.modules.system_monitor import ViewType, SystemMonitor
|
||||||
|
# import everything from power_helper, including bluetooth_disable and bluetooth_enable
|
||||||
from auto_cpufreq.power_helper import *
|
from auto_cpufreq.power_helper import *
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
@ -28,11 +29,15 @@ from threading import Thread
|
|||||||
@click.option("--config", is_flag=False, required=False, help="Use config file at defined path",)
|
@click.option("--config", is_flag=False, required=False, help="Use config file at defined path",)
|
||||||
@click.option("--stats", is_flag=True, help="View live stats of CPU optimizations made by daemon")
|
@click.option("--stats", is_flag=True, help="View live stats of CPU optimizations made by daemon")
|
||||||
@click.option("--get-state", is_flag=True, hidden=True)
|
@click.option("--get-state", is_flag=True, hidden=True)
|
||||||
@click.option("--completions", is_flag=False, help="Enables shell completions for bash, zsh and fish.\n Possible values bash|zsh|fish")
|
@click.option("--bluetooth_boot_off", is_flag=True, help="Turn off Bluetooth on boot")
|
||||||
|
@click.option("--bluetooth_boot_on", is_flag=True, help="Turn on Bluetooth on boot")
|
||||||
@click.option("--debug", is_flag=True, help="Show debug info (include when submitting bugs)")
|
@click.option("--debug", is_flag=True, help="Show debug info (include when submitting bugs)")
|
||||||
@click.option("--version", is_flag=True, help="Show currently installed version")
|
@click.option("--version", is_flag=True, help="Show currently installed version")
|
||||||
@click.option("--donate", is_flag=True, help="Support the project")
|
@click.option("--donate", is_flag=True, help="Support the project")
|
||||||
def main(monitor, live, daemon, install, update, remove, force, config, stats, get_state, completions, debug, version, donate):
|
def main(monitor, live, daemon, install, update, remove, force, config, stats, get_state,
|
||||||
|
bluetooth_boot_off,
|
||||||
|
bluetooth_boot_on,
|
||||||
|
debug, version, donate):
|
||||||
# display info if config file is used
|
# display info if config file is used
|
||||||
config_path = find_config_file(config)
|
config_path = find_config_file(config)
|
||||||
conf.set_path(config_path)
|
conf.set_path(config_path)
|
||||||
@ -40,22 +45,25 @@ def main(monitor, live, daemon, install, update, remove, force, config, stats, g
|
|||||||
if conf.has_config():
|
if conf.has_config():
|
||||||
print("\nUsing settings defined in " + config_path + " file")
|
print("\nUsing settings defined in " + config_path + " file")
|
||||||
|
|
||||||
if len(sys.argv) == 1:
|
# Check for empty arguments first
|
||||||
|
is_empty_run = len(sys.argv) == 1
|
||||||
|
|
||||||
|
# set governor override unless None or invalid, but not if it's an empty run
|
||||||
|
if not is_empty_run and force is not None:
|
||||||
|
not_running_daemon_check()
|
||||||
|
root_check()
|
||||||
|
set_override(force)
|
||||||
|
|
||||||
|
# Handle empty run after potential force override is processed or skipped
|
||||||
|
if is_empty_run:
|
||||||
print("\n" + "-" * 32 + " auto-cpufreq " + "-" * 33 + "\n")
|
print("\n" + "-" * 32 + " auto-cpufreq " + "-" * 33 + "\n")
|
||||||
print("Automatic CPU speed & power optimizer for Linux")
|
print("Automatic CPU speed & power optimizer for Linux")
|
||||||
|
|
||||||
print("\nExample usage:\nauto-cpufreq --monitor")
|
print("\nExample usage:\nauto-cpufreq --monitor")
|
||||||
print("\n-----\n")
|
print("\n-----\n")
|
||||||
|
|
||||||
run(["auto-cpufreq", "--help"])
|
run(["auto-cpufreq", "--help"])
|
||||||
footer()
|
footer()
|
||||||
|
# Handle other flags if it's not an empty run
|
||||||
else:
|
else:
|
||||||
# set governor override unless None or invalid
|
|
||||||
if force is not None:
|
|
||||||
not_running_daemon_check()
|
|
||||||
root_check() # Calling root_check before set_override as it will require sudo access
|
|
||||||
set_override(force) # Calling set override, only if force has some values
|
|
||||||
|
|
||||||
if monitor:
|
if monitor:
|
||||||
root_check()
|
root_check()
|
||||||
battery_setup()
|
battery_setup()
|
||||||
@ -67,15 +75,21 @@ def main(monitor, live, daemon, install, update, remove, force, config, stats, g
|
|||||||
gnome_power_detect()
|
gnome_power_detect()
|
||||||
tlp_service_detect()
|
tlp_service_detect()
|
||||||
|
|
||||||
if IS_INSTALLED_WITH_SNAP or tlp_stat_exists or (systemctl_exists and not bool(gnome_power_status)):
|
# Determine if confirmation is needed
|
||||||
|
needs_confirmation = IS_INSTALLED_WITH_SNAP or tlp_stat_exists
|
||||||
|
# Check gnome_power_status only if relevant variables exist
|
||||||
|
if not IS_INSTALLED_WITH_SNAP and 'systemctl_exists' in globals() and systemctl_exists and 'gnome_power_status' in locals() and not bool(gnome_power_status):
|
||||||
|
needs_confirmation = True
|
||||||
|
|
||||||
|
if needs_confirmation:
|
||||||
try:
|
try:
|
||||||
input("press Enter to continue or Ctrl + c to exit...")
|
input("press Enter to continue or Ctrl + c to exit...")
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
conf.notifier.stop()
|
conf.notifier.stop()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
monitor = SystemMonitor(suggestion=True, type=ViewType.MONITOR)
|
monitor_instance = SystemMonitor(suggestion=True, type=ViewType.MONITOR)
|
||||||
monitor.run(on_quit=conf.notifier.stop)
|
monitor_instance.run(on_quit=conf.notifier.stop)
|
||||||
elif live:
|
elif live:
|
||||||
root_check()
|
root_check()
|
||||||
battery_setup()
|
battery_setup()
|
||||||
@ -89,7 +103,13 @@ def main(monitor, live, daemon, install, update, remove, force, config, stats, g
|
|||||||
tuned_stop_live()
|
tuned_stop_live()
|
||||||
tlp_service_detect()
|
tlp_service_detect()
|
||||||
|
|
||||||
if IS_INSTALLED_WITH_SNAP or tlp_stat_exists or (systemctl_exists and not bool(gnome_power_status)):
|
# Determine if confirmation is needed
|
||||||
|
needs_confirmation = IS_INSTALLED_WITH_SNAP or tlp_stat_exists
|
||||||
|
# Check gnome_power_status only if relevant variables exist
|
||||||
|
if not IS_INSTALLED_WITH_SNAP and 'systemctl_exists' in globals() and systemctl_exists and 'gnome_power_status' in locals() and not bool(gnome_power_status):
|
||||||
|
needs_confirmation = True
|
||||||
|
|
||||||
|
if needs_confirmation:
|
||||||
try:
|
try:
|
||||||
input("press Enter to continue or Ctrl + c to exit...")
|
input("press Enter to continue or Ctrl + c to exit...")
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
@ -98,18 +118,19 @@ def main(monitor, live, daemon, install, update, remove, force, config, stats, g
|
|||||||
|
|
||||||
cpufreqctl()
|
cpufreqctl()
|
||||||
def live_daemon():
|
def live_daemon():
|
||||||
# Redirect stdout to suppress prints
|
|
||||||
class NullWriter:
|
class NullWriter:
|
||||||
def write(self, _): pass
|
def write(self, _): pass
|
||||||
def flush(self): pass
|
def flush(self): pass
|
||||||
|
original_stdout = sys.stdout
|
||||||
try:
|
try:
|
||||||
sys.stdout = NullWriter()
|
sys.stdout = NullWriter()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
set_autofreq()
|
set_autofreq()
|
||||||
except:
|
except Exception as e: # Catch specific exceptions if possible
|
||||||
pass
|
print(f"Error in live daemon thread: {e}", file=original_stdout) # Log errors
|
||||||
|
finally:
|
||||||
|
sys.stdout = original_stdout # Ensure stdout is restored
|
||||||
|
|
||||||
def live_daemon_off():
|
def live_daemon_off():
|
||||||
gnome_power_start_live()
|
gnome_power_start_live()
|
||||||
@ -120,12 +141,12 @@ def main(monitor, live, daemon, install, update, remove, force, config, stats, g
|
|||||||
thread = Thread(target=live_daemon, daemon=True)
|
thread = Thread(target=live_daemon, daemon=True)
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
monitor = SystemMonitor(type=ViewType.LIVE)
|
monitor_instance = SystemMonitor(type=ViewType.LIVE)
|
||||||
monitor.run(on_quit=live_daemon_off)
|
monitor_instance.run(on_quit=live_daemon_off)
|
||||||
elif daemon:
|
elif daemon:
|
||||||
config_info_dialog()
|
config_info_dialog()
|
||||||
root_check()
|
root_check()
|
||||||
file_stats()
|
file_stats() # This function from core.py likely uses the stats paths internally
|
||||||
if IS_INSTALLED_WITH_SNAP and SNAP_DAEMON_CHECK == "enabled":
|
if IS_INSTALLED_WITH_SNAP and SNAP_DAEMON_CHECK == "enabled":
|
||||||
gnome_power_detect_snap()
|
gnome_power_detect_snap()
|
||||||
tlp_service_detect_snap()
|
tlp_service_detect_snap()
|
||||||
@ -134,83 +155,142 @@ def main(monitor, live, daemon, install, update, remove, force, config, stats, g
|
|||||||
tlp_service_detect()
|
tlp_service_detect()
|
||||||
battery_setup()
|
battery_setup()
|
||||||
conf.notifier.start()
|
conf.notifier.start()
|
||||||
while True:
|
print("Starting auto-cpufreq daemon...") # Add startup message
|
||||||
try:
|
try:
|
||||||
footer()
|
# Initial setup before loop
|
||||||
gov_check()
|
gov_check()
|
||||||
cpufreqctl()
|
cpufreqctl()
|
||||||
distro_info()
|
distro_info() # Show info once on start
|
||||||
sysinfo()
|
sysinfo() # Show info once on start
|
||||||
|
while True:
|
||||||
set_autofreq()
|
set_autofreq()
|
||||||
countdown(2)
|
time.sleep(2) # Use simple sleep instead of countdown
|
||||||
except KeyboardInterrupt: break
|
except KeyboardInterrupt:
|
||||||
|
print("\nDaemon interrupted. Restoring settings...")
|
||||||
|
finally: # Ensure cleanup happens
|
||||||
conf.notifier.stop()
|
conf.notifier.stop()
|
||||||
|
cpufreqctl_restore() # Restore system state when daemon stops
|
||||||
|
footer()
|
||||||
elif install:
|
elif install:
|
||||||
root_check()
|
root_check()
|
||||||
if IS_INSTALLED_WITH_SNAP:
|
if IS_INSTALLED_WITH_SNAP:
|
||||||
running_daemon_check()
|
running_daemon_check()
|
||||||
gnome_power_detect_snap()
|
gnome_power_detect_snap()
|
||||||
tlp_service_detect_snap()
|
tlp_service_detect_snap()
|
||||||
bluetooth_notif_snap()
|
bluetooth_notif_snap() # Warn about bluetooth boot setting
|
||||||
gov_check()
|
gov_check()
|
||||||
run("snapctl set daemon=enabled", shell=True)
|
run("snapctl set daemon=enabled", shell=True, check=True)
|
||||||
run("snapctl start --enable auto-cpufreq", shell=True)
|
run("snapctl start --enable auto-cpufreq", shell=True, check=True)
|
||||||
else:
|
else:
|
||||||
running_daemon_check()
|
running_daemon_check()
|
||||||
gov_check()
|
gov_check()
|
||||||
deploy_daemon()
|
deploy_daemon() # This function from core.py likely uses stats paths
|
||||||
deploy_complete_msg()
|
deploy_complete_msg()
|
||||||
elif update:
|
elif update:
|
||||||
root_check()
|
root_check()
|
||||||
custom_dir = "/opt/auto-cpufreq/source"
|
custom_dir = "/opt/auto-cpufreq/source"
|
||||||
|
update_flag_present = False
|
||||||
|
args_to_remove = []
|
||||||
|
# Simplified update argument parsing
|
||||||
|
if "--update" in sys.argv:
|
||||||
|
update_flag_present = True
|
||||||
|
args_to_remove.append("--update")
|
||||||
|
# Simple check if next arg exists and isn't another flag
|
||||||
|
idx = sys.argv.index("--update")
|
||||||
|
if idx + 1 < len(sys.argv) and not sys.argv[idx+1].startswith('--'):
|
||||||
|
custom_dir = sys.argv[idx+1]
|
||||||
|
args_to_remove.append(custom_dir)
|
||||||
|
else:
|
||||||
for arg in sys.argv:
|
for arg in sys.argv:
|
||||||
if arg.startswith("--update="):
|
if arg.startswith("--update="):
|
||||||
custom_dir = arg.split("=")[1]
|
update_flag_present = True
|
||||||
sys.argv.remove(arg)
|
custom_dir = arg.split("=", 1)[1]
|
||||||
|
args_to_remove.append(arg)
|
||||||
|
break # Found it, no need to check further
|
||||||
|
|
||||||
if "--update" in sys.argv:
|
# Remove the parsed arguments
|
||||||
update = True
|
# This prevents them from being misinterpreted later if code relies on sys.argv directly
|
||||||
sys.argv.remove("--update")
|
_original_argv = sys.argv[:] # Make a copy if needed elsewhere
|
||||||
if len(sys.argv) == 2: custom_dir = sys.argv[1]
|
sys.argv = [arg for arg in sys.argv if arg not in args_to_remove]
|
||||||
|
|
||||||
|
|
||||||
|
if update_flag_present:
|
||||||
if IS_INSTALLED_WITH_SNAP:
|
if IS_INSTALLED_WITH_SNAP:
|
||||||
print("Detected auto-cpufreq was installed using snap")
|
print("Detected auto-cpufreq was installed using snap")
|
||||||
# refresh snap directly using this command
|
|
||||||
# path wont work in this case
|
|
||||||
|
|
||||||
print("Please update using snap package manager, i.e: `sudo snap refresh auto-cpufreq`.")
|
print("Please update using snap package manager, i.e: `sudo snap refresh auto-cpufreq`.")
|
||||||
#check for AUR
|
elif IS_INSTALLED_WITH_AUR:
|
||||||
elif IS_INSTALLED_WITH_AUR: print("Arch-based distribution with AUR support detected. Please refresh auto-cpufreq using your AUR helper.")
|
print("Arch-based distribution with AUR support detected. Please refresh auto-cpufreq using your AUR helper.")
|
||||||
else:
|
else:
|
||||||
is_new_update = check_for_update()
|
is_new_update = check_for_update()
|
||||||
if not is_new_update: return
|
if not is_new_update: return
|
||||||
ans = input("Do you want to update auto-cpufreq to the latest release? [Y/n]: ").strip().lower()
|
ans = input(f"Update source will be placed in '{custom_dir}'.\nDo you want to update auto-cpufreq to the latest release? [Y/n]: ").strip().lower()
|
||||||
if not os.path.exists(custom_dir): os.makedirs(custom_dir)
|
|
||||||
if os.path.exists(os.path.join(custom_dir, "auto-cpufreq")): rmtree(os.path.join(custom_dir, "auto-cpufreq"))
|
|
||||||
if ans in ['', 'y', 'yes']:
|
if ans in ['', 'y', 'yes']:
|
||||||
remove_daemon()
|
# Ensure directory exists
|
||||||
remove_complete_msg()
|
os.makedirs(custom_dir, exist_ok=True)
|
||||||
new_update(custom_dir)
|
auto_cpufreq_subdir = os.path.join(custom_dir, "auto-cpufreq")
|
||||||
print("enabling daemon")
|
if os.path.isdir(auto_cpufreq_subdir):
|
||||||
run(["auto-cpufreq", "--install"])
|
print(f"Removing existing source sub-directory: {auto_cpufreq_subdir}")
|
||||||
print("auto-cpufreq is installed with the latest version")
|
try:
|
||||||
run(["auto-cpufreq", "--version"])
|
rmtree(auto_cpufreq_subdir)
|
||||||
else: print("Aborted")
|
except OSError as e:
|
||||||
|
print(f"Error removing directory {auto_cpufreq_subdir}: {e}")
|
||||||
|
print("Update aborted.")
|
||||||
|
return # Stop update if cleanup fails
|
||||||
|
|
||||||
|
print("Removing existing installation (if any)...")
|
||||||
|
remove_daemon() # Call remove logic first
|
||||||
|
# remove_complete_msg() # Optional message
|
||||||
|
print(f"Downloading new version to {custom_dir}...")
|
||||||
|
new_update(custom_dir) # Download the update
|
||||||
|
print("Running installer for the updated version...")
|
||||||
|
# Use subprocess.run to call the install command of the main script
|
||||||
|
install_result = run([_original_argv[0], "--install"], check=False) # Use original script path
|
||||||
|
if install_result.returncode == 0:
|
||||||
|
print("\nUpdate and installation successful.")
|
||||||
|
run([_original_argv[0], "--version"])
|
||||||
|
else:
|
||||||
|
print("\nError during installation after update. Please check messages above.")
|
||||||
|
else:
|
||||||
|
print("Update aborted.")
|
||||||
|
# else: # If neither --update nor --update= was found
|
||||||
|
# Potentially show help or an error if update was expected
|
||||||
|
# print("Update command not used correctly.")
|
||||||
|
# run([_original_argv[0], "--help"])
|
||||||
|
|
||||||
elif remove:
|
elif remove:
|
||||||
root_check()
|
root_check()
|
||||||
if IS_INSTALLED_WITH_SNAP:
|
if IS_INSTALLED_WITH_SNAP:
|
||||||
run("snapctl set daemon=disabled", shell=True)
|
run("snapctl stop auto-cpufreq", shell=True, check=False)
|
||||||
run("snapctl stop --disable auto-cpufreq", shell=True)
|
run("snapctl set daemon=disabled", shell=True, check=True)
|
||||||
if auto_cpufreq_stats_path.exists():
|
# run("snapctl disable auto-cpufreq", shell=True, check=True) # Deprecated? Use stop --disable
|
||||||
if auto_cpufreq_stats_file is not None:
|
run("snapctl stop --disable auto-cpufreq", shell=True, check=True) # Correct way to stop and disable
|
||||||
auto_cpufreq_stats_file.close()
|
|
||||||
|
|
||||||
|
# Check if stats path/file variables exist before using them
|
||||||
|
# These should be available from 'from auto_cpufreq.core import *'
|
||||||
|
if 'auto_cpufreq_stats_path' in globals() and auto_cpufreq_stats_path.exists():
|
||||||
|
# Close file handle safely
|
||||||
|
if 'auto_cpufreq_stats_file' in globals() and auto_cpufreq_stats_file is not None:
|
||||||
|
if not auto_cpufreq_stats_file.closed:
|
||||||
|
try:
|
||||||
|
auto_cpufreq_stats_file.close()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Warning: Could not close stats file handle: {e}")
|
||||||
|
# Set to None after closing or if already closed
|
||||||
|
# auto_cpufreq_stats_file = None # Modifying imported var might be tricky
|
||||||
|
|
||||||
|
# Remove the file
|
||||||
|
try:
|
||||||
auto_cpufreq_stats_path.unlink()
|
auto_cpufreq_stats_path.unlink()
|
||||||
# ToDo:
|
print(f"Removed stats file: {auto_cpufreq_stats_path}")
|
||||||
# {the following snippet also used in --update, update it there too(if required)}
|
except OSError as e:
|
||||||
# * undo bluetooth boot disable
|
print(f"Warning: Could not remove stats file {auto_cpufreq_stats_path}: {e}")
|
||||||
|
|
||||||
|
# Reminders
|
||||||
gnome_power_rm_reminder_snap()
|
gnome_power_rm_reminder_snap()
|
||||||
else: remove_daemon()
|
bluetooth_on_notif_snap()
|
||||||
|
else:
|
||||||
|
remove_daemon() # Defined in core.py, handles service removal and cleanup including stats file
|
||||||
remove_complete_msg()
|
remove_complete_msg()
|
||||||
elif stats:
|
elif stats:
|
||||||
not_running_daemon_check()
|
not_running_daemon_check()
|
||||||
@ -222,34 +302,47 @@ def main(monitor, live, daemon, install, update, remove, force, config, stats, g
|
|||||||
gnome_power_detect()
|
gnome_power_detect()
|
||||||
tlp_service_detect()
|
tlp_service_detect()
|
||||||
|
|
||||||
if IS_INSTALLED_WITH_SNAP or tlp_stat_exists or (systemctl_exists and not bool(gnome_power_status)):
|
# Determine if confirmation is needed
|
||||||
|
needs_confirmation = IS_INSTALLED_WITH_SNAP or tlp_stat_exists
|
||||||
|
# Check gnome_power_status only if relevant variables exist
|
||||||
|
if not IS_INSTALLED_WITH_SNAP and 'systemctl_exists' in globals() and systemctl_exists and 'gnome_power_status' in locals() and not bool(gnome_power_status):
|
||||||
|
needs_confirmation = True
|
||||||
|
|
||||||
|
if needs_confirmation:
|
||||||
try:
|
try:
|
||||||
input("press Enter to continue or Ctrl + c to exit...")
|
input("press Enter to continue or Ctrl + c to exit...")
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
conf.notifier.stop()
|
# conf.notifier might not be started for stats mode
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
monitor = SystemMonitor(type=ViewType.STATS)
|
monitor_instance = SystemMonitor(type=ViewType.STATS)
|
||||||
monitor.run()
|
monitor_instance.run()
|
||||||
elif get_state:
|
elif get_state:
|
||||||
not_running_daemon_check()
|
not_running_daemon_check()
|
||||||
override = get_override()
|
override = get_override()
|
||||||
print(override)
|
print(override)
|
||||||
elif completions:
|
|
||||||
if completions == "bash":
|
elif bluetooth_boot_off:
|
||||||
print("Run the below command in your current shell!\n")
|
if IS_INSTALLED_WITH_SNAP:
|
||||||
print("echo 'eval \"$(_AUTO_CPUFREQ_COMPLETE=bash_source auto-cpufreq)\"' >> ~/.bashrc")
|
footer()
|
||||||
print("source ~/.bashrc")
|
bluetooth_notif_snap()
|
||||||
elif completions == "zsh":
|
footer()
|
||||||
print("Run the below command in your current shell!\n")
|
else:
|
||||||
print("echo 'eval \"$(_AUTO_CPUFREQ_COMPLETE=zsh_source auto-cpufreq)\"' >> ~/.zshrc")
|
footer()
|
||||||
print("source ~/.zshrc")
|
root_check()
|
||||||
elif completions == "fish":
|
bluetooth_disable()
|
||||||
print("Run the below command in your current shell!\n")
|
footer()
|
||||||
print("echo '_AUTO_CPUFREQ_COMPLETE=fish_source auto-cpufreq | source' > ~/.config/fish/completions/auto-cpufreq.fish")
|
elif bluetooth_boot_on:
|
||||||
else: print("Invalid Option, try bash|zsh|fish as argument to --completions")
|
if IS_INSTALLED_WITH_SNAP:
|
||||||
|
footer()
|
||||||
|
bluetooth_on_notif_snap()
|
||||||
|
footer()
|
||||||
|
else:
|
||||||
|
footer()
|
||||||
|
root_check()
|
||||||
|
bluetooth_enable()
|
||||||
|
footer()
|
||||||
elif debug:
|
elif debug:
|
||||||
# ToDo: add status of GNOME Power Profile service status
|
|
||||||
config_info_dialog()
|
config_info_dialog()
|
||||||
root_check()
|
root_check()
|
||||||
battery_get_thresholds()
|
battery_get_thresholds()
|
||||||
@ -263,7 +356,11 @@ def main(monitor, live, daemon, install, update, remove, force, config, stats, g
|
|||||||
python_info()
|
python_info()
|
||||||
print()
|
print()
|
||||||
device_info()
|
device_info()
|
||||||
|
# Check charging status function exists and call it
|
||||||
|
if 'charging' in globals() and callable(charging):
|
||||||
print(f"Battery is: {'' if charging() else 'dis'}charging")
|
print(f"Battery is: {'' if charging() else 'dis'}charging")
|
||||||
|
else:
|
||||||
|
print("Battery status unavailable.")
|
||||||
print()
|
print()
|
||||||
app_res_use()
|
app_res_use()
|
||||||
get_load()
|
get_load()
|
||||||
@ -281,5 +378,16 @@ def main(monitor, live, daemon, install, update, remove, force, config, stats, g
|
|||||||
print("Show your appreciation by donating!")
|
print("Show your appreciation by donating!")
|
||||||
print(GITHUB+"#donate")
|
print(GITHUB+"#donate")
|
||||||
footer()
|
footer()
|
||||||
|
# else: # Optional: Handle unrecognized flags if not caught by click
|
||||||
|
# print(f"Error: Unrecognized arguments.")
|
||||||
|
# run([_original_argv[0], "--help"])
|
||||||
|
|
||||||
if __name__ == "__main__": main()
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
import click
|
||||||
|
except ImportError:
|
||||||
|
print("Error: Required dependency 'click' not found. Please install it (e.g., pip install click)")
|
||||||
|
sys.exit(1)
|
||||||
|
# Call main entry point
|
||||||
|
main()
|
@ -6,6 +6,7 @@ from shutil import which
|
|||||||
from subprocess import call, DEVNULL, getoutput, STDOUT
|
from subprocess import call, DEVNULL, getoutput, STDOUT
|
||||||
from sys import argv
|
from sys import argv
|
||||||
|
|
||||||
|
# ToDo: update README part how to run this script
|
||||||
from auto_cpufreq.core import *
|
from auto_cpufreq.core import *
|
||||||
from auto_cpufreq.globals import GITHUB, IS_INSTALLED_WITH_SNAP
|
from auto_cpufreq.globals import GITHUB, IS_INSTALLED_WITH_SNAP
|
||||||
from auto_cpufreq.tlp_stat_parser import TLPStatusParser
|
from auto_cpufreq.tlp_stat_parser import TLPStatusParser
|
||||||
@ -16,7 +17,7 @@ app_name = "python3 power_helper.py" if argv[0] == "power_helper.py" else "auto-
|
|||||||
def header(): print("\n------------------------- auto-cpufreq: Power helper -------------------------\n")
|
def header(): print("\n------------------------- auto-cpufreq: Power helper -------------------------\n")
|
||||||
def warning(): print("\n----------------------------------- Warning -----------------------------------\n")
|
def warning(): print("\n----------------------------------- Warning -----------------------------------\n")
|
||||||
|
|
||||||
def helper_opts(): print("\nFor full list of options run: python3 power_helper.py --help")
|
def helper_opts(): print("\nFor full list of options run: python3 -m auto_cpufreq.power_helper --help")
|
||||||
|
|
||||||
# used to check if binary exists on the system
|
# used to check if binary exists on the system
|
||||||
def does_command_exists(cmd): return which(cmd) is not None
|
def does_command_exists(cmd): return which(cmd) is not None
|
||||||
@ -66,8 +67,7 @@ def gnome_power_detect():
|
|||||||
print("\nOnly necessary to be manually done on Snap package installs!")
|
print("\nOnly necessary to be manually done on Snap package installs!")
|
||||||
print("Steps to perform this action using auto-cpufreq: power_helper script:")
|
print("Steps to perform this action using auto-cpufreq: power_helper script:")
|
||||||
print(f"git clone {GITHUB}.git")
|
print(f"git clone {GITHUB}.git")
|
||||||
print("cd auto-cpufreq/auto_cpufreq")
|
print("python3 -m auto_cpufreq.power_helper --gnome_power_disable")
|
||||||
print("python3 power_helper.py --gnome_power_disable")
|
|
||||||
print(f"\nReference: {GITHUB}#configuring-auto-cpufreq")
|
print(f"\nReference: {GITHUB}#configuring-auto-cpufreq")
|
||||||
|
|
||||||
# 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
|
||||||
@ -90,8 +90,7 @@ def gnome_power_detect_snap():
|
|||||||
print("This daemon might interfere with auto-cpufreq and should be disabled!")
|
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("\nSteps to perform this action using auto-cpufreq: power_helper script:")
|
||||||
print(f"git clone {GITHUB}.git")
|
print(f"git clone {GITHUB}.git")
|
||||||
print("cd auto-cpufreq/auto_cpufreq")
|
print("python3 -m auto_cpufreq.power_helper --gnome_power_disable")
|
||||||
print("python3 power_helper.py --gnome_power_disable")
|
|
||||||
print(f"\nReference: {GITHUB}#configuring-auto-cpufreq")
|
print(f"\nReference: {GITHUB}#configuring-auto-cpufreq")
|
||||||
|
|
||||||
# stops gnome >= 40 power profiles (live)
|
# stops gnome >= 40 power profiles (live)
|
||||||
@ -151,7 +150,8 @@ def gnome_power_svc_status():
|
|||||||
def bluetooth_disable():
|
def bluetooth_disable():
|
||||||
if IS_INSTALLED_WITH_SNAP: bluetooth_notif_snap()
|
if IS_INSTALLED_WITH_SNAP: bluetooth_notif_snap()
|
||||||
elif bluetoothctl_exists:
|
elif bluetoothctl_exists:
|
||||||
print("* Turn off bluetooth on boot (can be turned on any time later on!)")
|
print("* Turn off Bluetooth on boot (only)!")
|
||||||
|
print(" If you want bluetooth enabled on boot run: auto-cpufreq --bluetooth_boot_on")
|
||||||
btconf = Path("/etc/bluetooth/main.conf")
|
btconf = Path("/etc/bluetooth/main.conf")
|
||||||
try:
|
try:
|
||||||
orig_set = "AutoEnable=true"
|
orig_set = "AutoEnable=true"
|
||||||
@ -185,13 +185,15 @@ def bluetooth_enable():
|
|||||||
def bluetooth_notif_snap():
|
def bluetooth_notif_snap():
|
||||||
print("\n* Unable to turn off bluetooth on boot due to Snap package restrictions!")
|
print("\n* Unable to turn off bluetooth on boot due to Snap package restrictions!")
|
||||||
print("\nSteps to perform this action using auto-cpufreq: power_helper script:")
|
print("\nSteps to perform this action using auto-cpufreq: power_helper script:")
|
||||||
print("python3 power_helper.py --bluetooth_boot_off")
|
print("python3 -m auto_cpufreq.power_helper --bluetooth_boot_off")
|
||||||
|
print("\nFor help see: https://github.com/AdnanHodzic/auto-cpufreq/#1-power_helperpy-script-snap-package-install-only")
|
||||||
|
|
||||||
# turn off bluetooth on snap message
|
# turn off bluetooth on snap message
|
||||||
def bluetooth_on_notif_snap():
|
def bluetooth_on_notif_snap():
|
||||||
print("\n* Unable to turn on bluetooth on boot due to Snap package restrictions!")
|
print("\n* Unable to turn on bluetooth on boot due to Snap package restrictions!")
|
||||||
print("\nSteps to perform this action using auto-cpufreq: power_helper script:")
|
print("\nSteps to perform this action using auto-cpufreq: power_helper script:")
|
||||||
print("python3 power_helper.py --bluetooth_boot_on")
|
print("python3 -m auto_cpufreq.power_helper --bluetooth_boot_on")
|
||||||
|
print("\nFor help see: https://github.com/AdnanHodzic/auto-cpufreq/#1-power_helperpy-script-snap-package-install-only")
|
||||||
|
|
||||||
# gnome power removal reminder
|
# gnome power removal reminder
|
||||||
def gnome_power_rm_reminder():
|
def gnome_power_rm_reminder():
|
||||||
@ -207,8 +209,7 @@ def gnome_power_rm_reminder_snap():
|
|||||||
print("Now it's recommended to enable this service.")
|
print("Now it's recommended to enable this service.")
|
||||||
print("\nSteps to perform this action using auto-cpufreq: power_helper script:")
|
print("\nSteps to perform this action using auto-cpufreq: power_helper script:")
|
||||||
print(f"git clone {GITHUB}.git")
|
print(f"git clone {GITHUB}.git")
|
||||||
print("cd auto-cpufreq/auto_cpufreq")
|
print("python3 -m auto_cpufreq.power_helper --gnome_power_enable")
|
||||||
print("python3 power_helper.py --gnome_power_enable")
|
|
||||||
print(f"\nReference: {GITHUB}#configuring-auto-cpufreq")
|
print(f"\nReference: {GITHUB}#configuring-auto-cpufreq")
|
||||||
|
|
||||||
def valid_options():
|
def valid_options():
|
||||||
@ -250,11 +251,11 @@ def gnome_power_svc_disable():
|
|||||||
# check if snapd is present and if snap package is installed | 0 is success
|
# check if snapd is present and if snap package is installed | 0 is success
|
||||||
if not bool(snap_pkg_check):
|
if not bool(snap_pkg_check):
|
||||||
print("GNOME Power Profiles Daemon is already disabled, it can be re-enabled by running:\n"
|
print("GNOME Power Profiles Daemon is already disabled, it can be re-enabled by running:\n"
|
||||||
"sudo python3 power_helper.py --gnome_power_enable\n"
|
"sudo python3 -m auto_cpufreq.power_helper --gnome_power_enable\n"
|
||||||
)
|
)
|
||||||
elif snap_pkg_check == 1:
|
elif snap_pkg_check == 1:
|
||||||
print("auto-cpufreq snap package not installed\nGNOME Power Profiles Daemon should be enabled. run:\n\n"
|
print("auto-cpufreq snap package not installed\nGNOME Power Profiles Daemon should be enabled. run:\n\n"
|
||||||
"sudo python3 power_helper.py --gnome_power_enable"
|
"sudo python3 -m auto_cpufreq.power_helper --gnome_power_enable"
|
||||||
)
|
)
|
||||||
except:
|
except:
|
||||||
# snapd not found on the system
|
# snapd not found on the system
|
||||||
@ -264,7 +265,7 @@ def gnome_power_svc_disable():
|
|||||||
if not bool(gnome_power_status) and powerprofilesctl_exists:
|
if not bool(gnome_power_status) and powerprofilesctl_exists:
|
||||||
if snap_pkg_check == 1:
|
if snap_pkg_check == 1:
|
||||||
print("auto-cpufreq snap package not installed.\nGNOME Power Profiles Daemon should be enabled, run:\n\n"
|
print("auto-cpufreq snap package not installed.\nGNOME Power Profiles Daemon should be enabled, run:\n\n"
|
||||||
"sudo python3 power_helper.py --gnome_power_enable"
|
"sudo python3 -m auto_cpufreq.power_helper --gnome_power_enable"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
print("auto-cpufreq snap package installed, GNOME Power Profiles Daemon should be disabled.\n")
|
print("auto-cpufreq snap package installed, GNOME Power Profiles Daemon should be disabled.\n")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user