#!/usr/bin/env python
usage="""
./submit_run_list.py all_run_list.txt

Notes:
 - all_run_list.txt = JSON text of run description
   -> see all_run_list.txt in the current directory as an example.
      It should match the config in runs 899-915.
   -> avoid special web characters like "&" or "+".
   -> can be copied from the AJ setup run web page directly, but
      special symbols like "&" or "+" may look weird.
 - this script can only be run directly on fermion
"""

import multiprocessing.connection as mp_con
import sys

msg_addr = ('localhost',10003)

def msg_send( send_list ):
    client = mp_con.Client(msg_addr)
    client.send( send_list )
    client.close()

def main(filename):
    run_list_json_to_dict = open(filename).read()

    n_loop = 1
    skip_build = True
    skip_reboot = False
    skip_post = False

    send_list = ['playList', run_list_json_to_dict, n_loop, skip_build, skip_reboot, skip_post]
    msg_send(send_list)


if __name__ == '__main__':
    if len(sys.argv) == 2:
        main(sys.argv[1])
    else:
        print(usage)
