Skip to content

Commit

Permalink
Show error message if threshold file doesn't exist (#742)
Browse files Browse the repository at this point in the history
* Show error message if threshold file doesn't exist

* Repare stop threshold message

* Repare check_output error
  • Loading branch information
Angel-Karasu authored Jul 18, 2024
1 parent 910aef9 commit 4ef561e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
9 changes: 5 additions & 4 deletions auto_cpufreq/battery_scripts/ideapad_acpi.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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))
13 changes: 7 additions & 6 deletions auto_cpufreq/battery_scripts/ideapad_laptop.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/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

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):
Expand All @@ -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:
Expand Down Expand Up @@ -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))
9 changes: 5 additions & 4 deletions auto_cpufreq/battery_scripts/thinkpad.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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))

0 comments on commit 4ef561e

Please sign in to comment.