Skip to content

Commit

Permalink
consolidate error messages and add daemon checks to --get-state and -…
Browse files Browse the repository at this point in the history
…-stats
  • Loading branch information
shadeyg56 committed Jan 30, 2023
1 parent 723301d commit a339b82
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 26 deletions.
23 changes: 3 additions & 20 deletions auto_cpufreq/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,6 @@ def footer(l=79):
print("\n" + "-" * l + "\n")


def daemon_not_found():
print("\n" + "-" * 32 + " Daemon check " + "-" * 33 + "\n")
print(
"ERROR:\n\nDaemon not enabled, must run install first, i.e: \nsudo auto-cpufreq --install"
)
footer()


def deploy_complete_msg():
print("\n" + "-" * 17 + " auto-cpufreq daemon installed and running " + "-" * 17 + "\n")
print("To view live stats, run:\nauto-cpufreq --stats")
Expand Down Expand Up @@ -1185,20 +1177,12 @@ def sysinfo():
print("\nCPU fan speed:", psutil.sensors_fans()[current_fan][0].current, "RPM")


def no_stats_msg():
print("\n" + "-" * 29 + " auto-cpufreq stats " + "-" * 30 + "\n")
print(
'ERROR: auto-cpufreq stats are missing.\n\nMake sure to run: "auto-cpufreq --install" first'
)


# read stats func
def read_stats():
# read stats
if os.path.isfile(auto_cpufreq_stats_path):
call(["tail", "-n 50", "-f", str(auto_cpufreq_stats_path)], stderr=DEVNULL)
else:
no_stats_msg()
footer()


Expand Down Expand Up @@ -1226,13 +1210,12 @@ def daemon_running_msg():
def daemon_not_running_msg():
print("\n" + "-" * 24 + " auto-cpufreq not running " + "-" * 30 + "\n")
print(
"ERROR: auto-cpufreq is not running in daemon mode.\n\nMake sure to start the daemon with --install before running with --force option"
"ERROR: auto-cpufreq is not running in daemon mode.\n\nMake sure to run \"sudo auto-cpufreq --install\" first"
)
footer()


# check if auto-cpufreq --daemon is running
def running_daemon():
def running_daemon_check():
if is_running("auto-cpufreq", "--daemon"):
daemon_running_msg()
exit(1)
Expand All @@ -1241,7 +1224,7 @@ def running_daemon():
exit(1)

# check if auto-cpufreq --daemon is not running
def not_running_daemon():
def not_running_daemon_check():
if not is_running("auto-cpufreq", "--daemon"):
daemon_not_running_msg()
exit(1)
Expand Down
14 changes: 8 additions & 6 deletions bin/auto-cpufreq
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def main(config, daemon, debug, install, remove, install_performance, live, log,

# set governor override unless None or invalid
if force is not None:
not_running_daemon()
not_running_daemon_check()
set_override(force)

if len(sys.argv) == 1:
Expand Down Expand Up @@ -99,7 +99,7 @@ def main(config, daemon, debug, install, remove, install_performance, live, log,
tlp_service_detect()
while True:
time.sleep(1)
running_daemon()
running_daemon_check()
footer()
gov_check()
cpufreqctl()
Expand All @@ -121,7 +121,7 @@ def main(config, daemon, debug, install, remove, install_performance, live, log,
tlp_service_detect()
while True:
try:
running_daemon()
running_daemon_check()
footer()
gov_check()
cpufreqctl()
Expand All @@ -134,6 +134,7 @@ def main(config, daemon, debug, install, remove, install_performance, live, log,
print("")
sys.exit()
elif stats:
not_running_daemon_check()
config_info_dialog()
print('\nNote: You can quit stats mode by pressing "ctrl+c"')
if os.getenv("PKG_MARKER") == "SNAP":
Expand All @@ -146,6 +147,7 @@ def main(config, daemon, debug, install, remove, install_performance, live, log,
elif log:
deprecated_log_msg()
elif get_state:
not_running_daemon_check()
override = get_override()
print(override)
elif debug:
Expand Down Expand Up @@ -191,14 +193,14 @@ def main(config, daemon, debug, install, remove, install_performance, live, log,
"Reference: https://github.com/AdnanHodzic/auto-cpufreq#configuring-auto-cpufreq\n")
else:
root_check()
running_daemon()
running_daemon_check()
gov_check()
deploy_daemon_performance()
deploy_complete_msg()
elif install:
if os.getenv("PKG_MARKER") == "SNAP":
root_check()
running_daemon()
running_daemon_check()
gnome_power_detect_snap()
tlp_service_detect_snap()
bluetooth_notif_snap()
Expand All @@ -208,7 +210,7 @@ def main(config, daemon, debug, install, remove, install_performance, live, log,
deploy_complete_msg()
else:
root_check()
running_daemon()
running_daemon_check()
gov_check()
deploy_daemon()
deploy_complete_msg()
Expand Down

0 comments on commit a339b82

Please sign in to comment.