Revamp of bluetooth & gnome power profile control on Snap

This commit is contained in:
Adnan Hodzic 2021-12-02 21:33:02 +01:00
parent 2daa37cf0e
commit d6bfdfc680
4 changed files with 49 additions and 23 deletions

View File

@ -330,6 +330,14 @@ def deploy_daemon():
call("/usr/bin/auto-cpufreq-install", shell=True)
def bt_snap():
if os.getenv("PKG_MARKER") == "SNAP":
try:
print("\n* Turn off bluetooth on boot")
call("rfkill block bluetooth", shell=True)
except:
print("n\nERROR:\nWas unable to turn off bluetooth on boot")
# remove auto-cpufreq daemon
def remove():

View File

@ -14,24 +14,26 @@ else:
app_name="auto-cpufreq"
# detect if gnome power profile service is running
gnome_power_stats = call(["systemctl", "is-active", "--quiet", "power-profiles-daemon"])
if os.getenv('PKG_MARKER') != "SNAP":
gnome_power_stats = call(["systemctl", "is-active", "--quiet", "power-profiles-daemon"])
# alert in case gnome power profile service is running
def gnome_power_detect():
# ToDo: broken, can't be checked like this
if os.getenv('PKG_MARKER') == "SNAP" and gnome_power_stats == 0:
print("\nDetected running 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("python3 gnome_power.py --disable")
elif gnome_power_stats == 0:
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")
# 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("python3 gnome_power.py --disable")
# disable gnome >= 40 power profiles (live)
def gnome_power_disable_live():
if(gnome_power_stats == 0):
@ -62,6 +64,7 @@ def valid_options():
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")
@ -74,10 +77,15 @@ def main(enable, disable):
footer()
else:
if enable:
# Todo: prettify output
root_check()
print("Enabling")
gnome_power_enable()
elif disable:
# Todo: prettify output
root_check()
print("Disabling")
gnome_power_disable()
else:
print("whatever")

View File

@ -46,6 +46,7 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don
config_info_dialog()
file_stats()
if os.getenv("PKG_MARKER") == "SNAP" and dcheck == "enabled":
gnome_power_detect_snap()
while True:
root_check()
footer()
@ -56,6 +57,9 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don
set_autofreq()
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()
@ -73,6 +77,7 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don
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()
@ -85,10 +90,14 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don
config_info_dialog()
print("\nNote: You can quit live mode by pressing \"ctrl+c\"")
time.sleep(1)
if os.getenv("PKG_MARKER") == "SNAP":
gnome_power_detect_snap()
else:
gnome_power_detect()
# ToDo: disable only if not disabled already
gnome_power_disable()
while True:
root_check()
gnome_power_detect()
gnome_power_disable_live()
running_daemon()
footer()
gov_check()
@ -141,8 +150,8 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don
if os.getenv('PKG_MARKER') == "SNAP":
root_check()
running_daemon()
gnome_power_detect()
gnome_power_disable()
gnome_power_detect_snap()
bt_snap()
gov_check()
run("snapctl set daemon=enabled", shell=True)
run("snapctl start --enable auto-cpufreq", shell=True)
@ -151,6 +160,7 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don
root_check()
running_daemon()
gnome_power_detect()
# ToDo: disable only if not disabled already
gnome_power_disable()
gov_check()
deploy_daemon()
@ -165,6 +175,9 @@ def main(config, daemon, debug, install, live, log, monitor, stats, version, don
auto_cpufreq_stats_file.close()
auto_cpufreq_stats_path.unlink()
# ToDo:
# * add message to enable GNOME power profiles again
# * undo bluetooth boot disable
remove_complete_msg()
else:
root_check()

View File

@ -26,6 +26,7 @@ parts:
stage-packages:
- coreutils
- dmidecode
- rfkill
source: .
deploy-scripts:
@ -40,27 +41,21 @@ plugs:
interface: system-files
write:
- /etc/auto-cpufreq.conf
etc-bluetooth-conf:
interface: system-files
write:
- /etc/bluetooth/main.conf
apps:
auto-cpufreq:
command: bin/auto-cpufreq
environment:
PYTHONPATH: $SNAP/usr/lib/python3/site-packages:$SNAP/usr/lib/python3/dist-packages:$PYTHONPATH
LC_ALL: C.UTF-8
LANG: C.UTF-8
PKG_MARKER: SNAP
plugs:
- cpu-control
- system-observe
- hardware-observe
- network-control
- etc-auto-cpufreq-conf
- etc-bluetooth-conf
environment:
LC_ALL: C.UTF-8
LANG: C.UTF-8
PKG_MARKER: SNAP
service:
command: usr/bin/snapdaemon
@ -68,6 +63,8 @@ apps:
- cpu-control
- system-observe
- hardware-observe
- network-control
- etc-auto-cpufreq-conf
environment:
LC_ALL: C.UTF-8
LANG: C.UTF-8