-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbacklight
More file actions
executable file
·37 lines (30 loc) · 903 Bytes
/
backlight
File metadata and controls
executable file
·37 lines (30 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/python3
import math
import os
import argh
PATH = '/sys/class/backlight/intel_backlight'
def read(name):
with open(os.path.join(PATH, name)) as f:
return int(f.read())
def write(name, value):
with open(os.path.join(PATH, name), 'w') as f:
f.write('{}\n'.format(value))
@argh.arg('percent', nargs='?', default=None)
def main(percent):
"""Set or get backlight brightness.
Give a percentage to set, or #N to set to an explicit integer N.
Give no args to query.
"""
if percent and percent.startswith('#'):
write('brightness', int(percent[1:]))
return
maxval = read('max_brightness')
if percent is None:
value = read('brightness')
print("{:.2f}% ({}/{})".format(100. * value / maxval, value, maxval))
else:
percent = float(percent)
value = int(math.ceil(maxval * percent / 100.))
write('brightness', value)
if __name__ == '__main__':
argh.dispatch_command(main)