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') report = generate_report(sensor_data, 'Current', 'Max')
f.write('\n'.join(report)) f.write('\n'.join(report))
sleep(1) sleep(1)
if not tmux_poll_pane(monitor_pane): if monitor_pane and not tmux_poll_pane(monitor_pane):
break break
def save_average_temp(sensor_data, temp_label, seconds=10): def save_average_temp(sensor_data, temp_label, seconds=10):

View file

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