#!/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')