Show error message if threshold file doesn't exist (#742)
* Show error message if threshold file doesn't exist * Repare stop threshold message * Repare check_output error
This commit is contained in:
parent
910aef9072
commit
4ef561eccf
|
@ -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))
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue