Commit 15266545 authored by sbiego's avatar sbiego

added verbose option, using regex, some fixes

parent 908f5fa6
#!/usr/bin/python
import sys, math, getpass
version = "0.4c"
import sys, math, re
# import getpass
version = "0.5"
actual_bl = open('/sys/class/backlight/intel_backlight/brightness','r+')
actual_bl = open('/sys/class/backlight/intel_backlight/brightness', 'r+')
actual_brightness = int(actual_bl.read())
max_bl = open('/sys/class/backlight/intel_backlight/max_brightness','r')
max_bl = open('/sys/class/backlight/intel_backlight/max_brightness', 'r')
max_brightness = int(max_bl.read())
help = "Intel Black Light Util · v" + version + "\n\nPlease insert a valid percentage or use inc/dec (i/d) options (optionally indicating the shift)\nExample: \"ibl d 20\" #decreases the blacklight of 20%, default is 4%"
unit = "[Unit]\nDescription=Intel BackLight Util, changes owner of /sys/class/blacklight/intel_blacklight/brightness\n\n[Service]\nExecStart=/usr/bin/chown jake:wheel /sys/class/backlight/intel_backlight/brightness\n\n[Install]\nWantedBy=multi-user.target\n"
argvs = len(sys.argv)
act_info = ''
verbose = 0
changed = 0
shift_percent = math.ceil(max_brightness/100)
percentize = 100/max_brightness
new_brightness = actual_brightness
if(argvs == 2):
......@@ -23,15 +28,30 @@ if(argvs == 2):
tmp = actual_brightness + 4 * shift_percent
new_brightness = min(max_brightness, tmp)
else:
perc = int(sys.argv[1])
if(perc <= 0):
new_brightness = 1
elif(perc <= 100):
new_brightness = perc * shift_percent
elif(perc > 100):
new_brightness = max_brightness
if (re.search(r"[v]+", sys.argv[1])): ##verbose
verbose = 1
act_percent = int(actual_brightness * percentize)
act_info = str(act_percent) + '% (' + str(actual_brightness) + '/' + str(max_brightness) + ')'
if(re.search(r"[0-9]+", sys.argv[1])):
perc = int(re.findall(r"[0-9]+", sys.argv[1])[0])
if(perc <= 0):
new_brightness = 1
elif(perc < 100):
new_brightness = min(perc * shift_percent, max_brightness)
elif(perc >= 100):
new_brightness = max_brightness
if not (new_brightness == actual_brightness):
new_percent = int(new_brightness * percentize)
new_info = str(new_percent) + '% (' + str(new_brightness) + '/' + str(max_brightness) + ')'
changed = 1
elif(argvs == 3):
option = sys.argv[1]
#re.search(r"d", sys.argv[1])[0] ###### TO DO implement regex for custom shift?
#re.search(r"d", sys.argv[1])[0])
if(option == 'dec' or option == 'd'):
new_brightness = max(1, actual_brightness - int(sys.argv[2]) * shift_percent)
elif(option == 'inc' or option == 'i'):
......@@ -39,13 +59,27 @@ elif(argvs == 3):
else:
print(help)
# username = getpass.getuser()
# if(sys.argv[1] == 'enable'):
# if(not os.path.exists('/etc/systemd/system/iblu.service')):
# unit_file = open('/etc/systemd/system/iblu.service', 'w')
# # unit_file.write(unit)
# print(unit)
# if(sys.argv[1] == 'disable'):
if verbose:
if changed:
print("old: ", act_info)
print("new: ", new_info)
else:
print("actual: ", act_info)
actual_bl.write(str(new_brightness))
actual_bl.close()
# def output(verbose, perc):
# if verbose:
# act_percent = int(actual_brightness * percentize)
# act_info = "actual: " + str(act_percent) + '% (' + str(actual_brightness) + '/' + str(max_brightness) + ')'
#
# if perc:
# new_percent = int(new_brightness * percentize)
# act_info += "new: " + str(act_percent) + '%'
#
# print(act_info)
#
# output(verb, perc)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment