Add background mode for monitoring sensors

* This will be called by hw_diags.py to update a file in the background
* NOTE: This uses a naive check before attempting to write data
This commit is contained in:
2Shirt 2018-12-05 23:55:15 -07:00
parent c777d49091
commit 5550cce8db
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
2 changed files with 14 additions and 8 deletions

View file

@ -162,7 +162,7 @@ def monitor_sensors(monitor_pane, monitor_file):
report = generate_report(sensor_data, 'Current', 'Max')
f.write('\n'.join(report))
sleep(1)
if not tmux_poll_pane(monitor_pane):
if monitor_pane and not tmux_poll_pane(monitor_pane):
break
def save_average_temp(sensor_data, temp_label, seconds=10):

View file

@ -13,14 +13,20 @@ from functions.tmux import *
init_global_vars()
if __name__ == '__main__':
background = False
try:
result = run_program(['mktemp'])
monitor_file = result.stdout.decode().strip()
print(monitor_file)
monitor_pane = tmux_split_window(
percent=1, vertical=True, watch=monitor_file)
cmd = ['tmux', 'resize-pane', '-Z', '-t', monitor_pane]
run_program(cmd, check=False)
if len(sys.argv) > 1 and os.path.exists(sys.argv[1]):
background = True
monitor_file = sys.argv[1]
monitor_pane=None
else:
result = run_program(['mktemp'])
monitor_file = result.stdout.decode().strip()
if not background:
monitor_pane = tmux_split_window(
percent=1, vertical=True, watch=monitor_file)
cmd = ['tmux', 'resize-pane', '-Z', '-t', monitor_pane]
run_program(cmd, check=False)
monitor_sensors(monitor_pane, monitor_file)
exit_script()
except SystemExit: