Add new script to manage brightness

This commit is contained in:
Nico Schottelius 2018-03-30 13:04:16 +02:00
parent 822d11cdb1
commit 762ea6bc10

36
brightness Executable file
View 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')