This commit is contained in:
Vinícius Moreira
2020-04-13 11:49:28 -03:00
parent 83aab1ff55
commit 01a60ea686
165 changed files with 12778 additions and 6171 deletions

View File

@@ -0,0 +1,38 @@
import multiprocessing
import os
import traceback
from bauh.commons.system import new_root_subprocess
def supports_performance_mode():
return os.path.exists('/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor')
def all_in_performance() -> bool:
for i in range(multiprocessing.cpu_count()):
with open('/sys/devices/system/cpu/cpu{}/cpufreq/scaling_governor'.format(i)) as f:
if f.read().strip() != 'performance':
return False
return False
def set_mode(mode: str, root_password: str):
new_gov_file = '/tmp/bauh_scaling_governor'
with open(new_gov_file, 'w+') as f:
f.write(mode)
for i in range(multiprocessing.cpu_count()):
try:
gov_file = '/sys/devices/system/cpu/cpu{}/cpufreq/scaling_governor'.format(i)
replace = new_root_subprocess(['cp', new_gov_file, gov_file], root_password=root_password)
replace.wait()
except:
traceback.print_exc()
if os.path.exists(new_gov_file):
try:
os.remove(new_gov_file)
except:
traceback.print_exc()