# -*- coding: utf-8 -*-
"""
ARTA driver for turntable.

This script should be converted to a .exe and can be called by ARTA. It relays
the ARTA command to the DMX controller.

Convert to .exe:
    - pip install pyinstaller
    - python -m PyInstaller --onedir -w ARTAdriver.py
    - The resulting .exe will be placed in the directory "dist"
"""
from multiprocessing.connection import Client
import subprocess
import sys

# Communication with DMX controller
address = ('localhost', 6000)  # family is deduced to be 'AF_INET'
authkey = b'FtGz6EyHQ38ki6RaUKP4'


def run():
    """Read the command line argument and send it to the DMX controller."""
    # Read command line input
    s = sys.argv[1]  # [0] is the script name, [1] is the first argument

    # Send to DMX controller
    with Client(address, authkey=authkey) as conn:
        conn.send(s)


if __name__ == '__main__':
    assert len(sys.argv) == 2, "The number of arguments is wrong. " \
                               "Program needs to be called like this: " \
                               "[main.exe -r] or [main.exe 45]. "
    run()
    sys.exit(0)
