more generic script; can enable zpool or upsc checking only executables; now handle low battery situation; now show battery percentage near bar
This commit is contained in:
parent
16e030a943
commit
a858cc9083
1 changed files with 51 additions and 17 deletions
|
@ -89,7 +89,7 @@ def zpool_print_status():
|
|||
|
||||
draw.text((0, s_height - 10), zpool_status_data["errors"], fill=1)
|
||||
|
||||
def ups_print_status():
|
||||
def upsc_print_status():
|
||||
ups_name_finder = os.popen('upsc -l 127.0.0.1')
|
||||
ups_name_finder_output = ups_name_finder.read().split("\n")
|
||||
|
||||
|
@ -108,39 +108,73 @@ def ups_print_status():
|
|||
|
||||
battery_charge = upsc_status_data["battery.charge"]
|
||||
|
||||
used_width = draw.textlength("[]%")
|
||||
used_width = draw.textlength("[] "+battery_charge+"%")
|
||||
bar_width = (128 - used_width)
|
||||
real_width = (int(battery_charge) * bar_width) / 100
|
||||
|
||||
draw.text((0,9), "[", fill=1)
|
||||
draw.rectangle((5,13, real_width, 17), fill=1)
|
||||
draw.text((bar_width, 9), "]%", fill=1)
|
||||
draw.text((bar_width, 9), "] "+battery_charge+"%", fill=1)
|
||||
|
||||
draw.text((0, 20), upsc_status_data["device.model"], fill=1)
|
||||
draw.text((0, 28), upsc_status_data["outlet.power"] + "W", fill=1)
|
||||
draw.text((0, 36), upsc_status_data["output.voltage"] + "V", fill=1)
|
||||
what_to_show = {
|
||||
'device.model': '%{value}',
|
||||
'outlet.power': '%{value}W',
|
||||
'output.voltage': '%{value}V'
|
||||
}
|
||||
|
||||
starting_height = 19
|
||||
if int(battery_charge) <= int(upsc_status_data['battery.charge.low']):
|
||||
draw.text((0, starting_height + 9), "*********************", fill=1)
|
||||
draw.text((0, starting_height + 18), "**** BATTERY LOW ****", fill=1)
|
||||
draw.text((0, starting_height + 27), "*********************", fill=1)
|
||||
else:
|
||||
starting_height += 9
|
||||
for key in what_to_show:
|
||||
value = what_to_show[key].replace('%{value}', upsc_status_data[key])
|
||||
|
||||
draw.text((0, starting_height), value, fill=1)
|
||||
|
||||
starting_height += 9
|
||||
|
||||
def main():
|
||||
if which('zpool') is None:
|
||||
print("Cannot find `zpool` executable.")
|
||||
modules_enabled = []
|
||||
|
||||
if which('zpool') is not None:
|
||||
modules_enabled.append('zpool')
|
||||
|
||||
if which('upsc') is not None:
|
||||
modules_enabled.append('upsc')
|
||||
|
||||
if not modules_enabled:
|
||||
print("This script cannot run any module; check dependencies")
|
||||
|
||||
exit(1)
|
||||
|
||||
if which('upsc') is None:
|
||||
print("Cannot find `upsc` executable.")
|
||||
|
||||
exit(1)
|
||||
possibles = globals().copy()
|
||||
possibles.update(locals())
|
||||
|
||||
start_count = 0
|
||||
last_print = ''
|
||||
while True:
|
||||
module_to_run = modules_enabled[start_count % 2]
|
||||
method = possibles.get(module_to_run + "_print_status")
|
||||
|
||||
if not method:
|
||||
print("Module "+module_to_run+" not implemented")
|
||||
|
||||
exit(1)
|
||||
else:
|
||||
if module_to_run != last_print:
|
||||
device.clear()
|
||||
|
||||
if (start_count % 2) == 0:
|
||||
zpool_print_status()
|
||||
else:
|
||||
ups_print_status()
|
||||
method()
|
||||
last_print = module_to_run
|
||||
|
||||
if start_count == (len(modules_enabled) - 1):
|
||||
start_count = 0
|
||||
else:
|
||||
start_count += 1
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in a new issue