Add new script to manage brightness
This commit is contained in:
parent
822d11cdb1
commit
762ea6bc10
1 changed files with 36 additions and 0 deletions
36
brightness
Executable file
36
brightness
Executable file
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import glob
|
||||
import os
|
||||
import argparse
|
||||
|
||||
basepath="/sys/class/backlight/"
|
||||
|
||||
def get_dirs():
|
||||
return glob.glob("{}*".format(basepath)):
|
||||
|
||||
def get_driver_from_dir(directory):
|
||||
regexp = r"{}(?P<driver>.+)".format(basepath)
|
||||
return re.match(regexp, directory).groupdict()['driver']
|
||||
|
||||
for dir in
|
||||
valf = os.path.join(dir, "brightness")
|
||||
maxf = os.path.join(dir, "max_brightness")
|
||||
|
||||
with open(valf, "r") as fd:
|
||||
val = int("".join(fd.readlines()))
|
||||
|
||||
with open(maxf, "r") as fd:
|
||||
maxval = int("".join(fd.readlines()))
|
||||
|
||||
percent = (val/maxval)*100
|
||||
|
||||
print("{} {} = {:.2f}%".format(val,maxval,percent))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='cbacklight')
|
||||
|
||||
parser.add_argument('--inc', help='Increment by percentage (points)')
|
||||
parser.add_argument('--dec', help='Decrement by percentage (points)')
|
||||
parser.add_argument('--set', help='Set to percentage')
|
Loading…
Reference in a new issue