From e2c95be5dc27acb86aa55c26174f82c7a9db3d5c Mon Sep 17 00:00:00 2001 From: Angel-Karasu Date: Sat, 1 Jun 2024 11:14:13 +0200 Subject: [PATCH 1/3] Remove | in type --- auto_cpufreq/utils/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto_cpufreq/utils/config.py b/auto_cpufreq/utils/config.py index ff673a3b..5f0e196f 100644 --- a/auto_cpufreq/utils/config.py +++ b/auto_cpufreq/utils/config.py @@ -5,7 +5,7 @@ import os import sys -def find_config_file(args_config_file: str | None) -> str: +def find_config_file(args_config_file) -> str: """ Find the config file to use. From 75623575101637655c9bcab4a514e47bafde66fa Mon Sep 17 00:00:00 2001 From: Angel-Karasu Date: Sat, 1 Jun 2024 14:19:21 +0200 Subject: [PATCH 2/3] Repare battery read problem --- auto_cpufreq/battery_scripts/ideapad_acpi.py | 10 +++------- auto_cpufreq/battery_scripts/ideapad_laptop.py | 10 +++------- auto_cpufreq/battery_scripts/thinkpad.py | 10 +++------- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/auto_cpufreq/battery_scripts/ideapad_acpi.py b/auto_cpufreq/battery_scripts/ideapad_acpi.py index 3e53126a..ae783581 100644 --- a/auto_cpufreq/battery_scripts/ideapad_acpi.py +++ b/auto_cpufreq/battery_scripts/ideapad_acpi.py @@ -33,10 +33,6 @@ def ideapad_acpi_print_thresholds(): print(f"battery count = {len(batteries)}") for bat in batteries: try: - with open(f'{POWER_SUPPLY_DIR}{bat}/charge_start_threshold', 'r') as f: - print(f'{bat} start threshold = {f.read()}', end="") - - with open(f'{POWER_SUPPLY_DIR}{bat}/charge_stop_threshold', 'r') as f: - print(f'{bat} stop threshold = {f.read()}', end="") - - except Exception: print(f"ERROR: failed to read battery {bat} thresholds") + print(f'{bat} start threshold = {subprocess.getoutput(f"cat {POWER_SUPPLY_DIR}{bat}/charge_start_threshold")}') + print(f'{bat} start threshold = {subprocess.getoutput(f"cat {POWER_SUPPLY_DIR}{bat}/charge_stop_threshold")}') + except Exception as e: print(f"ERROR: failed to read battery {bat} thresholds: ", repr(e)) diff --git a/auto_cpufreq/battery_scripts/ideapad_laptop.py b/auto_cpufreq/battery_scripts/ideapad_laptop.py index 039072d2..9d724d24 100644 --- a/auto_cpufreq/battery_scripts/ideapad_laptop.py +++ b/auto_cpufreq/battery_scripts/ideapad_laptop.py @@ -64,10 +64,6 @@ def ideapad_laptop_print_thresholds(): print(f"battery count = {len(batteries)}") for bat in batteries: try: - with open(f'{POWER_SUPPLY_DIR}{bat}/charge_start_threshold', 'r') as f: - print(f'{bat} start threshold = {f.read()}', end="") - - with open(f'{POWER_SUPPLY_DIR}{bat}/charge_stop_threshold', 'r') as f: - print(f'{bat} stop threshold = {f.read()}', end="") - - except Exception as e: print(f"ERROR: failed to read {bat} thresholds: {e}") + print(f'{bat} start threshold = {subprocess.getoutput(f"cat {POWER_SUPPLY_DIR}{bat}/charge_start_threshold")}') + print(f'{bat} start threshold = {subprocess.getoutput(f"cat {POWER_SUPPLY_DIR}{bat}/charge_stop_threshold")}') + except Exception as e: print(f"ERROR: failed to read battery {bat} thresholds: ", repr(e)) diff --git a/auto_cpufreq/battery_scripts/thinkpad.py b/auto_cpufreq/battery_scripts/thinkpad.py index 8fad54f5..a37500bc 100644 --- a/auto_cpufreq/battery_scripts/thinkpad.py +++ b/auto_cpufreq/battery_scripts/thinkpad.py @@ -34,10 +34,6 @@ def thinkpad_print_thresholds(): print(f"battery count = {len(batteries)}") for bat in batteries: try: - with open(f'{POWER_SUPPLY_DIR}{bat}/charge_start_threshold', 'r') as f: - print(f'{bat} start threshold = {f.read()}', end="") - - with open(f'{POWER_SUPPLY_DIR}{bat}/charge_stop_threshold', 'r') as f: - print(f'{bat} stop threshold = {f.read()}', end="") - - except Exception: print(f"ERROR: failed to read battery {bat} thresholds") + print(f'{bat} start threshold = {subprocess.getoutput(f"cat {POWER_SUPPLY_DIR}{bat}/charge_start_threshold")}') + print(f'{bat} start threshold = {subprocess.getoutput(f"cat {POWER_SUPPLY_DIR}{bat}/charge_stop_threshold")}') + except Exception as e: print(f"ERROR: failed to read battery {bat} thresholds: ", repr(e)) From cb32d3503fa62a46e1c786e1d26af20d922b92fa Mon Sep 17 00:00:00 2001 From: Angel-Karasu Date: Sat, 1 Jun 2024 14:25:43 +0200 Subject: [PATCH 3/3] Compatible with many arguments --- scripts/auto-cpufreq-venv-wrapper | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/scripts/auto-cpufreq-venv-wrapper b/scripts/auto-cpufreq-venv-wrapper index 7fdc478d..9d030235 100644 --- a/scripts/auto-cpufreq-venv-wrapper +++ b/scripts/auto-cpufreq-venv-wrapper @@ -3,32 +3,15 @@ set -eu -# get script name -PROGNAME=$(basename "${0}") - # bailout function -err_exit() -{ - echo "${PROGNAME}: ${1:-wrong invocation. try --help for help.}" 1>&2 - exit 1 +err_exit() { + echo "$(basename $0): ${1:-wrong invocation. try --help for help.}" 1>&2 + exit 1 } -# invocation handling -# - # load python virtual environment -venv_dir=/opt/auto-cpufreq/venv -. "$venv_dir/bin/activate" +opt_path=/opt/auto-cpufreq +venv_bin_dir=$opt_path/venv/bin +. "$venv_bin_dir/activate" -# run python code with venv loaded -if [[ "$#" -ne 1 ]]; then - PYTHONPATH=/opt/auto-cpufreq \ - /opt/auto-cpufreq/venv/bin/python \ - /opt/auto-cpufreq/venv/bin/auto-cpufreq -else - param="$1" - PYTHONPATH=/opt/auto-cpufreq \ - /opt/auto-cpufreq/venv/bin/python \ - /opt/auto-cpufreq/venv/bin/auto-cpufreq \ - "${param}" -fi +PYTHONPATH=$opt_path $venv_bin_dir/python $venv_bin_dir/auto-cpufreq "$@"