diff --git a/auto_cpufreq/battery_scripts/ideapad_acpi.py b/auto_cpufreq/battery_scripts/ideapad_acpi.py index 966132c..cb4334b 100644 --- a/auto_cpufreq/battery_scripts/ideapad_acpi.py +++ b/auto_cpufreq/battery_scripts/ideapad_acpi.py @@ -1,12 +1,13 @@ #!/usr/bin/env python3 -import os, subprocess +import os +from subprocess import check_output from auto_cpufreq.config.config import config from auto_cpufreq.globals import POWER_SUPPLY_DIR def set_battery(value, mode, bat): path = f"{POWER_SUPPLY_DIR}{bat}/charge_{mode}_threshold" - if os.path.isfile(path): subprocess.check_output(f"echo {value} | tee {path}", shell=True, text=True) + if os.path.isfile(path): check_output(f"echo {value} | tee {path}", shell=True, text=True) else: print(f"WARNING: {path} does NOT exist") def get_threshold_value(mode): @@ -32,6 +33,6 @@ def ideapad_acpi_print_thresholds(): print(f"battery count = {len(batteries)}") for bat in batteries: try: - 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")}') + print(bat, "start threshold =", check_output(["cat", POWER_SUPPLY_DIR+bat+"/charge_start_threshold"])) + print(bat, "stop threshold =", check_output(["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 0300162..766160a 100644 --- a/auto_cpufreq/battery_scripts/ideapad_laptop.py +++ b/auto_cpufreq/battery_scripts/ideapad_laptop.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 -import os, subprocess +import os +from subprocess import check_output from auto_cpufreq.config.config import config from auto_cpufreq.globals import CONSERVATION_MODE_FILE, POWER_SUPPLY_DIR @@ -7,7 +8,7 @@ from auto_cpufreq.globals import CONSERVATION_MODE_FILE, POWER_SUPPLY_DIR def set_battery(value, mode, bat): path = f"{POWER_SUPPLY_DIR}{bat}/charge_{mode}_threshold" if os.path.exists(path): - subprocess.check_output(f"echo {value} | tee {POWER_SUPPLY_DIR}{bat}/charge_{mode}_threshold", shell=True, text=True) + check_output(f"echo {value} | tee {POWER_SUPPLY_DIR}{bat}/charge_{mode}_threshold", shell=True, text=True) else: print(f"WARNING: {path} does NOT exist") def get_threshold_value(mode): @@ -16,14 +17,14 @@ def get_threshold_value(mode): def conservation_mode(value): try: - subprocess.check_output(f"echo {value} | tee {CONSERVATION_MODE_FILE}", shell=True, text=True) + check_output(f"echo {value} | tee {CONSERVATION_MODE_FILE}", shell=True, text=True) print(f"conservation_mode is {value}") except: print("unable to set conservation mode") return def check_conservation_mode(): try: - value = subprocess.check_output(["cat", CONSERVATION_MODE_FILE], text=True) + value = check_output(["cat", CONSERVATION_MODE_FILE], text=True) if value == "1": return True elif value == "0": return False else: @@ -63,6 +64,6 @@ def ideapad_laptop_print_thresholds(): print(f"battery count = {len(batteries)}") for bat in batteries: try: - 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")}') + print(bat, "start threshold =", check_output(["cat", POWER_SUPPLY_DIR+bat+"/charge_start_threshold"])) + print(bat, "stop threshold =", check_output(["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 04a10df..1f16415 100644 --- a/auto_cpufreq/battery_scripts/thinkpad.py +++ b/auto_cpufreq/battery_scripts/thinkpad.py @@ -1,12 +1,13 @@ #!/usr/bin/env python3 -import os, subprocess +import os +from subprocess import check_output from auto_cpufreq.config.config import config from auto_cpufreq.globals import POWER_SUPPLY_DIR def set_battery(value, mode, bat): path = f"{POWER_SUPPLY_DIR}{bat}/charge_{mode}_threshold" - if os.path.isfile(path): subprocess.check_output(f"echo {value} | tee {path}", shell=True, text=True) + if os.path.isfile(path): check_output(f"echo {value} | tee {path}", shell=True, text=True) else: print(f"WARNING: {path} does NOT exist") def get_threshold_value(mode): @@ -33,6 +34,6 @@ def thinkpad_print_thresholds(): print(f"battery count = {len(batteries)}") for bat in batteries: try: - 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")}') + print(bat, "start threshold =", check_output(["cat", POWER_SUPPLY_DIR+bat+"/charge_start_threshold"])) + print(bat, "stop threshold =", check_output(["cat", POWER_SUPPLY_DIR+bat+"/charge_stop_threshold"])) except Exception as e: print(f"ERROR: failed to read battery {bat} thresholds:", repr(e))